From: Cedric Bail Date: Thu, 10 Oct 2013 08:25:39 +0000 (+0900) Subject: eina: use Eina_Spinlock in Eina_Stringshare instead of Eina_Lock. X-Git-Tag: submit/devel/efl/20131029.075644~106 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0aa77d7ddebf2980c11c1e1f4a6f116ab5f2ef9e;p=platform%2Fupstream%2Fefl.git eina: use Eina_Spinlock in Eina_Stringshare instead of Eina_Lock. --- diff --git a/ChangeLog b/ChangeLog index f700f93..fcedcf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 2013-10-11 Cedric Bail * Eina: add Eina_Spinlock API, - use Eina_Spinlock in Eina_Log. + use Eina_Spinlock in Eina_Log, + replace Eina_Lock by Eina_Spinlock in Eina_Stringshare. 2013-10-10 Carsten Haitzler (The Rasterman) diff --git a/NEWS b/NEWS index e49464b..509d17c 100644 --- a/NEWS +++ b/NEWS @@ -198,7 +198,7 @@ Improvements: - Eina_Tiler now take tile size into account. - Improve support for 64bits system. - eina_strlcat now work with a NULL source. - - Use Eina_Spinlock for eina_log. + - Use Eina_Spinlock for eina_log, eina_stringshare. * Eet: - Display more information with eet -l -v. - Force thread to always run during eet_cache_concurrency test. diff --git a/src/lib/eina/eina_share_common.c b/src/lib/eina/eina_share_common.c index c2b64ac..0682b6e 100644 --- a/src/lib/eina/eina_share_common.c +++ b/src/lib/eina/eina_share_common.c @@ -174,7 +174,7 @@ struct _Eina_Share_Common_Head Eina_Bool _share_common_threads_activated = EINA_FALSE; -static Eina_Lock _mutex_big; +static Eina_Spinlock _mutex_big; #ifdef EINA_STRINGSHARE_USAGE @@ -256,9 +256,9 @@ eina_share_common_population_nolock_add(Eina_Share *share, int slen) void eina_share_common_population_add(Eina_Share *share, int slen) { - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); eina_share_common_population_nolock_add(share, slen); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); } static void @@ -272,9 +272,9 @@ eina_share_common_population_nolock_del(Eina_Share *share, int slen) void eina_share_common_population_del(Eina_Share *share, int slen) { - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); eina_share_common_population_nolock_del(chare, slen); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); } static void @@ -634,7 +634,7 @@ eina_share_common_init(Eina_Share **_share, if (_eina_share_common_count++ != 0) return EINA_TRUE; - eina_lock_new(&_mutex_big); + eina_spinlock_new(&_mutex_big); return EINA_TRUE; on_error: @@ -659,7 +659,7 @@ eina_share_common_shutdown(Eina_Share **_share) unsigned int i; Eina_Share *share = *_share; - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); _eina_share_common_population_stats(share); @@ -676,7 +676,7 @@ eina_share_common_shutdown(Eina_Share **_share) _eina_share_common_population_shutdown(share); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); free(*_share); *_share = NULL; @@ -685,7 +685,7 @@ eina_share_common_shutdown(Eina_Share **_share) if (--_eina_share_common_count != 0) return EINA_TRUE; - eina_lock_free(&_mutex_big); + eina_spinlock_free(&_mutex_big); return EINA_TRUE; } @@ -752,7 +752,7 @@ eina_share_common_add_length(Eina_Share *share, hash = eina_hash_superfast(str, slen); - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); p_bucket = share->share->buckets + EINA_SHARE_COMMON_BUCKET_IDX(hash); ed = _eina_share_common_find_hash(*p_bucket, EINA_SHARE_COMMON_NODE_HASH(hash)); @@ -764,27 +764,27 @@ eina_share_common_add_length(Eina_Share *share, str, slen, null_size); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return s; } - EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), NULL); + EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_spinlock_release(&_mutex_big), NULL); el = _eina_share_common_head_find(ed, str, slen); if (el) { EINA_MAGIC_CHECK_SHARE_COMMON_NODE(el, share->node_magic, - eina_lock_release(&_mutex_big)); + eina_spinlock_release(&_mutex_big)); el->references++; - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return el->str; } el = _eina_share_common_node_alloc(slen, null_size); if (!el) { - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return NULL; } @@ -793,7 +793,7 @@ eina_share_common_add_length(Eina_Share *share, ed->head = el; _eina_share_common_population_head_add(share, ed); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return el->str; } @@ -806,18 +806,18 @@ eina_share_common_ref(Eina_Share *share, const char *str) if (!str) return NULL; - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); node = _eina_share_common_node_from_str(str, share->node_magic); if (!node) { - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return str; } node->references++; eina_share_common_population_nolock_add(share, node->length); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return str; } @@ -834,7 +834,7 @@ eina_share_common_del(Eina_Share *share, const char *str) if (!str) return EINA_TRUE; - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); node = _eina_share_common_node_from_str(str, share->node_magic); if (!node) @@ -845,7 +845,7 @@ eina_share_common_del(Eina_Share *share, const char *str) if (node->references > 1) { node->references--; - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return EINA_TRUE; } @@ -855,7 +855,7 @@ eina_share_common_del(Eina_Share *share, const char *str) if (!ed) goto on_error; - EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), EINA_FALSE); + EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_spinlock_release(&_mutex_big), EINA_FALSE); if (node != &ed->builtin_node) { @@ -872,12 +872,12 @@ eina_share_common_del(Eina_Share *share, const char *str) else _eina_share_common_population_head_del(share, ed); - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); return EINA_TRUE; on_error: - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); /* possible segfault happened before here, but... */ return EINA_FALSE; } @@ -913,7 +913,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)( printf("DDD: len ref string\n"); printf("DDD:-------------------\n"); - eina_lock_take(&_mutex_big); + eina_spinlock_take(&_mutex_big); for (i = 0; i < EINA_SHARE_COMMON_BUCKETS; i++) { if (!share->share->buckets[i]) @@ -958,7 +958,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)( share->population_group[i].max); #endif - eina_lock_release(&_mutex_big); + eina_spinlock_release(&_mutex_big); } /** diff --git a/src/lib/eina/eina_stringshare.c b/src/lib/eina/eina_stringshare.c index 9f8d10e..2232fa9 100644 --- a/src/lib/eina/eina_stringshare.c +++ b/src/lib/eina/eina_stringshare.c @@ -69,7 +69,7 @@ static Eina_Share *stringshare_share; static const char EINA_MAGIC_STRINGSHARE_NODE_STR[] = "Eina Stringshare Node"; extern Eina_Bool _share_common_threads_activated; -static Eina_Lock _mutex_small; +static Eina_Spinlock _mutex_small; /* Stringshare optimizations */ static const unsigned char _eina_stringshare_single[512] = { @@ -396,7 +396,7 @@ error: static void _eina_stringshare_small_init(void) { - eina_lock_new(&_mutex_small); + eina_spinlock_new(&_mutex_small); memset(&_eina_small_share, 0, sizeof(_eina_small_share)); } @@ -428,7 +428,7 @@ _eina_stringshare_small_shutdown(void) *p_bucket = NULL; } - eina_lock_free(&_mutex_small); + eina_spinlock_free(&_mutex_small); } static void @@ -586,9 +586,9 @@ eina_stringshare_del(Eina_Stringshare *str) else if (slen < 4) { eina_share_common_population_del(stringshare_share, slen); - eina_lock_take(&_mutex_small); + eina_spinlock_take(&_mutex_small); _eina_stringshare_small_del(str, slen); - eina_lock_release(&_mutex_small); + eina_spinlock_release(&_mutex_small); return; } @@ -619,9 +619,9 @@ eina_stringshare_add_length(const char *str, unsigned int slen) const char *s; eina_share_common_population_add(stringshare_share, slen); - eina_lock_take(&_mutex_small); + eina_spinlock_take(&_mutex_small); s = _eina_stringshare_small_add(str, slen); - eina_lock_release(&_mutex_small); + eina_spinlock_release(&_mutex_small); return s; } @@ -738,9 +738,9 @@ eina_stringshare_ref(Eina_Stringshare *str) const char *s; eina_share_common_population_add(stringshare_share, slen); - eina_lock_take(&_mutex_small); + eina_spinlock_take(&_mutex_small); s = _eina_stringshare_small_add(str, slen); - eina_lock_release(&_mutex_small); + eina_spinlock_release(&_mutex_small); return s; }