eina: fix api to actually work as expected.

SVN revision: 58871
This commit is contained in:
Cedric BAIL 2011-04-24 16:49:48 +00:00
parent 702c047238
commit bd1337f4cd
9 changed files with 105 additions and 206 deletions

View File

@ -32,32 +32,32 @@ eina_lock_new(Eina_Lock *mutex)
} }
static inline void static inline void
eina_lock_free(Eina_Lock mutex) eina_lock_free(Eina_Lock *mutex)
{ {
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(mutex);
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take(Eina_Lock mutex) eina_lock_take(Eina_Lock *mutex)
{ {
if (_threads_activated) if (_threads_activated)
return (pthread_mutex_lock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; return (pthread_mutex_lock(mutex) == 0) ? EINA_TRUE : EINA_FALSE;
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take_try(Eina_Lock mutex) eina_lock_take_try(Eina_Lock *mutex)
{ {
if (_threads_activated) if (_threads_activated)
return (pthread_mutex_trylock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; return (pthread_mutex_trylock(mutex) == 0) ? EINA_TRUE : EINA_FALSE;
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_release(Eina_Lock mutex) eina_lock_release(Eina_Lock *mutex)
{ {
if (_threads_activated) if (_threads_activated)
return (pthread_mutex_unlock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; return (pthread_mutex_unlock(mutex) == 0) ? EINA_TRUE : EINA_FALSE;
return EINA_FALSE; return EINA_FALSE;
} }

View File

@ -34,35 +34,35 @@ eina_lock_new(Eina_Lock *mutex)
} }
static inline void static inline void
eina_lock_free(Eina_Lock mutex) eina_lock_free(Eina_Lock *mutex)
{ {
DeleteCriticalSection(&mutex); DeleteCriticalSection(mutex);
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take(Eina_Lock mutex) eina_lock_take(Eina_Lock *mutex)
{ {
if (!_threads_activated) return EINA_FALSE; if (!_threads_activated) return EINA_FALSE;
EnterCriticalSection(&mutex); EnterCriticalSection(mutex);
return EINA_TRUE; return EINA_TRUE;
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take_try(Eina_Lock mutex) eina_lock_take_try(Eina_Lock *mutex)
{ {
if (!_threads_activated) return EINA_FALSE; if (!_threads_activated) return EINA_FALSE;
return TryEnterCriticalSection(&mutex) == 0 ? EINA_FALSE : EINA_TRUE; return TryEnterCriticalSection(mutex) == 0 ? EINA_FALSE : EINA_TRUE;
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_release(Eina_Lock mutex) eina_lock_release(Eina_Lock *mutex)
{ {
if (!_threads_activated) return EINA_FALSE; if (!_threads_activated) return EINA_FALSE;
LeaveCriticalSection(&mutex); LeaveCriticalSection(mutex);
return EINA_TRUE; return EINA_TRUE;
} }

View File

@ -36,19 +36,19 @@ eina_lock_new(Eina_Lock *mutex)
} }
static inline void static inline void
eina_lock_free(Eina_Lock mutex) eina_lock_free(Eina_Lock *mutex)
{ {
CloseHandle(mutex); CloseHandle(*mutex);
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take(Eina_Lock mutex) eina_lock_take(Eina_Lock *mutex)
{ {
DWORD res; DWORD res;
if (!_threads_activated) return EINA_FALSE; if (!_threads_activated) return EINA_FALSE;
res = WaitForSingleObject(mutex, INFINITE); res = WaitForSingleObject(*mutex, INFINITE);
if ((res == WAIT_ABANDONED) || (res == WAIT_FAILED)) if ((res == WAIT_ABANDONED) || (res == WAIT_FAILED))
return EINA_FALSE; return EINA_FALSE;
@ -56,17 +56,17 @@ eina_lock_take(Eina_Lock mutex)
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_take_try(Eina_Lock mutex) eina_lock_take_try(Eina_Lock *mutex)
{ {
return eina_lock_take(mutex); return eina_lock_take(*mutex);
} }
static inline Eina_Bool static inline Eina_Bool
eina_lock_release(Eina_Lock mutex) eina_lock_release(Eina_Lock *mutex)
{ {
if (!_threads_activated) return EINA_FALSE; if (!_threads_activated) return EINA_FALSE;
return ReleaseMutex(mutex); return ReleaseMutex(*mutex);
} }

View File

@ -46,10 +46,10 @@
#endif #endif
static inline Eina_Bool eina_lock_new(Eina_Lock *mutex); static inline Eina_Bool eina_lock_new(Eina_Lock *mutex);
static inline void eina_lock_free(Eina_Lock mutex); static inline void eina_lock_free(Eina_Lock *mutex);
static inline Eina_Bool eina_lock_take(Eina_Lock mutex); static inline Eina_Bool eina_lock_take(Eina_Lock *mutex);
static inline Eina_Bool eina_lock_take_try(Eina_Lock mutex); static inline Eina_Bool eina_lock_take_try(Eina_Lock *mutex);
static inline Eina_Bool eina_lock_release(Eina_Lock mutex); static inline Eina_Bool eina_lock_release(Eina_Lock *mutex);
/** /**
* @} * @}

View File

@ -226,7 +226,7 @@ eina_shutdown(void)
{ {
_eina_shutdown_from_desc(_eina_desc_setup + _eina_desc_setup_len); _eina_shutdown_from_desc(_eina_desc_setup + _eina_desc_setup_len);
eina_lock_free(_mutex); eina_lock_free(&_mutex);
} }
return _eina_main_count; return _eina_main_count;
@ -240,13 +240,13 @@ eina_threads_init(void)
int ret; int ret;
eina_lock_take(_mutex); eina_lock_take(&_mutex);
++_eina_main_thread_count; ++_eina_main_thread_count;
ret = _eina_main_thread_count; ret = _eina_main_thread_count;
if(_eina_main_thread_count > 1) if(_eina_main_thread_count > 1)
{ {
eina_lock_release(_mutex); eina_lock_release(&_mutex);
return ret; return ret;
} }
@ -254,7 +254,7 @@ eina_threads_init(void)
eina_log_threads_init(); eina_log_threads_init();
_threads_activated = EINA_TRUE; _threads_activated = EINA_TRUE;
eina_lock_release(_mutex); eina_lock_release(&_mutex);
return ret; return ret;
#else #else
@ -268,18 +268,18 @@ eina_threads_shutdown(void)
#ifdef EFL_HAVE_THREADS #ifdef EFL_HAVE_THREADS
int ret; int ret;
eina_lock_take(_mutex); eina_lock_take(&_mutex);
ret = --_eina_main_thread_count; ret = --_eina_main_thread_count;
if(_eina_main_thread_count > 0) if(_eina_main_thread_count > 0)
{ {
eina_lock_release(_mutex); eina_lock_release(&_mutex);
return ret; return ret;
} }
eina_share_common_threads_shutdown(); eina_share_common_threads_shutdown();
eina_log_threads_shutdown(); eina_log_threads_shutdown();
eina_lock_release(_mutex); eina_lock_release(&_mutex);
_threads_activated = EINA_FALSE; _threads_activated = EINA_FALSE;

View File

@ -77,6 +77,7 @@
#include "eina_rbtree.h" #include "eina_rbtree.h"
#include "eina_error.h" #include "eina_error.h"
#include "eina_log.h" #include "eina_log.h"
#include "eina_lock.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h" #include "eina_safety_checks.h"
@ -169,27 +170,9 @@ struct _Eina_Share_Common_Head
Eina_Share_Common_Node builtin_node; Eina_Share_Common_Node builtin_node;
}; };
#ifdef EFL_HAVE_THREADS
Eina_Bool _share_common_threads_activated = EINA_FALSE; Eina_Bool _share_common_threads_activated = EINA_FALSE;
# ifdef EFL_HAVE_POSIX_THREADS static Eina_Lock _mutex_big;
static pthread_mutex_t _mutex_big = PTHREAD_MUTEX_INITIALIZER;
# define SHARE_COMMON_LOCK_BIG() if(_share_common_threads_activated) \
pthread_mutex_lock(&_mutex_big)
# define SHARE_COMMON_UNLOCK_BIG() if(_share_common_threads_activated) \
pthread_mutex_unlock(&_mutex_big)
# else /* EFL_HAVE_WIN32_THREADS */
static HANDLE _mutex_big = NULL;
# define SHARE_COMMON_LOCK_BIG() if(_share_common_threads_activated) \
WaitForSingleObject(_mutex_big, INFINITE)
# define SHARE_COMMON_UNLOCK_BIG() if(_share_common_threads_activated) \
ReleaseMutex(_mutex_big)
# endif /* EFL_HAVE_WIN32_THREADS */
#else /* EFL_HAVE_THREADS */
# define SHARE_COMMON_LOCK_BIG() do {} while (0)
# define SHARE_COMMON_UNLOCK_BIG() do {} while (0)
#endif
#ifdef EINA_SHARE_COMMON_USAGE #ifdef EINA_SHARE_COMMON_USAGE
struct _Eina_Share_Common_Population struct _Eina_Share_Common_Population
@ -269,7 +252,7 @@ _eina_share_common_population_stats(Eina_Share *share)
void void
eina_share_common_population_add(Eina_Share *share, int slen) eina_share_common_population_add(Eina_Share *share, int slen)
{ {
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
share->population.count++; share->population.count++;
if (share->population.count > share->population.max) if (share->population.count > share->population.max)
@ -284,19 +267,19 @@ eina_share_common_population_add(Eina_Share *share, int slen)
share->population_group[slen].count; share->population_group[slen].count;
} }
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
} }
void void
eina_share_common_population_del(Eina_Share *share, int slen) eina_share_common_population_del(Eina_Share *share, int slen)
{ {
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
share->population.count--; share->population.count--;
if (slen < 4) if (slen < 4)
share->population_group[slen].count--; share->population_group[slen].count--;
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
} }
static void static void
@ -571,7 +554,7 @@ eina_iterator_array_check(const Eina_Rbtree *rbtree __UNUSED__,
{ {
Eina_Share_Common_Node *node; Eina_Share_Common_Node *node;
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
fdata->used += sizeof(Eina_Share_Common_Head); fdata->used += sizeof(Eina_Share_Common_Head);
for (node = head->head; node; node = node->next) for (node = head->head; node; node = node->next)
@ -585,7 +568,7 @@ eina_iterator_array_check(const Eina_Rbtree *rbtree __UNUSED__,
fdata->unique++; fdata->unique++;
} }
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return EINA_TRUE; return EINA_TRUE;
} }
@ -652,6 +635,8 @@ eina_share_common_init(Eina_Share **_share,
EINA_MAGIC_SET(share->share, EINA_MAGIC_SHARE); EINA_MAGIC_SET(share->share, EINA_MAGIC_SHARE);
_eina_share_common_population_init(share); _eina_share_common_population_init(share);
eina_lock_new(&_mutex_big);
return EINA_TRUE; return EINA_TRUE;
} }
@ -672,7 +657,7 @@ eina_share_common_shutdown(Eina_Share **_share)
unsigned int i; unsigned int i;
Eina_Share *share = *_share; Eina_Share *share = *_share;
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
_eina_share_common_population_stats(share); _eina_share_common_population_stats(share);
@ -694,7 +679,9 @@ eina_share_common_shutdown(Eina_Share **_share)
_eina_share_common_log_dom = -1; _eina_share_common_log_dom = -1;
} }
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
eina_lock_free(&_mutex_big);
free(*_share); free(*_share);
*_share = NULL; *_share = NULL;
@ -765,7 +752,7 @@ eina_share_common_add_length(Eina_Share *share,
hash_num = hash & 0xFF; hash_num = hash & 0xFF;
hash = (hash >> 8) & EINA_SHARE_COMMON_MASK; hash = (hash >> 8) & EINA_SHARE_COMMON_MASK;
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
p_bucket = share->share->buckets + hash_num; p_bucket = share->share->buckets + hash_num;
ed = _eina_share_common_find_hash(*p_bucket, hash); ed = _eina_share_common_find_hash(*p_bucket, hash);
@ -777,27 +764,27 @@ eina_share_common_add_length(Eina_Share *share,
str, str,
slen, slen,
null_size); null_size);
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return s; return s;
} }
EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, SHARE_COMMON_UNLOCK_BIG(), NULL); EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), NULL);
el = _eina_share_common_head_find(ed, str, slen); el = _eina_share_common_head_find(ed, str, slen);
if (el) if (el)
{ {
EINA_MAGIC_CHECK_SHARE_COMMON_NODE(el, EINA_MAGIC_CHECK_SHARE_COMMON_NODE(el,
share->node_magic, share->node_magic,
SHARE_COMMON_UNLOCK_BIG()); eina_lock_release(&_mutex_big));
el->references++; el->references++;
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return el->str; return el->str;
} }
el = _eina_share_common_node_alloc(slen, null_size); el = _eina_share_common_node_alloc(slen, null_size);
if (!el) if (!el)
{ {
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return NULL; return NULL;
} }
@ -806,7 +793,7 @@ eina_share_common_add_length(Eina_Share *share,
ed->head = el; ed->head = el;
_eina_share_common_population_head_add(share, ed); _eina_share_common_population_head_add(share, ed);
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return el->str; return el->str;
} }
@ -819,13 +806,13 @@ eina_share_common_ref(Eina_Share *share, const char *str)
if (!str) if (!str)
return NULL; return NULL;
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
node = _eina_share_common_node_from_str(str, share->node_magic); node = _eina_share_common_node_from_str(str, share->node_magic);
if (!node) return str; if (!node) return str;
node->references++; node->references++;
DBG("str=%p refs=%u", str, node->references); DBG("str=%p refs=%u", str, node->references);
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
eina_share_common_population_add(share, node->length); eina_share_common_population_add(share, node->length);
@ -845,7 +832,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
if (!str) if (!str)
return; return;
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
node = _eina_share_common_node_from_str(str, share->node_magic); node = _eina_share_common_node_from_str(str, share->node_magic);
if (!node) if (!node)
@ -857,7 +844,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
{ {
node->references--; node->references--;
DBG("str=%p refs=%u", str, node->references); DBG("str=%p refs=%u", str, node->references);
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return; return;
} }
@ -873,7 +860,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
if (!ed) if (!ed)
goto on_error; goto on_error;
EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, SHARE_COMMON_UNLOCK_BIG()); EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big));
if (!_eina_share_common_head_remove_node(ed, node)) if (!_eina_share_common_head_remove_node(ed, node))
goto on_error; goto on_error;
@ -886,12 +873,12 @@ eina_share_common_del(Eina_Share *share, const char *str)
else else
_eina_share_common_population_head_del(share, ed); _eina_share_common_population_head_del(share, ed);
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
return; return;
on_error: on_error:
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
/* possible segfault happened before here, but... */ /* possible segfault happened before here, but... */
CRITICAL("EEEK trying to del non-shared share_common \"%s\"", str); CRITICAL("EEEK trying to del non-shared share_common \"%s\"", str);
} }
@ -927,7 +914,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)(
printf("DDD: len ref string\n"); printf("DDD: len ref string\n");
printf("DDD:-------------------\n"); printf("DDD:-------------------\n");
SHARE_COMMON_LOCK_BIG(); eina_lock_take(&_mutex_big);
for (i = 0; i < EINA_SHARE_COMMON_BUCKETS; i++) for (i = 0; i < EINA_SHARE_COMMON_BUCKETS; i++)
{ {
if (!share->share->buckets[i]) if (!share->share->buckets[i])
@ -971,7 +958,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)(
share->population_group[i].max); share->population_group[i].max);
#endif #endif
SHARE_COMMON_UNLOCK_BIG(); eina_lock_release(&_mutex_big);
} }
/** /**

View File

@ -47,10 +47,6 @@ void *alloca (size_t);
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
#ifdef HAVE_EVIL #ifdef HAVE_EVIL
# include <Evil.h> # include <Evil.h>
#endif #endif
@ -62,6 +58,7 @@ void *alloca (size_t);
#include "eina_error.h" #include "eina_error.h"
#include "eina_log.h" #include "eina_log.h"
#include "eina_stringshare.h" #include "eina_stringshare.h"
#include "eina_lock.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h" #include "eina_safety_checks.h"
@ -71,27 +68,8 @@ void *alloca (size_t);
static Eina_Share *stringshare_share; static Eina_Share *stringshare_share;
static const char EINA_MAGIC_STRINGSHARE_NODE_STR[] = "Eina Stringshare Node"; static const char EINA_MAGIC_STRINGSHARE_NODE_STR[] = "Eina Stringshare Node";
#ifdef EFL_HAVE_THREADS
extern Eina_Bool _share_common_threads_activated; extern Eina_Bool _share_common_threads_activated;
static Eina_Lock _mutex_small;
# ifdef EFL_HAVE_POSIX_THREADS
static pthread_mutex_t _mutex_small = PTHREAD_MUTEX_INITIALIZER;
# define STRINGSHARE_LOCK_SMALL() if(_share_common_threads_activated) \
pthread_mutex_lock(&_mutex_small)
# define STRINGSHARE_UNLOCK_SMALL() if(_share_common_threads_activated) \
pthread_mutex_unlock(&_mutex_small)
# else /* EFL_HAVE_WIN32_THREADS */
static HANDLE _mutex_small = NULL;
# define STRINGSHARE_LOCK_SMALL() if(_share_common_threads_activated) \
WaitForSingleObject(_mutex_small, INFINITE)
# define STRINGSHARE_UNLOCK_SMALL() if(_share_common_threads_activated) \
ReleaseMutex(_mutex_small)
# endif /* EFL_HAVE_WIN32_THREADS */
#else /* EFL_HAVE_THREADS */
# define STRINGSHARE_LOCK_SMALL() do {} while (0)
# define STRINGSHARE_UNLOCK_SMALL() do {} while (0)
#endif
/* Stringshare optimizations */ /* Stringshare optimizations */
static const unsigned char _eina_stringshare_single[512] = { static const unsigned char _eina_stringshare_single[512] = {
@ -418,6 +396,7 @@ error:
static void static void
_eina_stringshare_small_init(void) _eina_stringshare_small_init(void)
{ {
eina_lock_new(&_mutex_small);
memset(&_eina_small_share, 0, sizeof(_eina_small_share)); memset(&_eina_small_share, 0, sizeof(_eina_small_share));
} }
@ -448,6 +427,8 @@ _eina_stringshare_small_shutdown(void)
free(bucket); free(bucket);
*p_bucket = NULL; *p_bucket = NULL;
} }
eina_lock_free(&_mutex_small);
} }
static void static void
@ -579,9 +560,9 @@ eina_stringshare_del(const char *str)
else if (slen < 4) else if (slen < 4)
{ {
eina_share_common_population_del(stringshare_share, slen); eina_share_common_population_del(stringshare_share, slen);
STRINGSHARE_LOCK_SMALL(); eina_lock_take(&_mutex_small);
_eina_stringshare_small_del(str, slen); _eina_stringshare_small_del(str, slen);
STRINGSHARE_UNLOCK_SMALL(); eina_lock_release(&_mutex_small);
return; return;
} }
@ -601,9 +582,9 @@ eina_stringshare_add_length(const char *str, unsigned int slen)
{ {
const char *s; const char *s;
STRINGSHARE_LOCK_SMALL(); eina_lock_take(&_mutex_small);
s = _eina_stringshare_small_add(str, slen); s = _eina_stringshare_small_add(str, slen);
STRINGSHARE_UNLOCK_SMALL(); eina_lock_release(&_mutex_small);
return s; return s;
} }
@ -734,9 +715,9 @@ eina_stringshare_ref(const char *str)
const char *s; const char *s;
eina_share_common_population_add(stringshare_share, slen); eina_share_common_population_add(stringshare_share, slen);
STRINGSHARE_LOCK_SMALL(); eina_lock_take(&_mutex_small);
s = _eina_stringshare_small_add(str, slen); s = _eina_stringshare_small_add(str, slen);
STRINGSHARE_UNLOCK_SMALL(); eina_lock_release(&_mutex_small);
return s; return s;
} }

View File

@ -241,7 +241,7 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
Chained_Pool *p = NULL; Chained_Pool *p = NULL;
void *mem; void *mem;
if (!eina_lock_take(pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EFL_DEBUG_THREADS #ifdef EFL_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(pthread_equal(pool->self, pthread_self()));
@ -267,7 +267,7 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
p = _eina_chained_mp_pool_new(pool); p = _eina_chained_mp_pool_new(pool);
if (!p) if (!p)
{ {
eina_lock_release(pool->mutex); eina_lock_release(&pool->mutex);
return NULL; return NULL;
} }
@ -278,7 +278,7 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
mem = _eina_chained_mempool_alloc_in(pool, p); mem = _eina_chained_mempool_alloc_in(pool, p);
eina_lock_release(pool->mutex); eina_lock_release(&pool->mutex);
return mem; return mem;
} }
@ -291,7 +291,7 @@ eina_chained_mempool_free(void *data, void *ptr)
Chained_Pool *p; Chained_Pool *p;
// look 4 pool // look 4 pool
if (!eina_lock_take(pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EFL_DEBUG_THREADS #ifdef EFL_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(pthread_equal(pool->self, pthread_self()));
@ -322,7 +322,7 @@ eina_chained_mempool_free(void *data, void *ptr)
} }
#endif #endif
eina_lock_release(pool->mutex); eina_lock_release(&pool->mutex);
return; return;
} }
@ -336,7 +336,7 @@ eina_chained_mempool_repack(void *data,
Chained_Pool *tail; Chained_Pool *tail;
/* FIXME: Improvement - per Chained_Pool lock */ /* FIXME: Improvement - per Chained_Pool lock */
if (!eina_lock_take(pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EFL_DEBUG_THREADS #ifdef EFL_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(pthread_equal(pool->self, pthread_self()));
@ -409,7 +409,7 @@ eina_chained_mempool_repack(void *data,
} }
/* FIXME: improvement - reorder pool so that the most used one get in front */ /* FIXME: improvement - reorder pool so that the most used one get in front */
eina_lock_release(pool->mutex); eina_lock_release(&pool->mutex);
} }
static void * static void *
@ -494,7 +494,7 @@ eina_chained_mempool_shutdown(void *data)
VALGRIND_DESTROY_MEMPOOL(mp); VALGRIND_DESTROY_MEMPOOL(mp);
#endif #endif
eina_lock_free(mp->mutex); eina_lock_free(&mp->mutex);
#ifdef EFL_DEBUG_THREADS #ifdef EFL_DEBUG_THREADS
assert(pthread_equal(mp->self, pthread_self())); assert(pthread_equal(mp->self, pthread_self()));

View File

@ -39,6 +39,7 @@
#include "eina_trash.h" #include "eina_trash.h"
#include "eina_inlist.h" #include "eina_inlist.h"
#include "eina_log.h" #include "eina_log.h"
#include "eina_lock.h"
#ifndef NVALGRIND #ifndef NVALGRIND
# include <valgrind/memcheck.h> # include <valgrind/memcheck.h>
@ -75,16 +76,10 @@ struct _One_Big
Eina_Trash *empty; Eina_Trash *empty;
Eina_Inlist *over_list; Eina_Inlist *over_list;
#ifdef EFL_HAVE_THREADS #ifdef EFL_DEBUG_THREADS
# ifdef EFL_HAVE_POSIX_THREADS
# ifdef EFL_DEBUG_THREADS
pthread_t self; pthread_t self;
# endif
pthread_mutex_t mutex;
# else
HANDLE mutex;
# endif
#endif #endif
Eina_Lock mutex;
}; };
static void * static void *
@ -93,22 +88,12 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size)
One_Big *pool = data; One_Big *pool = data;
unsigned char *mem = NULL; unsigned char *mem = NULL;
#ifdef EFL_HAVE_THREADS if (!eina_lock_take(&pool->mutex))
if (_threads_activated)
{ {
# ifdef EFL_HAVE_POSIX_THREADS #ifdef EFL_DEBUG_THREADS
pthread_mutex_lock(&pool->mutex); assert(pthread_equal(pool->self, pthread_self()));
# else
WaitForSingleObject(pool->mutex, INFINITE);
# endif
}
# ifdef EFL_HAVE_POSIX_THREADS
# ifdef EFL_DEBUG_THREADS
else
assert(pthread_equal(pool->self, pthread_self()));
# endif
# endif
#endif #endif
}
if (pool->empty) if (pool->empty)
{ {
@ -158,16 +143,7 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size)
#endif #endif
on_exit: on_exit:
#ifdef EFL_HAVE_THREADS eina_lock_release(&pool->mutex);
if (_threads_activated)
{
# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
# else
ReleaseMutex(pool->mutex);
# endif
}
#endif
#ifndef NVALGRIND #ifndef NVALGRIND
VALGRIND_MEMPOOL_ALLOC(pool, mem, pool->item_size); VALGRIND_MEMPOOL_ALLOC(pool, mem, pool->item_size);
@ -180,22 +156,12 @@ eina_one_big_free(void *data, void *ptr)
{ {
One_Big *pool = data; One_Big *pool = data;
#ifdef EFL_HAVE_THREADS if (!eina_lock_take(&pool->mutex))
if (_threads_activated)
{ {
# ifdef EFL_HAVE_POSIX_THREADS #ifdef EFL_DEBUG_THREADS
pthread_mutex_lock(&pool->mutex); assert(pthread_equal(pool->self, pthread_self()));
# else
WaitForSingleObject(pool->mutex, INFINITE);
# endif
}
# ifdef EFL_HAVE_POSIX_THREADS
# ifdef EFL_DEBUG_THREADS
else
assert(pthread_equal(pool->self, pthread_self()));
# endif
# endif
#endif #endif
}
if ((void *)pool->base <= ptr if ((void *)pool->base <= ptr
&& ptr < (void *)(pool->base + (pool->max * pool->item_size))) && ptr < (void *)(pool->base + (pool->max * pool->item_size)))
@ -228,16 +194,7 @@ eina_one_big_free(void *data, void *ptr)
VALGRIND_MEMPOOL_FREE(pool, ptr); VALGRIND_MEMPOOL_FREE(pool, ptr);
#endif #endif
#ifdef EFL_HAVE_THREADS eina_lock_release(&pool->mutex);
if (_threads_activated)
{
# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
# else
ReleaseMutex(pool->mutex);
# endif
}
#endif
} }
static void * static void *
@ -274,16 +231,10 @@ eina_one_big_init(const char *context,
memcpy((char *)pool->name, context, length); memcpy((char *)pool->name, context, length);
} }
#ifdef EFL_HAVE_THREADS #ifdef EFL_DEBUG_THREADS
# ifdef EFL_HAVE_POSIX_THREADS
# ifdef EFL_DEBUG_THREADS
pool->self = pthread_self(); pool->self = pthread_self();
# endif
pthread_mutex_init(&pool->mutex, NULL);
# else
pool->mutex = CreateMutex(NULL, FALSE, NULL);
# endif
#endif #endif
eina_lock_new(&pool->mutex);
#ifndef NVALGRIND #ifndef NVALGRIND
VALGRIND_CREATE_MEMPOOL(pool, 0, 1); VALGRIND_CREATE_MEMPOOL(pool, 0, 1);
@ -298,22 +249,12 @@ eina_one_big_shutdown(void *data)
One_Big *pool = data; One_Big *pool = data;
if (!pool) return; if (!pool) return;
#ifdef EFL_HAVE_THREADS if (!eina_lock_take(&pool->mutex))
if (_threads_activated)
{ {
# ifdef EFL_HAVE_POSIX_THREADS #ifdef EFL_DEBUG_THREADS
pthread_mutex_lock(&pool->mutex); assert(pthread_equal(pool->self, pthread_self()));
# else
WaitForSingleObject(pool->mutex, INFINITE);
# endif
}
# ifdef EFL_HAVE_POSIX_THREADS
# ifdef EFL_DEBUG_THREADS
else
assert(pthread_equal(pool->self, pthread_self()));
# endif
# endif
#endif #endif
}
if (pool->over > 0) if (pool->over > 0)
{ {
@ -344,18 +285,8 @@ eina_one_big_shutdown(void *data)
if (pool->base) free(pool->base); if (pool->base) free(pool->base);
#ifdef EFL_HAVE_THREADS eina_lock_release(&pool->mutex);
if (_threads_activated) eina_lock_free(&pool->mutex);
{
# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
pthread_mutex_destroy(&pool->mutex);
# else
ReleaseMutex(pool->mutex);
CloseHandle(pool->mutex);
# endif
}
#endif
free(pool); free(pool);
} }