On Sun, 24 Apr 2011, Enlightenment SVN wrote:
> Modified: trunk/eina/src/lib/eina_main.c > =================================================================== > --- trunk/eina/src/lib/eina_main.c 2011-04-24 15:44:18 UTC (rev 58868) > +++ trunk/eina/src/lib/eina_main.c 2011-04-24 15:54:09 UTC (rev 58869) > @@ -22,10 +22,6 @@ > > #include <stdio.h> > > -#ifdef EFL_HAVE_POSIX_THREADS > -# include <pthread.h> > -#endif > - > #ifdef EFL_HAVE_WIN32_THREADS > # define WIN32_LEAN_AND_MEAN > # include <windows.h> > @@ -50,6 +46,7 @@ > #include "eina_magic.h" > #include "eina_rectangle.h" > #include "eina_safety_checks.h" > +#include "eina_lock.h" > > /*============================================================================* > * Local * > @@ -77,25 +74,9 @@ > #endif > #define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__) > > -Eina_Bool _threads_activated = EINA_FALSE; > +EAPI Eina_Bool _threads_activated = EINA_FALSE; > > -#ifdef EFL_HAVE_THREADS > -# ifdef EFL_HAVE_POSIX_THREADS > -static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER; > -# define LOCK() if(_threads_activated) pthread_mutex_lock(&_mutex) > -# define UNLOCK() if(_threads_activated) pthread_mutex_unlock(&_mutex) > -# define UNLOCK_FORCE() pthread_mutex_unlock(&_mutex) > -# else /* EFL_HAVE_WIN32_THREADS */ > -static HANDLE _mutex = NULL; > -# define LOCK() if(_threads_activated) WaitForSingleObject(_mutex, INFINITE) > -# define UNLOCK() if(_threads_activated) ReleaseMutex(_mutex) > -# define UNLOCK_FORCE() ReleaseMutex(_mutex) > -# endif > -#else > -# define LOCK() do {} while (0) > -# define UNLOCK() do {} while (0) > -# define UNLOCK_FORCE() do {} while (0) > -#endif > +static Eina_Lock _mutex; > > /* place module init/shutdown functions here to avoid other modules > * calling them by mistake. > @@ -231,6 +212,8 @@ > } > } > > + eina_lock_new(&_mutex); you don't check the returned value ? Vincent > + > _eina_main_count = 1; > return 1; > } > @@ -240,8 +223,12 @@ > { > _eina_main_count--; > if (EINA_UNLIKELY(_eina_main_count == 0)) > - _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); > + } > + > return _eina_main_count; > } > > @@ -252,22 +239,14 @@ > #ifdef EFL_HAVE_THREADS > int ret; > > -# ifdef EFL_HAVE_WIN32_THREADS > - if (!_mutex) > - _mutex = CreateMutex(NULL, FALSE, NULL); > > - if (!_mutex) > - return 0; > - > -# endif > - > - LOCK(); > + eina_lock_take(_mutex); > ++_eina_main_thread_count; > ret = _eina_main_thread_count; > > if(_eina_main_thread_count > 1) > { > - UNLOCK(); > + eina_lock_release(_mutex); > return ret; > } > > @@ -275,6 +254,8 @@ > eina_log_threads_init(); > _threads_activated = EINA_TRUE; > > + eina_lock_release(_mutex); > + > return ret; > #else > return 0; > @@ -287,27 +268,21 @@ > #ifdef EFL_HAVE_THREADS > int ret; > > - LOCK(); > + eina_lock_take(_mutex); > ret = --_eina_main_thread_count; > if(_eina_main_thread_count > 0) > { > - UNLOCK(); > + eina_lock_release(_mutex); > return ret; > } > > eina_share_common_threads_shutdown(); > eina_log_threads_shutdown(); > > + eina_lock_release(_mutex); > + > _threads_activated = EINA_FALSE; > > - UNLOCK_FORCE(); > - > -# ifdef EFL_HAVE_WIN32_THREADS > - if (_mutex) > - CloseHandle(_mutex); > - > -# endif > - > return ret; > #else > return 0; > > Modified: trunk/eina/src/modules/mp/chained_pool/eina_chained_mempool.c > =================================================================== > --- trunk/eina/src/modules/mp/chained_pool/eina_chained_mempool.c > 2011-04-24 15:44:18 UTC (rev 58868) > +++ trunk/eina/src/modules/mp/chained_pool/eina_chained_mempool.c > 2011-04-24 15:54:09 UTC (rev 58869) > @@ -43,6 +43,7 @@ > #include "eina_mempool.h" > #include "eina_trash.h" > #include "eina_rbtree.h" > +#include "eina_lock.h" > > #include "eina_private.h" > > @@ -73,16 +74,10 @@ > int alloc_size; > int group_size; > int usage; > -#ifdef EFL_HAVE_THREADS > -# ifdef EFL_HAVE_POSIX_THREADS > -# ifdef EFL_DEBUG_THREADS > +#ifdef EFL_DEBUG_THREADS > pthread_t self; > -# endif > - pthread_mutex_t mutex; > -# else > - HANDLE mutex; > -# endif > #endif > + Eina_Lock mutex; > }; > > typedef struct _Chained_Pool Chained_Pool; > @@ -246,20 +241,12 @@ > Chained_Pool *p = NULL; > void *mem; > > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > + if (!eina_lock_take(pool->mutex)) > { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_lock(&pool->mutex); > -# else > - WaitForSingleObject(pool->mutex, INFINITE); > -# endif > - } > #ifdef EFL_DEBUG_THREADS > - else > - assert(pthread_equal(pool->self, pthread_self())); > + assert(pthread_equal(pool->self, pthread_self())); > #endif > -#endif > + } > > // Either we have some free space in the first one, or there is no free > space. > if (pool->first) p = EINA_INLIST_CONTAINER_GET(pool->first, Chained_Pool); > @@ -280,16 +267,7 @@ > p = _eina_chained_mp_pool_new(pool); > if (!p) > { > -#ifdef EFL_HAVE_PTHREAD > - if (_threads_activated) > - { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_unlock(&pool->mutex); > -# else > - ReleaseMutex(pool->mutex); > -# endif > - } > -#endif > + eina_lock_release(pool->mutex); > return NULL; > } > > @@ -300,16 +278,7 @@ > > mem = _eina_chained_mempool_alloc_in(pool, p); > > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > - { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_unlock(&pool->mutex); > -# else > - ReleaseMutex(pool->mutex); > -# endif > - } > -#endif > + eina_lock_release(pool->mutex); > > return mem; > } > @@ -322,21 +291,12 @@ > Chained_Pool *p; > > // look 4 pool > - > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > + if (!eina_lock_take(pool->mutex)) > { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_lock(&pool->mutex); > -# else > - WaitForSingleObject(pool->mutex, INFINITE); > -# endif > - } > #ifdef EFL_DEBUG_THREADS > - else > - assert(pthread_equal(pool->self, pthread_self())); > + assert(pthread_equal(pool->self, pthread_self())); > #endif > -#endif > + } > > // searching for the right mempool > r = eina_rbtree_inline_lookup(pool->root, ptr, 0, > _eina_chained_mp_pool_key_cmp, NULL); > @@ -362,16 +322,7 @@ > } > #endif > > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > - { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_unlock(&pool->mutex); > -# else > - ReleaseMutex(pool->mutex); > -# endif > - } > -#endif > + eina_lock_release(pool->mutex); > return; > } > > @@ -385,21 +336,12 @@ > Chained_Pool *tail; > > /* FIXME: Improvement - per Chained_Pool lock */ > - > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > + if (!eina_lock_take(pool->mutex)) > { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_lock(&pool->mutex); > -# else > - WaitForSingleObject(pool->mutex, INFINITE); > -# endif > - } > #ifdef EFL_DEBUG_THREADS > - else > - assert(pthread_equal(pool->self, pthread_self())); > + assert(pthread_equal(pool->self, pthread_self())); > #endif > -#endif > + } > > pool->first = eina_inlist_sort(pool->first, > (Eina_Compare_Cb) > _eina_chained_mempool_usage_cmp); > @@ -467,17 +409,7 @@ > } > > /* FIXME: improvement - reorder pool so that the most used one get in > front */ > - > -#ifdef EFL_HAVE_THREADS > - if (_threads_activated) > - { > -# ifdef EFL_HAVE_POSIX_THREADS > - pthread_mutex_unlock(&pool->mutex); > -# else > - ReleaseMutex(pool->mutex); > -# endif > - } > -#endif > + eina_lock_release(pool->mutex); > } > > static void * > @@ -520,17 +452,12 @@ > VALGRIND_CREATE_MEMPOOL(mp, 0, 1); > #endif > > -#ifdef EFL_HAVE_THREADS > -# ifdef EFL_HAVE_POSIX_THREADS > -# ifdef EFL_DEBUG_THREADS > +#ifdef EFL_DEBUG_THREADS > mp->self = pthread_self(); > -# endif > - pthread_mutex_init(&mp->mutex, NULL); > -# else > - mp->mutex = CreateMutex(NULL, FALSE, NULL); > -# endif > #endif > > + eina_lock_new(&mp->mutex); > + > return mp; > } > > @@ -567,15 +494,10 @@ > VALGRIND_DESTROY_MEMPOOL(mp); > #endif > > -#ifdef EFL_HAVE_THREADS > -# ifdef EFL_HAVE_POSIX_THREADS > -# ifdef EFL_DEBUG_THREADS > + eina_lock_free(mp->mutex); > + > +#ifdef EFL_DEBUG_THREADS > assert(pthread_equal(mp->self, pthread_self())); > -# endif > - pthread_mutex_destroy(&mp->mutex); > -# else > - CloseHandle(mp->mutex); > -# endif > #endif > > free(mp); > > > ------------------------------------------------------------------------------ > Fulfilling the Lean Software Promise > Lean software platforms are now widely adopted and the benefits have been > demonstrated beyond question. Learn why your peers are replacing JEE > containers with lightweight application servers - and what you can gain > from the move. http://p.sf.net/sfu/vmware-sfemails > _______________________________________________ > enlightenment-svn mailing list > enlightenment-...@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/enlightenment-svn > > ------------------------------------------------------------------------------ Fulfilling the Lean Software Promise Lean software platforms are now widely adopted and the benefits have been demonstrated beyond question. Learn why your peers are replacing JEE containers with lightweight application servers - and what you can gain from the move. http://p.sf.net/sfu/vmware-sfemails _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel