From b9d8a7af3ac164f47f62329c278d1cf09d9b1346 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Thu, 10 Oct 2013 17:27:41 +0900 Subject: [PATCH] eet: use Eina_Spinlock instead of Eina_Lock for Eet_Dictionary. --- ChangeLog | 4 +-- NEWS | 1 + src/lib/eet/Eet_private.h | 2 +- src/lib/eet/eet_dictionary.c | 54 ++++++++++++++++++------------------ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcedcf49aa..892a7a8415 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,8 @@ 2013-10-11 Cedric Bail * Eina: add Eina_Spinlock API, - use Eina_Spinlock in Eina_Log, - replace Eina_Lock by Eina_Spinlock in Eina_Stringshare. + use Eina_Spinlock in Eina_Log, replace Eina_Lock by Eina_Spinlock in Eina_Stringshare. + * Eet: replace Eina_Lock by Eina_Spinlock in Eet_Dictionnary. 2013-10-10 Carsten Haitzler (The Rasterman) diff --git a/NEWS b/NEWS index 509d17c2c7..00c4dbda5b 100644 --- a/NEWS +++ b/NEWS @@ -202,6 +202,7 @@ Improvements: * Eet: - Display more information with eet -l -v. - Force thread to always run during eet_cache_concurrency test. + - Use Eina_Spinlock for locking dictionnary instead of Eina_Lock. * Evas: - Reduced number of enqueued font commands when rendering textgrid objects - Use Eina_File in webp, gif, tiff, png and eet loader diff --git a/src/lib/eet/Eet_private.h b/src/lib/eet/Eet_private.h index af4f75e109..5d57c0172a 100644 --- a/src/lib/eet/Eet_private.h +++ b/src/lib/eet/Eet_private.h @@ -40,7 +40,7 @@ struct _Eet_Dictionary unsigned char *all_allocated; Eina_Hash *converts; - Eina_Lock mutex; + Eina_Spinlock mutex; int size; int offset; diff --git a/src/lib/eet/eet_dictionary.c b/src/lib/eet/eet_dictionary.c index b003616787..d3466508ad 100644 --- a/src/lib/eet/eet_dictionary.c +++ b/src/lib/eet/eet_dictionary.c @@ -21,7 +21,7 @@ eet_dictionary_add(void) return NULL; memset(new->hash, -1, sizeof (int) * 256); - eina_lock_new(&new->mutex); + eina_spinlock_new(&new->mutex); return new; } @@ -33,7 +33,7 @@ eet_dictionary_free(Eet_Dictionary *ed) if (!ed) return; - eina_lock_free(&ed->mutex); + eina_spinlock_free(&ed->mutex); for (i = 0; i < ed->count; ++i) if (ed->all_allocated[i >> 8] & (1 << (i & 0x7))) @@ -108,7 +108,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, hash = _eet_hash_gen(string, 8); len = strlen(string) + 1; - eina_lock_take(&ed->mutex); + eina_spinlock_take(&ed->mutex); idx = _eet_dictionary_lookup(ed, string, len, hash, &pidx); @@ -118,7 +118,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, ((ed->all[idx].str == string) || (!strcmp(ed->all[idx].str, string)))) { - eina_lock_release(&ed->mutex); + eina_spinlock_release(&ed->mutex); return idx; } } @@ -174,11 +174,11 @@ eet_dictionary_string_add(Eet_Dictionary *ed, } cnt = ed->count++; - eina_lock_release(&ed->mutex); + eina_spinlock_release(&ed->mutex); return cnt; on_error: - eina_lock_release(&ed->mutex); + eina_spinlock_release(&ed->mutex); return -1; } @@ -192,12 +192,12 @@ eet_dictionary_string_get_size(const Eet_Dictionary *ed, if (idx < 0) goto done; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (idx < ed->count) length = ed->all[idx].len; - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); done: return length; @@ -219,12 +219,12 @@ eet_dictionary_string_get_hash(const Eet_Dictionary *ed, if (idx < 0) goto done; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (idx < ed->count) hash = ed->all_hash[idx]; - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); done: return hash; @@ -240,7 +240,7 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, if (idx < 0) goto done; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (idx < ed->count) { @@ -255,7 +255,7 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, s = ed->all[idx].str; } - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); done: return s; @@ -333,14 +333,14 @@ _eet_dictionary_test(const Eet_Dictionary *ed, if (idx < 0) goto done; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (!(idx < ed->count)) goto unlock_done; limit = EINA_TRUE; unlock_done: - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); done: return limit; @@ -353,7 +353,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed, { Eet_Convert *result; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); *str = ed->all[idx].str; @@ -373,7 +373,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed, eina_hash_add(ed->converts, &idx, result); done: - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); return result; } @@ -394,7 +394,7 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, if (!(convert->type & EET_D_FLOAT)) { - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, &convert->f)) { @@ -404,13 +404,13 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) { - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); return EINA_FALSE; } convert->f = ldexpf((float)mantisse, exponent); } - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); convert->type |= EET_D_FLOAT; } @@ -435,7 +435,7 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, if (!(convert->type & EET_D_DOUBLE)) { - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, &convert->d)) @@ -446,13 +446,13 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) { - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); return EINA_FALSE; } convert->d = ldexp((double)mantisse, exponent); } - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); convert->type |= EET_D_DOUBLE; } @@ -479,13 +479,13 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed, { Eina_F32p32 fp; - eina_lock_take((Eina_Lock*) &ed->mutex); + eina_spinlock_take((Eina_Spinlock*) &ed->mutex); if (!eina_convert_atofp(str, ed->all[idx].len, &fp)) { - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); return EINA_FALSE; } - eina_lock_release((Eina_Lock*) &ed->mutex); + eina_spinlock_release((Eina_Spinlock*) &ed->mutex); convert->fp = fp; convert->type |= EET_D_FIXED_POINT; @@ -505,7 +505,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed, if ((!ed) || (!string)) return 0; - eina_lock_take(&ed->mutex); + eina_spinlock_take(&ed->mutex); if ((ed->start <= string) && (string < ed->end)) res = 1; @@ -520,7 +520,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed, } } - eina_lock_release(&ed->mutex); + eina_spinlock_release(&ed->mutex); return res; }