summaryrefslogtreecommitdiff
path: root/legacy/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-05-15 06:43:07 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-05-15 06:43:07 +0000
commit31bdf4d2c9a7d9611347cc6d8f5aabd6b7169f4e (patch)
tree52f59c9ca79922f1529cb5b61081bf394c3ec211 /legacy/eet
parent11c2dc7454b94300fa8b2dd1c826cdcbdb3c972c (diff)
eet: make eet_dictionary thread safe.
SVN revision: 71094
Diffstat (limited to 'legacy/eet')
-rw-r--r--legacy/eet/ChangeLog4
-rw-r--r--legacy/eet/NEWS1
-rw-r--r--legacy/eet/src/lib/Eet_private.h1
-rw-r--r--legacy/eet/src/lib/eet_dictionary.c149
4 files changed, 113 insertions, 42 deletions
diff --git a/legacy/eet/ChangeLog b/legacy/eet/ChangeLog
index 26d4870612..43e85b2e45 100644
--- a/legacy/eet/ChangeLog
+++ b/legacy/eet/ChangeLog
@@ -586,3 +586,7 @@
5862012-05-11 Cedric Bail 5862012-05-11 Cedric Bail
587 587
588 * Force destruction of all pending file when shuting down eet. 588 * Force destruction of all pending file when shuting down eet.
589
5902012-05-15 Cedric Bail
591
592 * Make eet_dictionary thread safe.
diff --git a/legacy/eet/NEWS b/legacy/eet/NEWS
index bff1bff2c3..5d11d3ee9d 100644
--- a/legacy/eet/NEWS
+++ b/legacy/eet/NEWS
@@ -5,6 +5,7 @@ Changes since Eet 1.6.0:
5 5
6Fixes: 6Fixes:
7 * Force destruction of all pending file when shuting down eet. 7 * Force destruction of all pending file when shuting down eet.
8 * Make eet_dictionary thread safe.
8 9
9Eet 1.6.0 10Eet 1.6.0
10 11
diff --git a/legacy/eet/src/lib/Eet_private.h b/legacy/eet/src/lib/Eet_private.h
index c04daf0239..afd4685dbe 100644
--- a/legacy/eet/src/lib/Eet_private.h
+++ b/legacy/eet/src/lib/Eet_private.h
@@ -41,6 +41,7 @@ struct _Eet_Dictionary
41{ 41{
42 Eet_String *all; 42 Eet_String *all;
43 Eina_Hash *converts; 43 Eina_Hash *converts;
44 Eina_Lock mutex;
44 45
45 int size; 46 int size;
46 int offset; 47 int offset;
diff --git a/legacy/eet/src/lib/eet_dictionary.c b/legacy/eet/src/lib/eet_dictionary.c
index c79239bc5d..f307d4ddbe 100644
--- a/legacy/eet/src/lib/eet_dictionary.c
+++ b/legacy/eet/src/lib/eet_dictionary.c
@@ -21,6 +21,7 @@ eet_dictionary_add(void)
21 return NULL; 21 return NULL;
22 22
23 memset(new->hash, -1, sizeof (int) * 256); 23 memset(new->hash, -1, sizeof (int) * 256);
24 eina_lock_new(&new->mutex);
24 25
25 return new; 26 return new;
26} 27}
@@ -32,6 +33,8 @@ eet_dictionary_free(Eet_Dictionary *ed)
32 33
33 if (!ed) return; 34 if (!ed) return;
34 35
36 eina_lock_free(&ed->mutex);
37
35 for (i = 0; i < ed->count; ++i) 38 for (i = 0; i < ed->count; ++i)
36 if (ed->all[i].allocated) 39 if (ed->all[i].allocated)
37 eina_stringshare_del(ed->all[i].str); 40 eina_stringshare_del(ed->all[i].str);
@@ -94,12 +97,17 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
94 hash = _eet_hash_gen(string, 8); 97 hash = _eet_hash_gen(string, 8);
95 len = strlen(string) + 1; 98 len = strlen(string) + 1;
96 99
100 eina_lock_take(&ed->mutex);
101
97 idx = _eet_dictionary_lookup(ed, string, len, hash); 102 idx = _eet_dictionary_lookup(ed, string, len, hash);
98 103
99 if (idx != -1) 104 if (idx != -1)
100 { 105 {
101 if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0)) 106 if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
102 return idx; 107 {
108 eina_lock_release(&ed->mutex);
109 return idx;
110 }
103 } 111 }
104 112
105 if (ed->total == ed->count) 113 if (ed->total == ed->count)
@@ -110,16 +118,14 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
110 total = ed->total + 8; 118 total = ed->total + 8;
111 119
112 new = realloc(ed->all, total * sizeof(Eet_String)); 120 new = realloc(ed->all, total * sizeof(Eet_String));
113 if (!new) 121 if (!new) goto on_error;
114 return -1;
115 122
116 ed->all = new; 123 ed->all = new;
117 ed->total = total; 124 ed->total = total;
118 } 125 }
119 126
120 str = eina_stringshare_add(string); 127 str = eina_stringshare_add(string);
121 if (!str) 128 if (!str) goto on_error;
122 return -1;
123 129
124 current = ed->all + ed->count; 130 current = ed->all + ed->count;
125 131
@@ -150,23 +156,33 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
150 ed->hash[hash] = ed->count; 156 ed->hash[hash] = ed->count;
151 } 157 }
152 158
159 eina_lock_release(&ed->mutex);
153 return ed->count++; 160 return ed->count++;
161
162 on_error:
163 eina_lock_release(&ed->mutex);
164 return -1;
154} 165}
155 166
156int 167int
157eet_dictionary_string_get_size(const Eet_Dictionary *ed, 168eet_dictionary_string_get_size(const Eet_Dictionary *ed,
158 int idx) 169 int idx)
159{ 170{
160 if (!ed) 171 int length = 0;
161 return 0;
162 172
163 if (idx < 0) 173 if (!ed) goto done;
164 return 0; 174
175 if (idx < 0) goto done;
176
177 eina_lock_take((Eina_Lock*) &ed->mutex);
165 178
166 if (idx < ed->count) 179 if (idx < ed->count)
167 return ed->all[idx].len; 180 length = ed->all[idx].len;
168 181
169 return 0; 182 eina_lock_release((Eina_Lock*) &ed->mutex);
183
184 done:
185 return length;
170} 186}
171 187
172EAPI int 188EAPI int
@@ -179,27 +195,34 @@ int
179eet_dictionary_string_get_hash(const Eet_Dictionary *ed, 195eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
180 int idx) 196 int idx)
181{ 197{
182 if (!ed) 198 int hash = -1;
183 return -1;
184 199
185 if (idx < 0) 200 if (!ed) goto done;
186 return -1; 201
202 if (idx < 0) goto done;
203
204 eina_lock_take((Eina_Lock*) &ed->mutex);
187 205
188 if (idx < ed->count) 206 if (idx < ed->count)
189 return ed->all[idx].hash; 207 hash = ed->all[idx].hash;
190 208
191 return -1; 209 eina_lock_release((Eina_Lock*) &ed->mutex);
210
211 done:
212 return hash;
192} 213}
193 214
194const char * 215const char *
195eet_dictionary_string_get_char(const Eet_Dictionary *ed, 216eet_dictionary_string_get_char(const Eet_Dictionary *ed,
196 int idx) 217 int idx)
197{ 218{
198 if (!ed) 219 const char *s = NULL;
199 return NULL;
200 220
201 if (idx < 0) 221 if (!ed) goto done;
202 return NULL; 222
223 if (idx < 0) goto done;
224
225 eina_lock_take((Eina_Lock*) &ed->mutex);
203 226
204 if (idx < ed->count) 227 if (idx < ed->count)
205 { 228 {
@@ -211,10 +234,13 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed,
211 ed->all[idx].allocated = EINA_TRUE; 234 ed->all[idx].allocated = EINA_TRUE;
212 } 235 }
213#endif /* ifdef _WIN32 */ 236#endif /* ifdef _WIN32 */
214 return ed->all[idx].str; 237 s = ed->all[idx].str;
215 } 238 }
216 239
217 return NULL; 240 eina_lock_release((Eina_Lock*) &ed->mutex);
241
242 done:
243 return s;
218} 244}
219 245
220static inline Eina_Bool 246static inline Eina_Bool
@@ -281,19 +307,25 @@ _eet_dictionary_test(const Eet_Dictionary *ed,
281 int idx, 307 int idx,
282 void *result) 308 void *result)
283{ 309{
284 if (!result) 310 Eina_Bool limit = EINA_FALSE;
285 return EINA_FALSE;
286 311
287 if (!ed) 312 if (!result) goto done;
288 return EINA_FALSE;
289 313
290 if (idx < 0) 314 if (!ed) goto done;
291 return EINA_FALSE;
292 315
293 if (!(idx < ed->count)) 316 if (idx < 0) goto done;
294 return EINA_FALSE;
295 317
296 return EINA_TRUE; 318 eina_lock_take((Eina_Lock*) &ed->mutex);
319
320 if (!(idx < ed->count)) goto unlock_done;
321
322 limit = EINA_TRUE;
323
324 unlock_done:
325 eina_lock_release((Eina_Lock*) &ed->mutex);
326
327 done:
328 return limit;
297} 329}
298 330
299static Eet_Convert * 331static Eet_Convert *
@@ -303,6 +335,8 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed,
303{ 335{
304 Eet_Convert *result; 336 Eet_Convert *result;
305 337
338 eina_lock_take((Eina_Lock*) &ed->mutex);
339
306 *str = ed->all[idx].str; 340 *str = ed->all[idx].str;
307 341
308 if (!ed->converts) 342 if (!ed->converts)
@@ -313,12 +347,16 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed,
313 } 347 }
314 348
315 result = eina_hash_find(ed->converts, &idx); 349 result = eina_hash_find(ed->converts, &idx);
316 if (result) return result; 350 if (result) goto done;
317 351
318add_convert: 352 add_convert:
319 result = calloc(1, sizeof (Eet_Convert)); 353 result = calloc(1, sizeof (Eet_Convert));
320 354
321 eina_hash_add(ed->converts, &idx, result); 355 eina_hash_add(ed->converts, &idx, result);
356
357 done:
358 eina_lock_release((Eina_Lock*) &ed->mutex);
359
322 return result; 360 return result;
323} 361}
324 362
@@ -338,6 +376,7 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed,
338 376
339 if (!(convert->type & EET_D_FLOAT)) 377 if (!(convert->type & EET_D_FLOAT))
340 { 378 {
379 eina_lock_take((Eina_Lock*) &ed->mutex);
341 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, 380 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
342 &convert->f)) 381 &convert->f))
343 { 382 {
@@ -346,10 +385,14 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed,
346 385
347 if (eina_convert_atod(str, ed->all[idx].len, &mantisse, 386 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
348 &exponent) == EINA_FALSE) 387 &exponent) == EINA_FALSE)
349 return EINA_FALSE; 388 {
389 eina_lock_release((Eina_Lock*) &ed->mutex);
390 return EINA_FALSE;
391 }
350 392
351 convert->f = ldexpf((float)mantisse, exponent); 393 convert->f = ldexpf((float)mantisse, exponent);
352 } 394 }
395 eina_lock_release((Eina_Lock*) &ed->mutex);
353 396
354 convert->type |= EET_D_FLOAT; 397 convert->type |= EET_D_FLOAT;
355 } 398 }
@@ -374,6 +417,8 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed,
374 417
375 if (!(convert->type & EET_D_DOUBLE)) 418 if (!(convert->type & EET_D_DOUBLE))
376 { 419 {
420 eina_lock_take((Eina_Lock*) &ed->mutex);
421
377 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, 422 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
378 &convert->d)) 423 &convert->d))
379 { 424 {
@@ -382,10 +427,14 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed,
382 427
383 if (eina_convert_atod(str, ed->all[idx].len, &mantisse, 428 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
384 &exponent) == EINA_FALSE) 429 &exponent) == EINA_FALSE)
385 return EINA_FALSE; 430 {
431 eina_lock_release((Eina_Lock*) &ed->mutex);
432 return EINA_FALSE;
433 }
386 434
387 convert->d = ldexp((double)mantisse, exponent); 435 convert->d = ldexp((double)mantisse, exponent);
388 } 436 }
437 eina_lock_release((Eina_Lock*) &ed->mutex);
389 438
390 convert->type |= EET_D_DOUBLE; 439 convert->type |= EET_D_DOUBLE;
391 } 440 }
@@ -412,8 +461,13 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
412 { 461 {
413 Eina_F32p32 fp; 462 Eina_F32p32 fp;
414 463
464 eina_lock_take((Eina_Lock*) &ed->mutex);
415 if (!eina_convert_atofp(str, ed->all[idx].len, &fp)) 465 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
416 return EINA_FALSE; 466 {
467 eina_lock_release((Eina_Lock*) &ed->mutex);
468 return EINA_FALSE;
469 }
470 eina_lock_release((Eina_Lock*) &ed->mutex);
417 471
418 convert->fp = fp; 472 convert->fp = fp;
419 convert->type |= EET_D_FIXED_POINT; 473 convert->type |= EET_D_FIXED_POINT;
@@ -427,18 +481,29 @@ EAPI int
427eet_dictionary_string_check(Eet_Dictionary *ed, 481eet_dictionary_string_check(Eet_Dictionary *ed,
428 const char *string) 482 const char *string)
429{ 483{
484 int res = 0;
430 int i; 485 int i;
431 486
432 if ((!ed) || (!string)) 487 if ((!ed) || (!string))
433 return 0; 488 return 0;
434 489
490 eina_lock_take(&ed->mutex);
491
435 if ((ed->start <= string) && (string < ed->end)) 492 if ((ed->start <= string) && (string < ed->end))
436 return 1; 493 res = 1;
437 494
438 for (i = 0; i < ed->count; ++i) 495 if (!res)
439 if ((ed->all[i].allocated) && ed->all[i].str == string) 496 {
440 return 1; 497 for (i = 0; i < ed->count; ++i)
498 if ((ed->all[i].allocated) && ed->all[i].str == string)
499 {
500 res = 1;
501 break;
502 }
503 }
504
505 eina_lock_release(&ed->mutex);
441 506
442 return 0; 507 return res;
443} 508}
444 509