return NULL;
memset(new->hash, -1, sizeof (int) * 256);
+ eina_lock_new(&new->mutex);
return new;
}
if (!ed) return;
+ eina_lock_free(&ed->mutex);
+
for (i = 0; i < ed->count; ++i)
if (ed->all[i].allocated)
eina_stringshare_del(ed->all[i].str);
hash = _eet_hash_gen(string, 8);
len = strlen(string) + 1;
+ eina_lock_take(&ed->mutex);
+
idx = _eet_dictionary_lookup(ed, string, len, hash);
if (idx != -1)
{
if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
- return idx;
+ {
+ eina_lock_release(&ed->mutex);
+ return idx;
+ }
}
if (ed->total == ed->count)
total = ed->total + 8;
new = realloc(ed->all, total * sizeof(Eet_String));
- if (!new)
- return -1;
+ if (!new) goto on_error;
ed->all = new;
ed->total = total;
}
str = eina_stringshare_add(string);
- if (!str)
- return -1;
+ if (!str) goto on_error;
current = ed->all + ed->count;
ed->hash[hash] = ed->count;
}
+ eina_lock_release(&ed->mutex);
return ed->count++;
+
+ on_error:
+ eina_lock_release(&ed->mutex);
+ return -1;
}
int
eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int idx)
{
- if (!ed)
- return 0;
+ int length = 0;
- if (idx < 0)
- return 0;
+ if (!ed) goto done;
+
+ if (idx < 0) goto done;
+
+ eina_lock_take((Eina_Lock*) &ed->mutex);
if (idx < ed->count)
- return ed->all[idx].len;
+ length = ed->all[idx].len;
- return 0;
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+
+ done:
+ return length;
}
EAPI int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int idx)
{
- if (!ed)
- return -1;
+ int hash = -1;
- if (idx < 0)
- return -1;
+ if (!ed) goto done;
+
+ if (idx < 0) goto done;
+
+ eina_lock_take((Eina_Lock*) &ed->mutex);
if (idx < ed->count)
- return ed->all[idx].hash;
+ hash = ed->all[idx].hash;
- return -1;
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+
+ done:
+ return hash;
}
const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed,
int idx)
{
- if (!ed)
- return NULL;
+ const char *s = NULL;
- if (idx < 0)
- return NULL;
+ if (!ed) goto done;
+
+ if (idx < 0) goto done;
+
+ eina_lock_take((Eina_Lock*) &ed->mutex);
if (idx < ed->count)
{
ed->all[idx].allocated = EINA_TRUE;
}
#endif /* ifdef _WIN32 */
- return ed->all[idx].str;
+ s = ed->all[idx].str;
}
- return NULL;
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+
+ done:
+ return s;
}
static inline Eina_Bool
int idx,
void *result)
{
- if (!result)
- return EINA_FALSE;
+ Eina_Bool limit = EINA_FALSE;
- if (!ed)
- return EINA_FALSE;
+ if (!result) goto done;
- if (idx < 0)
- return EINA_FALSE;
+ if (!ed) goto done;
- if (!(idx < ed->count))
- return EINA_FALSE;
+ if (idx < 0) goto done;
- return EINA_TRUE;
+ eina_lock_take((Eina_Lock*) &ed->mutex);
+
+ if (!(idx < ed->count)) goto unlock_done;
+
+ limit = EINA_TRUE;
+
+ unlock_done:
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+
+ done:
+ return limit;
}
static Eet_Convert *
{
Eet_Convert *result;
+ eina_lock_take((Eina_Lock*) &ed->mutex);
+
*str = ed->all[idx].str;
if (!ed->converts)
}
result = eina_hash_find(ed->converts, &idx);
- if (result) return result;
+ if (result) goto done;
-add_convert:
+ add_convert:
result = calloc(1, sizeof (Eet_Convert));
eina_hash_add(ed->converts, &idx, result);
+
+ done:
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+
return result;
}
if (!(convert->type & EET_D_FLOAT))
{
+ eina_lock_take((Eina_Lock*) &ed->mutex);
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
&convert->f))
{
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE)
- return EINA_FALSE;
+ {
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+ return EINA_FALSE;
+ }
convert->f = ldexpf((float)mantisse, exponent);
}
+ eina_lock_release((Eina_Lock*) &ed->mutex);
convert->type |= EET_D_FLOAT;
}
if (!(convert->type & EET_D_DOUBLE))
{
+ eina_lock_take((Eina_Lock*) &ed->mutex);
+
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
&convert->d))
{
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE)
- return EINA_FALSE;
+ {
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+ return EINA_FALSE;
+ }
convert->d = ldexp((double)mantisse, exponent);
}
+ eina_lock_release((Eina_Lock*) &ed->mutex);
convert->type |= EET_D_DOUBLE;
}
{
Eina_F32p32 fp;
+ eina_lock_take((Eina_Lock*) &ed->mutex);
if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
- return EINA_FALSE;
+ {
+ eina_lock_release((Eina_Lock*) &ed->mutex);
+ return EINA_FALSE;
+ }
+ eina_lock_release((Eina_Lock*) &ed->mutex);
convert->fp = fp;
convert->type |= EET_D_FIXED_POINT;
eet_dictionary_string_check(Eet_Dictionary *ed,
const char *string)
{
+ int res = 0;
int i;
if ((!ed) || (!string))
return 0;
+ eina_lock_take(&ed->mutex);
+
if ((ed->start <= string) && (string < ed->end))
- return 1;
+ res = 1;
- for (i = 0; i < ed->count; ++i)
- if ((ed->all[i].allocated) && ed->all[i].str == string)
- return 1;
+ if (!res)
+ {
+ for (i = 0; i < ed->count; ++i)
+ if ((ed->all[i].allocated) && ed->all[i].str == string)
+ {
+ res = 1;
+ break;
+ }
+ }
+
+ eina_lock_release(&ed->mutex);
- return 0;
+ return res;
}