summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2010-08-16 09:32:09 +0000
committerCedric BAIL <cedric.bail@free.fr>2010-08-16 09:32:09 +0000
commitf75eab161dbfd37683ff875ad34025732b3dfef2 (patch)
treefcb8cded56681411768b72285a2036141064faec
parent128e61649d68dda4d86876cdc9bd36e2960b2328 (diff)
* eina: remove thread safe data type for now. They will be back !
SVN revision: 51179
-rw-r--r--legacy/eina/src/include/eina_array.h5
-rw-r--r--legacy/eina/src/include/eina_hash.h4
-rw-r--r--legacy/eina/src/include/eina_inline_array.x98
-rw-r--r--legacy/eina/src/lib/eina_array.c118
-rw-r--r--legacy/eina/src/lib/eina_hash.c357
-rw-r--r--legacy/eina/src/tests/eina_test_array.c57
-rw-r--r--legacy/eina/src/tests/eina_test_hash.c63
7 files changed, 18 insertions, 684 deletions
diff --git a/legacy/eina/src/include/eina_array.h b/legacy/eina/src/include/eina_array.h
index 6cdf738858..a5e071ef5c 100644
--- a/legacy/eina/src/include/eina_array.h
+++ b/legacy/eina/src/include/eina_array.h
@@ -29,11 +29,6 @@
29#include "eina_accessor.h" 29#include "eina_accessor.h"
30#include "eina_magic.h" 30#include "eina_magic.h"
31 31
32#ifdef EINA_RWLOCKS_ENABLED
33# include <pthread.h>
34# include <errno.h>
35#endif
36
37/** 32/**
38 * @addtogroup Eina_Data_Types_Group Data Types 33 * @addtogroup Eina_Data_Types_Group Data Types
39 * 34 *
diff --git a/legacy/eina/src/include/eina_hash.h b/legacy/eina/src/include/eina_hash.h
index efd134178b..0b5b3166ab 100644
--- a/legacy/eina/src/include/eina_hash.h
+++ b/legacy/eina/src/include/eina_hash.h
@@ -23,10 +23,6 @@
23#include "eina_types.h" 23#include "eina_types.h"
24#include "eina_iterator.h" 24#include "eina_iterator.h"
25 25
26#ifdef EINA_RWLOCKS_ENABLED
27# include <pthread.h>
28# include <errno.h>
29#endif
30/** 26/**
31 * @addtogroup Eina_Data_Types_Group Data Types 27 * @addtogroup Eina_Data_Types_Group Data Types
32 * 28 *
diff --git a/legacy/eina/src/include/eina_inline_array.x b/legacy/eina/src/include/eina_inline_array.x
index 38ddfe2c2b..a02e5a99c5 100644
--- a/legacy/eina/src/include/eina_inline_array.x
+++ b/legacy/eina/src/include/eina_inline_array.x
@@ -19,10 +19,6 @@
19#ifndef EINA_INLINE_ARRAY_X_ 19#ifndef EINA_INLINE_ARRAY_X_
20#define EINA_INLINE_ARRAY_X_ 20#define EINA_INLINE_ARRAY_X_
21 21
22#ifdef EINA_RWLOCKS_ENABLED
23# include <pthread.h>
24#endif
25
26/** 22/**
27 * @cond LOCAL 23 * @cond LOCAL
28 */ 24 */
@@ -62,20 +58,12 @@ eina_array_push(Eina_Array *array, const void *data)
62{ 58{
63 if (!data) return EINA_FALSE; 59 if (!data) return EINA_FALSE;
64 60
65 if (EINA_UNLIKELY(!eina_array_wrlock(array)))
66 return EINA_FALSE;
67
68 if (EINA_UNLIKELY((array->count + 1) > array->total)) 61 if (EINA_UNLIKELY((array->count + 1) > array->total))
69 if (!eina_array_grow(array)) 62 if (!eina_array_grow(array))
70 { 63 return EINA_FALSE;
71 eina_array_unlock(array);
72 return EINA_FALSE;
73 }
74 64
75 array->data[array->count++] = (void*) data; 65 array->data[array->count++] = (void*) data;
76 66
77 eina_array_unlock(array);
78
79 return EINA_TRUE; 67 return EINA_TRUE;
80} 68}
81 69
@@ -96,17 +84,12 @@ eina_array_pop(Eina_Array *array)
96{ 84{
97 void *ret = NULL; 85 void *ret = NULL;
98 86
99 if (EINA_UNLIKELY(!eina_array_wrlock(array)))
100 return NULL;
101
102 if (array->count <= 0) 87 if (array->count <= 0)
103 goto on_empty; 88 goto on_empty;
104 89
105 ret = array->data[--array->count]; 90 ret = array->data[--array->count];
106 91
107 on_empty: 92 on_empty:
108 eina_array_unlock(array);
109
110 return ret; 93 return ret;
111} 94}
112 95
@@ -160,71 +143,6 @@ eina_array_count_get(const Eina_Array *array)
160 return array->count; 143 return array->count;
161} 144}
162 145
163#ifdef EINA_RWLOCKS_ENABLED
164static inline Eina_Bool
165eina_array_rdlock(const Eina_Array *array)
166{
167 if (!array) return EINA_FALSE;
168 if (array->threadsafe)
169 {
170 int ret;
171
172 ret = pthread_rwlock_rdlock(&((Eina_Array*) array)->lock);
173 if ((ret != 0) && (ret != EDEADLK))
174 return EINA_FALSE;
175 }
176 return EINA_TRUE;
177}
178
179static inline Eina_Bool
180eina_array_wrlock(Eina_Array *array)
181{
182 if (!array) return EINA_FALSE;
183 if (array->threadsafe)
184 {
185 int ret;
186
187 ret = pthread_rwlock_wrlock(&array->lock);
188 if ((ret != 0) && (ret != EDEADLK))
189 return EINA_FALSE;
190 }
191 return EINA_TRUE;
192}
193
194static inline Eina_Bool
195eina_array_unlock(const Eina_Array *array)
196{
197 if (!array) return EINA_FALSE;
198 if (array->threadsafe)
199 if (pthread_rwlock_unlock(&((Eina_Array*) array)->lock))
200 return EINA_FALSE;
201 return EINA_TRUE;
202}
203
204#else
205
206static inline Eina_Bool
207eina_array_rdlock(const Eina_Array *array)
208{
209 if (!array) return EINA_FALSE;
210 return EINA_TRUE;
211}
212
213static inline Eina_Bool
214eina_array_wrlock(Eina_Array *array)
215{
216 if (!array) return EINA_FALSE;
217 return EINA_TRUE;
218}
219
220static inline Eina_Bool
221eina_array_unlock(const Eina_Array *array)
222{
223 if (!array) return EINA_FALSE;
224 return EINA_TRUE;
225}
226#endif
227
228/** 146/**
229 * @brief Provide a safe way to iterate over an array 147 * @brief Provide a safe way to iterate over an array
230 * 148 *
@@ -233,12 +151,9 @@ eina_array_unlock(const Eina_Array *array)
233 * @param fdata The user data to pass to the callback. 151 * @param fdata The user data to pass to the callback.
234 * @return EINA_TRUE if it successfully iterate all items of the array. 152 * @return EINA_TRUE if it successfully iterate all items of the array.
235 * 153 *
236 * This function provide a safe way to iterate over an array. If 154 * This function provide a safe way to iterate over an array. @p cb should
237 * the array was created with @p eina_array_threadsafe_new, it will 155 * return EINA_TRUE as long as you want the function to continue iterating,
238 * be correctly locked and unlocked. @p cb should return EINA_TRUE 156 * by returning EINA_FALSE it will stop and return EINA_FALSE as a result.
239 * as long as you want the function to continue iterating, by
240 * returning EINA_FALSE it will stop and return EINA_FALSE as a
241 * result.
242 */ 157 */
243static inline Eina_Bool 158static inline Eina_Bool
244eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata) 159eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata)
@@ -248,9 +163,6 @@ eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata)
248 unsigned int i; 163 unsigned int i;
249 Eina_Bool ret = EINA_TRUE; 164 Eina_Bool ret = EINA_TRUE;
250 165
251 if (EINA_UNLIKELY(!eina_array_wrlock(array)))
252 return EINA_FALSE;
253
254 EINA_ARRAY_ITER_NEXT(array, i, data, iterator) 166 EINA_ARRAY_ITER_NEXT(array, i, data, iterator)
255 if (cb(array, data, fdata) != EINA_TRUE) 167 if (cb(array, data, fdata) != EINA_TRUE)
256 { 168 {
@@ -258,8 +170,6 @@ eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata)
258 break; 170 break;
259 } 171 }
260 172
261 eina_array_unlock(array);
262
263 return ret; 173 return ret;
264} 174}
265 175
diff --git a/legacy/eina/src/lib/eina_array.c b/legacy/eina/src/lib/eina_array.c
index 3925e49d63..e379f23a1e 100644
--- a/legacy/eina/src/lib/eina_array.c
+++ b/legacy/eina/src/lib/eina_array.c
@@ -231,21 +231,6 @@ eina_array_iterator_free(Eina_Iterator_Array *it)
231 MAGIC_FREE(it); 231 MAGIC_FREE(it);
232} 232}
233 233
234#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
235static Eina_Bool
236eina_array_iterator_lock(Eina_Iterator_Array *it)
237{
238 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE);
239 return eina_array_wrlock((Eina_Array *) it->array);
240}
241
242static Eina_Bool
243eina_array_iterator_unlock(Eina_Iterator_Array *it)
244{
245 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE);
246 return eina_array_unlock(it->array);
247}
248#endif
249static Eina_Bool 234static Eina_Bool
250eina_array_accessor_get_at(Eina_Accessor_Array *it, 235eina_array_accessor_get_at(Eina_Accessor_Array *it,
251 unsigned int idx, 236 unsigned int idx,
@@ -276,21 +261,6 @@ eina_array_accessor_free(Eina_Accessor_Array *it)
276 MAGIC_FREE(it); 261 MAGIC_FREE(it);
277} 262}
278 263
279#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
280static Eina_Bool
281eina_array_accessor_lock(Eina_Accessor_Array *it)
282{
283 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE);
284 return eina_array_wrlock((Eina_Array *) it->array);
285}
286
287static Eina_Bool
288eina_array_accessor_unlock(Eina_Accessor_Array *it)
289{
290 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE);
291 return eina_array_unlock(it->array);
292}
293#endif
294EAPI Eina_Bool 264EAPI Eina_Bool
295eina_array_grow(Eina_Array *array) 265eina_array_grow(Eina_Array *array)
296{ 266{
@@ -449,64 +419,11 @@ eina_array_new(unsigned int step)
449 array->total = 0; 419 array->total = 0;
450 array->count = 0; 420 array->count = 0;
451 array->step = step; 421 array->step = step;
452#ifdef EINA_RWLOCKS_ENABLED
453 array->threadsafe = EINA_FALSE;
454#endif
455 422
456 return array; 423 return array;
457} 424}
458 425
459/** 426/**
460 * @brief Create a new array that is threadsafe.
461 *
462 * @param step The count of pointers to add when increasing the array size.
463 * @return @c NULL on failure, non @c NULL otherwise.
464 *
465 * This function creates a new array which is different than a normal array.
466 * Arrays created with this function will automatically mutex themselves in eina_array_*
467 * function calls. In order to ensure that the created array operates successfully
468 * in a threadsafe environment, only EINA_ARRAY_THREADSAFE_* macros can be used with
469 * this type of list.
470 * When adding an element, the array allocates @p step elements. When that buffer is
471 * full, then adding another element will increase the buffer of @p step elements again.
472 *
473 * This function return a valid array on success, or @c NULL if memory
474 * allocation fails. In that case, the error is set to
475 * #EINA_ERROR_OUT_OF_MEMORY.
476 */
477EAPI Eina_Array *
478eina_array_threadsafe_new(unsigned int step)
479{
480#ifdef EINA_RWLOCKS_ENABLED
481 Eina_Array *array;
482
483 eina_error_set(0);
484 array = malloc(sizeof (Eina_Array));
485 if (!array)
486 {
487 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
488 return NULL;
489 }
490
491 EINA_MAGIC_SET(array, EINA_MAGIC_ARRAY);
492
493 array->data = NULL;
494 array->total = 0;
495 array->count = 0;
496 array->step = step;
497
498 pthread_rwlock_init(&array->lock, NULL);
499 array->threadsafe = EINA_TRUE;
500
501 return array;
502#else
503 (void) step;
504
505 return NULL;
506#endif
507}
508
509/**
510 * @brief Free an array. 427 * @brief Free an array.
511 * 428 *
512 * @param array The array to free. 429 * @param array The array to free.
@@ -523,13 +440,7 @@ eina_array_free(Eina_Array *array)
523 eina_array_flush(array); 440 eina_array_flush(array);
524 441
525 EINA_SAFETY_ON_NULL_RETURN(array); 442 EINA_SAFETY_ON_NULL_RETURN(array);
526 if (!eina_array_wrlock(array))
527 return;
528 EINA_MAGIC_CHECK_ARRAY(array); 443 EINA_MAGIC_CHECK_ARRAY(array);
529#ifdef EINA_RWLOCKS_ENABLED
530 if (array->threadsafe)
531 pthread_rwlock_destroy(&array->lock);
532#endif
533 MAGIC_FREE(array); 444 MAGIC_FREE(array);
534} 445}
535 446
@@ -552,9 +463,6 @@ eina_array_step_set(Eina_Array *array, unsigned int step)
552 array->total = 0; 463 array->total = 0;
553 array->count = 0; 464 array->count = 0;
554 array->step = step; 465 array->step = step;
555#ifdef EINA_RWLOCKS_ENABLED
556 array->threadsafe = EINA_FALSE;
557#endif
558 EINA_MAGIC_SET(array, EINA_MAGIC_ARRAY); 466 EINA_MAGIC_SET(array, EINA_MAGIC_ARRAY);
559} 467}
560 468
@@ -573,11 +481,7 @@ eina_array_clean(Eina_Array *array)
573 EINA_SAFETY_ON_NULL_RETURN(array); 481 EINA_SAFETY_ON_NULL_RETURN(array);
574 EINA_MAGIC_CHECK_ARRAY(array); 482 EINA_MAGIC_CHECK_ARRAY(array);
575 483
576 if (!eina_array_wrlock(array))
577 return;
578
579 array->count = 0; 484 array->count = 0;
580 eina_array_unlock(array);
581} 485}
582 486
583/** 487/**
@@ -595,8 +499,7 @@ eina_array_flush(Eina_Array *array)
595{ 499{
596 EINA_SAFETY_ON_NULL_RETURN(array); 500 EINA_SAFETY_ON_NULL_RETURN(array);
597 EINA_MAGIC_CHECK_ARRAY(array); 501 EINA_MAGIC_CHECK_ARRAY(array);
598 if (!eina_array_wrlock(array)) 502
599 return;
600 array->count = 0; 503 array->count = 0;
601 array->total = 0; 504 array->total = 0;
602 505
@@ -605,7 +508,6 @@ eina_array_flush(Eina_Array *array)
605 508
606 free(array->data); 509 free(array->data);
607 array->data = NULL; 510 array->data = NULL;
608 eina_array_unlock(array);
609} 511}
610 512
611/** 513/**
@@ -642,8 +544,6 @@ eina_array_remove(Eina_Array *array, Eina_Bool (*keep)(void *data,
642 544
643 EINA_SAFETY_ON_NULL_RETURN_VAL(array, EINA_FALSE); 545 EINA_SAFETY_ON_NULL_RETURN_VAL(array, EINA_FALSE);
644 EINA_SAFETY_ON_NULL_RETURN_VAL(keep, EINA_FALSE); 546 EINA_SAFETY_ON_NULL_RETURN_VAL(keep, EINA_FALSE);
645 if (!eina_array_wrlock(array))
646 return EINA_FALSE;
647 EINA_MAGIC_CHECK_ARRAY(array); 547 EINA_MAGIC_CHECK_ARRAY(array);
648 548
649 if (array->total == 0) 549 if (array->total == 0)
@@ -718,7 +618,6 @@ eina_array_remove(Eina_Array *array, Eina_Bool (*keep)(void *data,
718 618
719 array->data = tmp; 619 array->data = tmp;
720 array->count = total; 620 array->count = total;
721 eina_array_unlock(array);
722 return EINA_TRUE; 621 return EINA_TRUE;
723} 622}
724 623
@@ -760,14 +659,6 @@ eina_array_iterator_new(const Eina_Array *array)
760 eina_array_iterator_get_container); 659 eina_array_iterator_get_container);
761 it->iterator.free = FUNC_ITERATOR_FREE(eina_array_iterator_free); 660 it->iterator.free = FUNC_ITERATOR_FREE(eina_array_iterator_free);
762 661
763#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
764 if (array->threadsafe)
765 {
766 it->iterator.lock = FUNC_ITERATOR_LOCK(eina_array_iterator_lock);
767 it->iterator.unlock = FUNC_ITERATOR_LOCK(eina_array_iterator_unlock);
768 }
769#endif
770
771 return &it->iterator; 662 return &it->iterator;
772} 663}
773 664
@@ -809,13 +700,6 @@ eina_array_accessor_new(const Eina_Array *array)
809 eina_array_accessor_get_container); 700 eina_array_accessor_get_container);
810 it->accessor.free = FUNC_ACCESSOR_FREE(eina_array_accessor_free); 701 it->accessor.free = FUNC_ACCESSOR_FREE(eina_array_accessor_free);
811 702
812#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
813 if (array->threadsafe)
814 {
815 it->accessor.lock = FUNC_ACCESSOR_LOCK(eina_array_accessor_lock);
816 it->accessor.unlock = FUNC_ACCESSOR_LOCK(eina_array_accessor_unlock);
817 }
818#endif
819 return &it->accessor; 703 return &it->accessor;
820} 704}
821 705
diff --git a/legacy/eina/src/lib/eina_hash.c b/legacy/eina/src/lib/eina_hash.c
index d28e5bad00..19e156af4c 100644
--- a/legacy/eina/src/lib/eina_hash.c
+++ b/legacy/eina/src/lib/eina_hash.c
@@ -86,11 +86,6 @@ struct _Eina_Hash
86 86
87 int population; 87 int population;
88 88
89#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
90 pthread_rwlock_t lock;
91 Eina_Bool threadsafe:1;
92#endif
93
94 EINA_MAGIC 89 EINA_MAGIC
95}; 90};
96 91
@@ -154,71 +149,6 @@ struct _Eina_Hash_Each
154 + (uint32_t)(((const uint8_t *)(d))[0])) 149 + (uint32_t)(((const uint8_t *)(d))[0]))
155#endif 150#endif
156 151
157#ifdef EINA_RWLOCKS_ENABLED
158static inline Eina_Bool
159eina_hash_rdlock(const Eina_Hash *hash)
160{
161 if (!hash) return EINA_FALSE;
162 if (hash->threadsafe)
163 {
164 int ret;
165
166 ret = pthread_rwlock_rdlock(&((Eina_Hash*) hash)->lock);
167 if ((ret != 0) && (ret != EDEADLK))
168 return EINA_FALSE;
169 }
170 return EINA_TRUE;
171}
172
173static inline Eina_Bool
174eina_hash_wrlock(Eina_Hash *hash)
175{
176 if (!hash) return EINA_FALSE;
177 if (hash->threadsafe)
178 {
179 int ret;
180
181 ret = pthread_rwlock_wrlock(&hash->lock);
182 if ((ret != 0) && (ret != EDEADLK))
183 return EINA_FALSE;
184 }
185 return EINA_TRUE;
186}
187
188static inline Eina_Bool
189eina_hash_unlock(const Eina_Hash *hash)
190{
191 if (!hash) return EINA_FALSE;
192 if (hash->threadsafe)
193 if (pthread_rwlock_unlock(&((Eina_Hash*) hash)->lock))
194 return EINA_FALSE;
195 return EINA_TRUE;
196}
197
198#else
199
200static inline Eina_Bool
201eina_hash_rdlock(const Eina_Hash *hash)
202{
203 if (!hash) return EINA_FALSE;
204 return EINA_TRUE;
205}
206
207static inline Eina_Bool
208eina_hash_wrlock(Eina_Hash *hash)
209{
210 if (!hash) return EINA_FALSE;
211 return EINA_TRUE;
212}
213
214static inline Eina_Bool
215eina_hash_unlock(const Eina_Hash *hash)
216{
217 if (!hash) return EINA_FALSE;
218 return EINA_TRUE;
219}
220#endif
221
222static inline int 152static inline int
223_eina_hash_hash_rbtree_cmp_hash(const Eina_Hash_Head *hash_head, 153_eina_hash_hash_rbtree_cmp_hash(const Eina_Hash_Head *hash_head,
224 const int *hash, 154 const int *hash,
@@ -760,22 +690,6 @@ _eina_hash_iterator_free(Eina_Iterator_Hash *it)
760 free(it); 690 free(it);
761} 691}
762 692
763#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
764static Eina_Bool
765_eina_hash_iterator_lock(Eina_Iterator_Hash *it)
766{
767 EINA_MAGIC_CHECK_HASH_ITERATOR(it, EINA_FALSE);
768 return eina_hash_wrlock((Eina_Hash*)it->hash);
769}
770
771static Eina_Bool
772_eina_hash_iterator_unlock(Eina_Iterator_Hash *it)
773{
774 EINA_MAGIC_CHECK_HASH_ITERATOR(it, EINA_FALSE);
775 return eina_hash_unlock((Eina_Hash*)it->hash);
776}
777#endif
778
779/** 693/**
780 * @endcond 694 * @endcond
781 */ 695 */
@@ -839,9 +753,6 @@ eina_hash_new(Eina_Key_Length key_length_cb,
839 new->data_free_cb = data_free_cb; 753 new->data_free_cb = data_free_cb;
840 new->buckets = NULL; 754 new->buckets = NULL;
841 new->population = 0; 755 new->population = 0;
842#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
843 new->threadsafe = EINA_FALSE;
844#endif
845 756
846 new->size = 1 << buckets_power_size; 757 new->size = 1 << buckets_power_size;
847 new->mask = new->size - 1; 758 new->mask = new->size - 1;
@@ -1050,18 +961,12 @@ eina_hash_free(Eina_Hash *hash)
1050 EINA_MAGIC_CHECK_HASH(hash); 961 EINA_MAGIC_CHECK_HASH(hash);
1051 EINA_SAFETY_ON_NULL_RETURN(hash); 962 EINA_SAFETY_ON_NULL_RETURN(hash);
1052 963
1053 if (!eina_hash_wrlock(hash))
1054 return;
1055 if (hash->buckets) 964 if (hash->buckets)
1056 { 965 {
1057 for (i = 0; i < hash->size; i++) 966 for (i = 0; i < hash->size; i++)
1058 eina_rbtree_delete(hash->buckets[i], EINA_RBTREE_FREE_CB(_eina_hash_head_free), hash); 967 eina_rbtree_delete(hash->buckets[i], EINA_RBTREE_FREE_CB(_eina_hash_head_free), hash);
1059 free(hash->buckets); 968 free(hash->buckets);
1060 } 969 }
1061#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
1062 if (hash->threadsafe)
1063 pthread_rwlock_destroy(&hash->lock);
1064#endif
1065 free(hash); 970 free(hash);
1066} 971}
1067 972
@@ -1082,8 +987,6 @@ eina_hash_free_buckets(Eina_Hash *hash)
1082 EINA_MAGIC_CHECK_HASH(hash); 987 EINA_MAGIC_CHECK_HASH(hash);
1083 EINA_SAFETY_ON_NULL_RETURN(hash); 988 EINA_SAFETY_ON_NULL_RETURN(hash);
1084 989
1085 if (!eina_hash_wrlock(hash))
1086 return;
1087 if (hash->buckets) 990 if (hash->buckets)
1088 { 991 {
1089 for (i = 0; i < hash->size; i++) 992 for (i = 0; i < hash->size; i++)
@@ -1093,7 +996,6 @@ eina_hash_free_buckets(Eina_Hash *hash)
1093 hash->buckets = NULL; 996 hash->buckets = NULL;
1094 hash->population = 0; 997 hash->population = 0;
1095 } 998 }
1096 eina_hash_unlock(hash);
1097} 999}
1098 1000
1099/** 1001/**
@@ -1125,18 +1027,12 @@ eina_hash_add_by_hash(Eina_Hash *hash,
1125 const void *key, int key_length, int key_hash, 1027 const void *key, int key_length, int key_hash,
1126 const void *data) 1028 const void *data)
1127{ 1029{
1128 Eina_Bool ret; 1030 return eina_hash_add_alloc_by_hash(hash,
1129 if (!eina_hash_wrlock(hash)) 1031 key,
1130 return EINA_FALSE;
1131
1132 ret = eina_hash_add_alloc_by_hash(hash,
1133 key,
1134 key_length, 1032 key_length,
1135 key_length, 1033 key_length,
1136 key_hash, 1034 key_hash,
1137 data); 1035 data);
1138 eina_hash_unlock(hash);
1139 return ret;
1140} 1036}
1141 1037
1142/** 1038/**
@@ -1169,13 +1065,7 @@ eina_hash_direct_add_by_hash(Eina_Hash *hash,
1169 const void *key, int key_length, int key_hash, 1065 const void *key, int key_length, int key_hash,
1170 const void *data) 1066 const void *data)
1171{ 1067{
1172 Eina_Bool ret; 1068 return eina_hash_add_alloc_by_hash(hash, key, key_length, 0, key_hash, data);
1173 if (!eina_hash_wrlock(hash))
1174 return EINA_FALSE;
1175
1176 ret = eina_hash_add_alloc_by_hash(hash, key, key_length, 0, key_hash, data);
1177 eina_hash_unlock(hash);
1178 return ret;
1179} 1069}
1180 1070
1181/** 1071/**
@@ -1204,7 +1094,6 @@ eina_hash_add(Eina_Hash *hash, const void *key, const void *data)
1204{ 1094{
1205 unsigned int key_length; 1095 unsigned int key_length;
1206 int key_hash; 1096 int key_hash;
1207 Eina_Bool ret;
1208 1097
1209 EINA_MAGIC_CHECK_HASH(hash); 1098 EINA_MAGIC_CHECK_HASH(hash);
1210 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1099 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
@@ -1212,15 +1101,10 @@ eina_hash_add(Eina_Hash *hash, const void *key, const void *data)
1212 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE); 1101 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE);
1213 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE); 1102 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
1214 1103
1215 if (!eina_hash_wrlock(hash))
1216 return EINA_FALSE;
1217
1218 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0; 1104 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0;
1219 key_hash = hash->key_hash_cb(key, key_length); 1105 key_hash = hash->key_hash_cb(key, key_length);
1220 1106
1221 ret = eina_hash_add_alloc_by_hash(hash, key, key_length, key_length, key_hash, data); 1107 return eina_hash_add_alloc_by_hash(hash, key, key_length, key_length, key_hash, data);
1222 eina_hash_unlock(hash);
1223 return ret;
1224} 1108}
1225 1109
1226/** 1110/**
@@ -1251,7 +1135,6 @@ eina_hash_direct_add(Eina_Hash *hash, const void *key, const void *data)
1251{ 1135{
1252 int key_length; 1136 int key_length;
1253 int key_hash; 1137 int key_hash;
1254 Eina_Bool ret;
1255 1138
1256 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1139 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
1257 EINA_SAFETY_ON_NULL_RETURN_VAL(hash->key_hash_cb, EINA_FALSE); 1140 EINA_SAFETY_ON_NULL_RETURN_VAL(hash->key_hash_cb, EINA_FALSE);
@@ -1259,15 +1142,10 @@ eina_hash_direct_add(Eina_Hash *hash, const void *key, const void *data)
1259 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE); 1142 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
1260 EINA_MAGIC_CHECK_HASH(hash); 1143 EINA_MAGIC_CHECK_HASH(hash);
1261 1144
1262 if (!eina_hash_wrlock(hash))
1263 return EINA_FALSE;
1264
1265 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0; 1145 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0;
1266 key_hash = hash->key_hash_cb(key, key_length); 1146 key_hash = hash->key_hash_cb(key, key_length);
1267 1147
1268 ret = eina_hash_add_alloc_by_hash(hash, key, key_length, 0, key_hash, data); 1148 return eina_hash_add_alloc_by_hash(hash, key, key_length, 0, key_hash, data);
1269 eina_hash_unlock(hash);
1270 return ret;
1271} 1149}
1272 1150
1273/** 1151/**
@@ -1292,16 +1170,10 @@ eina_hash_del_by_key_hash(Eina_Hash *hash,
1292 int key_length, 1170 int key_length,
1293 int key_hash) 1171 int key_hash)
1294{ 1172{
1295 Eina_Bool ret;
1296 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1173 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
1297 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE); 1174 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE);
1298 1175
1299 if (!eina_hash_wrlock(hash)) 1176 return _eina_hash_del_by_key_hash(hash, key, key_length, key_hash, NULL);
1300 return EINA_FALSE;
1301 ret = _eina_hash_del_by_key_hash(hash, key, key_length, key_hash, NULL);
1302
1303 eina_hash_unlock(hash);
1304 return ret;
1305} 1177}
1306 1178
1307/** 1179/**
@@ -1323,15 +1195,10 @@ eina_hash_del_by_key_hash(Eina_Hash *hash,
1323EAPI Eina_Bool 1195EAPI Eina_Bool
1324eina_hash_del_by_key(Eina_Hash *hash, const void *key) 1196eina_hash_del_by_key(Eina_Hash *hash, const void *key)
1325{ 1197{
1326 Eina_Bool ret;
1327 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1198 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
1328 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE); 1199 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE);
1329 1200
1330 if (!eina_hash_wrlock(hash)) 1201 return _eina_hash_del_by_key(hash, key, NULL);
1331 return EINA_FALSE;
1332 ret = _eina_hash_del_by_key(hash, key, NULL);
1333 eina_hash_unlock(hash);
1334 return ret;
1335} 1202}
1336 1203
1337/** 1204/**
@@ -1351,7 +1218,6 @@ eina_hash_del_by_key(Eina_Hash *hash, const void *key)
1351EAPI Eina_Bool 1218EAPI Eina_Bool
1352eina_hash_del_by_data(Eina_Hash *hash, const void *data) 1219eina_hash_del_by_data(Eina_Hash *hash, const void *data)
1353{ 1220{
1354 Eina_Bool ret = EINA_FALSE;
1355 Eina_Hash_Element *hash_element; 1221 Eina_Hash_Element *hash_element;
1356 Eina_Hash_Head *hash_head; 1222 Eina_Hash_Head *hash_head;
1357 int key_hash; 1223 int key_hash;
@@ -1360,9 +1226,6 @@ eina_hash_del_by_data(Eina_Hash *hash, const void *data)
1360 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE); 1226 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
1361 EINA_MAGIC_CHECK_HASH(hash); 1227 EINA_MAGIC_CHECK_HASH(hash);
1362 1228
1363 if (!eina_hash_wrlock(hash))
1364 return EINA_FALSE;
1365
1366 hash_element = _eina_hash_find_by_data(hash, data, &key_hash, &hash_head); 1229 hash_element = _eina_hash_find_by_data(hash, data, &key_hash, &hash_head);
1367 if (!hash_element) 1230 if (!hash_element)
1368 goto error; 1231 goto error;
@@ -1370,11 +1233,10 @@ eina_hash_del_by_data(Eina_Hash *hash, const void *data)
1370 if (hash_element->tuple.data != data) 1233 if (hash_element->tuple.data != data)
1371 goto error; 1234 goto error;
1372 1235
1373 ret = _eina_hash_del_by_hash_el(hash, hash_element, hash_head, key_hash); 1236 return _eina_hash_del_by_hash_el(hash, hash_element, hash_head, key_hash);
1374 1237
1375error: 1238error:
1376 eina_hash_unlock(hash); 1239 return EINA_FALSE;
1377 return ret;
1378} 1240}
1379 1241
1380/** 1242/**
@@ -1407,17 +1269,15 @@ eina_hash_del_by_hash(Eina_Hash *hash,
1407 const void *data) 1269 const void *data)
1408{ 1270{
1409 Eina_Bool ret; 1271 Eina_Bool ret;
1272
1410 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1273 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
1411 EINA_MAGIC_CHECK_HASH(hash); 1274 EINA_MAGIC_CHECK_HASH(hash);
1412 1275
1413 if (!eina_hash_wrlock(hash))
1414 return EINA_FALSE;
1415
1416 if (key) 1276 if (key)
1417 ret = _eina_hash_del_by_key_hash(hash, key, key_length, key_hash, data); 1277 ret = _eina_hash_del_by_key_hash(hash, key, key_length, key_hash, data);
1418 else 1278 else
1419 ret = eina_hash_del_by_data(hash, data); 1279 ret = eina_hash_del_by_data(hash, data);
1420 eina_hash_unlock(hash); 1280
1421 return ret; 1281 return ret;
1422} 1282}
1423 1283
@@ -1445,19 +1305,13 @@ eina_hash_del_by_hash(Eina_Hash *hash,
1445EAPI Eina_Bool 1305EAPI Eina_Bool
1446eina_hash_del(Eina_Hash *hash, const void *key, const void *data) 1306eina_hash_del(Eina_Hash *hash, const void *key, const void *data)
1447{ 1307{
1448 Eina_Bool ret;
1449 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); 1308 EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
1450 EINA_MAGIC_CHECK_HASH(hash); 1309 EINA_MAGIC_CHECK_HASH(hash);
1451 1310
1452 if (!key) 1311 if (!key)
1453 return eina_hash_del_by_data(hash, data); 1312 return eina_hash_del_by_data(hash, data);
1454 1313
1455 if (!eina_hash_wrlock(hash)) 1314 return _eina_hash_del_by_key(hash, key, data);
1456 return EINA_FALSE;
1457
1458 ret = _eina_hash_del_by_key(hash, key, data);
1459 eina_hash_unlock(hash);
1460 return ret;
1461} 1315}
1462 1316
1463/** 1317/**
@@ -1489,11 +1343,7 @@ eina_hash_find_by_hash(const Eina_Hash *hash,
1489 tuple.key_length = key_length; 1343 tuple.key_length = key_length;
1490 tuple.data = NULL; 1344 tuple.data = NULL;
1491 1345
1492 if (!eina_hash_rdlock(hash))
1493 return NULL;;
1494
1495 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head); 1346 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head);
1496 eina_hash_unlock(hash);
1497 if (hash_element) 1347 if (hash_element)
1498 return hash_element->tuple.data; 1348 return hash_element->tuple.data;
1499 1349
@@ -1520,9 +1370,6 @@ eina_hash_find(const Eina_Hash *hash, const void *key)
1520 EINA_SAFETY_ON_NULL_RETURN_VAL(key, NULL); 1370 EINA_SAFETY_ON_NULL_RETURN_VAL(key, NULL);
1521 EINA_MAGIC_CHECK_HASH(hash); 1371 EINA_MAGIC_CHECK_HASH(hash);
1522 1372
1523 if (!eina_hash_rdlock(hash))
1524 return NULL;
1525
1526 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0; 1373 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0;
1527 hash_num = hash->key_hash_cb(key, key_length); 1374 hash_num = hash->key_hash_cb(key, key_length);
1528 1375
@@ -1561,9 +1408,6 @@ eina_hash_modify_by_hash(Eina_Hash *hash,
1561 tuple.key_length = key_length; 1408 tuple.key_length = key_length;
1562 tuple.data = NULL; 1409 tuple.data = NULL;
1563 1410
1564 if (!eina_hash_rdlock(hash))
1565 return NULL;
1566
1567 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head); 1411 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head);
1568 if (hash_element) 1412 if (hash_element)
1569 { 1413 {
@@ -1571,7 +1415,6 @@ eina_hash_modify_by_hash(Eina_Hash *hash,
1571 hash_element->tuple.data = (void *)data; 1415 hash_element->tuple.data = (void *)data;
1572 } 1416 }
1573 1417
1574 eina_hash_unlock(hash);
1575 return old_data; 1418 return old_data;
1576} 1419}
1577 1420
@@ -1602,9 +1445,6 @@ eina_hash_set(Eina_Hash *hash, const void *key, const void *data)
1602 EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL); 1445 EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL);
1603 EINA_MAGIC_CHECK_HASH(hash); 1446 EINA_MAGIC_CHECK_HASH(hash);
1604 1447
1605 if (!eina_hash_wrlock(hash))
1606 return NULL;
1607
1608 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0; 1448 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0;
1609 key_hash = hash->key_hash_cb(key, key_length); 1449 key_hash = hash->key_hash_cb(key, key_length);
1610 1450
@@ -1619,7 +1459,6 @@ eina_hash_set(Eina_Hash *hash, const void *key, const void *data)
1619 1459
1620 old_data = hash_element->tuple.data; 1460 old_data = hash_element->tuple.data;
1621 hash_element->tuple.data = (void *)data; 1461 hash_element->tuple.data = (void *)data;
1622 eina_hash_unlock(hash);
1623 return old_data; 1462 return old_data;
1624 } 1463 }
1625 1464
@@ -1652,9 +1491,6 @@ eina_hash_modify(Eina_Hash *hash, const void *key, const void *data)
1652 EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL); 1491 EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL);
1653 EINA_MAGIC_CHECK_HASH(hash); 1492 EINA_MAGIC_CHECK_HASH(hash);
1654 1493
1655 if (!eina_hash_wrlock(hash))
1656 return NULL;
1657
1658 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0; 1494 key_length = hash->key_length_cb ? hash->key_length_cb(key) : 0;
1659 hash_num = hash->key_hash_cb(key, key_length); 1495 hash_num = hash->key_hash_cb(key, key_length);
1660 1496
@@ -1684,11 +1520,7 @@ eina_hash_move(Eina_Hash *hash, const void *old_key, const void *new_key)
1684 EINA_SAFETY_ON_NULL_RETURN_VAL(new_key, EINA_FALSE); 1520 EINA_SAFETY_ON_NULL_RETURN_VAL(new_key, EINA_FALSE);
1685 EINA_MAGIC_CHECK_HASH(hash); 1521 EINA_MAGIC_CHECK_HASH(hash);
1686 1522
1687 if (!eina_hash_wrlock(hash))
1688 return EINA_FALSE;
1689
1690 data = eina_hash_find(hash, old_key); 1523 data = eina_hash_find(hash, old_key);
1691
1692 if (!data) goto error; 1524 if (!data) goto error;
1693 1525
1694 hash_free_cb = hash->data_free_cb; 1526 hash_free_cb = hash->data_free_cb;
@@ -1700,7 +1532,6 @@ eina_hash_move(Eina_Hash *hash, const void *old_key, const void *new_key)
1700 hash->data_free_cb = hash_free_cb; 1532 hash->data_free_cb = hash_free_cb;
1701 1533
1702error: 1534error:
1703 eina_hash_unlock(hash);
1704 return result; 1535 return result;
1705} 1536}
1706 1537
@@ -1805,13 +1636,7 @@ eina_hash_iterator_data_new(const Eina_Hash *hash)
1805 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER( 1636 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
1806 _eina_hash_iterator_get_container); 1637 _eina_hash_iterator_get_container);
1807 it->iterator.free = FUNC_ITERATOR_FREE(_eina_hash_iterator_free); 1638 it->iterator.free = FUNC_ITERATOR_FREE(_eina_hash_iterator_free);
1808#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK 1639
1809 if (hash->threadsafe)
1810 {
1811 it->iterator.lock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_lock;
1812 it->iterator.unlock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_unlock;
1813 }
1814#endif
1815 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR); 1640 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
1816 EINA_MAGIC_SET(it, EINA_MAGIC_HASH_ITERATOR); 1641 EINA_MAGIC_SET(it, EINA_MAGIC_HASH_ITERATOR);
1817 1642
@@ -1857,13 +1682,6 @@ eina_hash_iterator_key_new(const Eina_Hash *hash)
1857 it->get_content = FUNC_ITERATOR_GET_CONTENT( 1682 it->get_content = FUNC_ITERATOR_GET_CONTENT(
1858 _eina_hash_iterator_key_get_content); 1683 _eina_hash_iterator_key_get_content);
1859 1684
1860#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
1861 if (hash->threadsafe)
1862 {
1863 it->iterator.lock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_lock;
1864 it->iterator.unlock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_unlock;
1865 }
1866#endif
1867 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_hash_iterator_next); 1685 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_hash_iterator_next);
1868 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER( 1686 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
1869 _eina_hash_iterator_get_container); 1687 _eina_hash_iterator_get_container);
@@ -1918,14 +1736,6 @@ eina_hash_iterator_tuple_new(const Eina_Hash *hash)
1918 it->get_content = FUNC_ITERATOR_GET_CONTENT( 1736 it->get_content = FUNC_ITERATOR_GET_CONTENT(
1919 _eina_hash_iterator_tuple_get_content); 1737 _eina_hash_iterator_tuple_get_content);
1920 1738
1921#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
1922 if (hash->threadsafe)
1923 {
1924 it->iterator.lock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_lock;
1925 it->iterator.unlock = (Eina_Iterator_Lock_Callback)_eina_hash_iterator_unlock;
1926 }
1927#endif
1928
1929 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_hash_iterator_next); 1739 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_hash_iterator_next);
1930 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER( 1740 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
1931 _eina_hash_iterator_get_container); 1741 _eina_hash_iterator_get_container);
@@ -1993,147 +1803,6 @@ eina_hash_superfast(const char *key, int len)
1993 return hash; 1803 return hash;
1994} 1804}
1995 1805
1996/* *************************************************
1997 * THREADSAFE
1998 */
1999
2000/**
2001 * @addtogroup Eina_Hash_Threadsafe_Group Threadsafe Hash
2002 * @brief This hash will automatically lock itself upon being accessed, and is safe to use without mutexes in threads.
2003 * Threadsafe hash types are identical to regular hash types except that they will always mutex themselves properly upon being accessed
2004 * to prevent pointer collision when using the same hash in multiple threads. They function in exactly the same manner as a regular
2005 * hash table, and regular api functions will automatically lock threadsafe hashes.
2006 *
2007 * All threadsafe api functions have identical arguments to regular api functions.
2008 * @{
2009 */
2010EAPI Eina_Hash *
2011eina_hash_threadsafe_new(__UNUSED__ Eina_Key_Length key_length_cb,
2012 __UNUSED__ Eina_Key_Cmp key_cmp_cb,
2013 __UNUSED__ Eina_Key_Hash key_hash_cb,
2014 __UNUSED__ Eina_Free_Cb data_free_cb,
2015 __UNUSED__ int buckets_power_size)
2016{
2017#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
2018 /* FIXME: Use mempool. */
2019 Eina_Hash *new;
2020
2021 if (!(new = eina_hash_new(key_length_cb, key_cmp_cb, key_hash_cb, data_free_cb, buckets_power_size)))
2022 return NULL;
2023 new->threadsafe = EINA_TRUE;
2024 if (pthread_rwlock_init(&new->lock, NULL))
2025 {
2026 free(new);
2027 goto on_error;
2028 }
2029
2030 return new;
2031
2032on_error:
2033 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2034#endif
2035 return NULL;
2036}
2037
2038/**
2039 * @see eina_hash_string_djb2_new
2040 */
2041EAPI Eina_Hash *
2042eina_hash_threadsafe_string_djb2_new(Eina_Free_Cb data_free_cb)
2043{
2044 return eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length),
2045 EINA_KEY_CMP(_eina_string_key_cmp),
2046 EINA_KEY_HASH(eina_hash_djb2),
2047 data_free_cb,
2048 EINA_HASH_BUCKET_SIZE);
2049}
2050
2051/**
2052 * @brief
2053 * @see eina_hash_string_superfast_new
2054 */
2055EAPI Eina_Hash *
2056eina_hash_threadsafe_string_superfast_new(Eina_Free_Cb data_free_cb)
2057{
2058 return eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length),
2059 EINA_KEY_CMP(_eina_string_key_cmp),
2060 EINA_KEY_HASH(eina_hash_superfast),
2061 data_free_cb,
2062 EINA_HASH_BUCKET_SIZE);
2063}
2064
2065/**
2066 * @see eina_hash_string_small_new
2067 */
2068EAPI Eina_Hash *
2069eina_hash_threadsafe_string_small_new(Eina_Free_Cb data_free_cb)
2070{
2071 return eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length),
2072 EINA_KEY_CMP(_eina_string_key_cmp),
2073 EINA_KEY_HASH(eina_hash_superfast),
2074 data_free_cb,
2075 EINA_HASH_SMALL_BUCKET_SIZE);
2076}
2077
2078/**
2079 * @see eina_hash_int32_new
2080 */
2081EAPI Eina_Hash *
2082eina_hash_threadsafe_int32_new(Eina_Free_Cb data_free_cb)
2083{
2084 return eina_hash_new(EINA_KEY_LENGTH(_eina_int32_key_length),
2085 EINA_KEY_CMP(_eina_int32_key_cmp),
2086 EINA_KEY_HASH(eina_hash_int32),
2087 data_free_cb,
2088 EINA_HASH_BUCKET_SIZE);
2089}
2090
2091/**
2092 * @see eina_hash_int64_new
2093 */
2094EAPI Eina_Hash *
2095eina_hash_threadsafe_int64_new(Eina_Free_Cb data_free_cb)
2096{
2097 return eina_hash_new(EINA_KEY_LENGTH(_eina_int64_key_length),
2098 EINA_KEY_CMP(_eina_int64_key_cmp),
2099 EINA_KEY_HASH(eina_hash_int64),
2100 data_free_cb,
2101 EINA_HASH_BUCKET_SIZE);
2102}
2103
2104/**
2105 * @see eina_hash_pointer_new
2106 */
2107EAPI Eina_Hash *
2108eina_hash_threadsafe_pointer_new(Eina_Free_Cb data_free_cb)
2109{
2110#ifdef __LP64__
2111 return eina_hash_new(EINA_KEY_LENGTH(_eina_int64_key_length),
2112 EINA_KEY_CMP(_eina_int64_key_cmp),
2113 EINA_KEY_HASH(eina_hash_int64),
2114 data_free_cb,
2115 EINA_HASH_BUCKET_SIZE);
2116#else
2117 return eina_hash_new(EINA_KEY_LENGTH(_eina_int32_key_length),
2118 EINA_KEY_CMP(_eina_int32_key_cmp),
2119 EINA_KEY_HASH(eina_hash_int32),
2120 data_free_cb,
2121 EINA_HASH_BUCKET_SIZE);
2122#endif
2123}
2124/**
2125 * @see eina_hash_stringshared_new
2126 */
2127EAPI Eina_Hash *
2128eina_hash_threadsafe_stringshared_new(Eina_Free_Cb data_free_cb)
2129{
2130 return eina_hash_new(NULL,
2131 EINA_KEY_CMP(_eina_stringshared_key_cmp),
2132 EINA_KEY_HASH(eina_hash_superfast),
2133 data_free_cb,
2134 EINA_HASH_BUCKET_SIZE);
2135}
2136
2137/** 1806/**
2138 * @} 1807 * @}
2139 * @} 1808 * @}
diff --git a/legacy/eina/src/tests/eina_test_array.c b/legacy/eina/src/tests/eina_test_array.c
index 7f411f0e7d..dec8981d87 100644
--- a/legacy/eina/src/tests/eina_test_array.c
+++ b/legacy/eina/src/tests/eina_test_array.c
@@ -69,60 +69,6 @@ START_TEST(eina_array_simple)
69} 69}
70END_TEST 70END_TEST
71 71
72#ifdef EINA_RWLOCKS_ENABLED
73static Eina_Bool
74_eina_array_clean(Eina_Array *ea, char *tmp, unsigned int *i)
75{
76 fail_if(!ea);
77 fail_if((unsigned int)atoi(tmp) != *i);
78 free(tmp);
79
80 (*i)++;
81
82 return EINA_TRUE;
83}
84
85START_TEST(eina_array_threadsafe)
86{
87 Eina_Array *ea;
88 char *tmp;
89 unsigned int i;
90
91 eina_init();
92
93 ea = eina_array_threadsafe_new(11);
94 fail_if(!ea);
95
96 for (i = 0; i < 201; ++i)
97 {
98 tmp = malloc(sizeof(char) * 10);
99 fail_if(!tmp);
100 eina_convert_itoa(i, tmp);
101
102 eina_array_push(ea, tmp);
103 }
104
105 fail_if(eina_array_data_get(ea, 10) == NULL);
106 fail_if(atoi(eina_array_data_get(ea, 10)) != 10);
107 tmp = eina_array_pop(ea);
108 fail_if(tmp == NULL);
109 fail_if(atoi(tmp) != 200);
110 free(tmp);
111
112 i = 0;
113 eina_array_foreach(ea, EINA_EACH_CB(_eina_array_clean), &i);
114
115 fail_if(i != 200);
116
117 eina_array_clean(ea);
118 eina_array_flush(ea);
119 eina_array_free(ea);
120
121 eina_shutdown();
122}
123END_TEST
124#endif
125
126START_TEST(eina_array_static) 72START_TEST(eina_array_static)
127{ 73{
128 Eina_Array sea; 74 Eina_Array sea;
@@ -240,9 +186,6 @@ void
240eina_test_array(TCase *tc) 186eina_test_array(TCase *tc)
241{ 187{
242 tcase_add_test(tc, eina_array_simple); 188 tcase_add_test(tc, eina_array_simple);
243#ifdef EINA_RWLOCKS_ENABLED
244 tcase_add_test(tc, eina_array_threadsafe);
245#endif
246 tcase_add_test(tc, eina_array_static); 189 tcase_add_test(tc, eina_array_static);
247 tcase_add_test(tc, eina_array_remove_stuff); 190 tcase_add_test(tc, eina_array_remove_stuff);
248} 191}
diff --git a/legacy/eina/src/tests/eina_test_hash.c b/legacy/eina/src/tests/eina_test_hash.c
index d2100c6a17..aeeb655e7b 100644
--- a/legacy/eina/src/tests/eina_test_hash.c
+++ b/legacy/eina/src/tests/eina_test_hash.c
@@ -197,73 +197,10 @@ START_TEST(eina_hash_all_int)
197} 197}
198END_TEST 198END_TEST
199 199
200#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
201START_TEST(eina_hash_threadsafe_simple)
202{
203 Eina_Hash *hash = NULL;
204 int *test;
205 int array[] = { 1, 42, 4, 5, 6 };
206
207 /* As mempool is already initialized and it use hash, we should have 2 init. */
208 fail_if(eina_init() != 2);
209
210 hash = eina_hash_threadsafe_string_superfast_new(NULL);
211 fail_if(hash == NULL);
212
213 fail_if(eina_hash_add(hash, "1", &array[0]) != EINA_TRUE);
214 fail_if(eina_hash_add(hash, "42", &array[1]) != EINA_TRUE);
215 fail_if(eina_hash_direct_add(hash, "4", &array[2]) != EINA_TRUE);
216 fail_if(eina_hash_direct_add(hash, "5", &array[3]) != EINA_TRUE);
217 fail_if(eina_hash_add(hash, "", "") != EINA_TRUE);
218
219 test = eina_hash_find(hash, "4");
220 fail_if(!test);
221 fail_if(*test != 4);
222
223 test = eina_hash_find(hash, "42");
224 fail_if(!test);
225 fail_if(*test != 42);
226
227 eina_hash_foreach(hash, eina_foreach_check, NULL);
228
229 test = eina_hash_modify(hash, "5", &array[4]);
230 fail_if(!test);
231 fail_if(*test != 5);
232
233 test = eina_hash_find(hash, "5");
234 fail_if(!test);
235 fail_if(*test != 6);
236
237 fail_if(eina_hash_population(hash) != 5);
238
239 fail_if(eina_hash_find(hash, "120") != NULL);
240
241 fail_if(eina_hash_del(hash, "5", NULL) != EINA_TRUE);
242 fail_if(eina_hash_find(hash, "5") != NULL);
243
244 fail_if(eina_hash_del(hash, NULL, &array[2]) != EINA_TRUE);
245 fail_if(eina_hash_find(hash, "4") != NULL);
246
247 fail_if(eina_hash_del(hash, NULL, &array[2]) != EINA_FALSE);
248
249 fail_if(eina_hash_del(hash, "1", NULL) != EINA_TRUE);
250 fail_if(eina_hash_del(hash, "42", NULL) != EINA_TRUE);
251
252 eina_hash_free(hash);
253
254 /* Same comment as eina_init */
255 fail_if(eina_shutdown() != 1);
256}
257END_TEST
258#endif
259
260void eina_test_hash(TCase *tc) 200void eina_test_hash(TCase *tc)
261{ 201{
262 tcase_add_test(tc, eina_hash_simple); 202 tcase_add_test(tc, eina_hash_simple);
263 tcase_add_test(tc, eina_hash_extended); 203 tcase_add_test(tc, eina_hash_extended);
264 tcase_add_test(tc, eina_hash_double_item); 204 tcase_add_test(tc, eina_hash_double_item);
265 tcase_add_test(tc, eina_hash_all_int); 205 tcase_add_test(tc, eina_hash_all_int);
266#ifdef EFL_HAVE_POSIX_THREADS_RWLOCK
267 tcase_add_test(tc, eina_hash_threadsafe_simple);
268#endif
269} 206}