From 90f5fe9927607477897a094bcdbfe9078e615d06 Mon Sep 17 00:00:00 2001 From: mike_m Date: Fri, 12 Aug 2011 05:21:49 +0000 Subject: [PATCH] ecore: Use eina locks for _ecore_lock() Always count lock calls too. Signed-off-by: Mike McCormack git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@62372 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/ecore/ecore.c | 3 +++ src/lib/ecore/ecore_private.h | 21 ++++++++++++++++----- src/lib/ecore/ecore_thread.c | 22 ---------------------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c index 9b14b55..7af5d4d 100644 --- a/src/lib/ecore/ecore.c +++ b/src/lib/ecore/ecore.c @@ -64,6 +64,8 @@ static void _thread_callback(void *data, void *buffer, unsigned int nbyte); static Eina_List *_thread_cb = NULL; static Ecore_Pipe *_thread_call = NULL; static Eina_Lock _thread_safety; +Eina_Lock _ecore_main_loop_lock; +int _ecore_main_lock_count; /** OpenBSD does not define CODESET * FIXME ?? @@ -139,6 +141,7 @@ ecore_init(void) _ecore_time_init(); eina_lock_new(&_thread_safety); + eina_lock_new(&_ecore_main_loop_lock); _thread_call = ecore_pipe_add(_thread_callback, NULL); #if HAVE_MALLINFO diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h index 10a4f49..2982de3 100644 --- a/src/lib/ecore/ecore_private.h +++ b/src/lib/ecore/ecore_private.h @@ -1,6 +1,8 @@ #ifndef _ECORE_PRIVATE_H #define _ECORE_PRIVATE_H +#include + extern int _ecore_log_dom ; #ifdef _ECORE_DEFAULT_LOG_DOM # undef _ECORE_DEFAULT_LOG_DOM @@ -199,22 +201,31 @@ void _ecore_main_loop_shutdown(void); void _ecore_throttle(void); -#ifdef HAVE_THREAD_SAFETY -void _ecore_lock(void); -void _ecore_unlock(void); -#else +extern int _ecore_main_lock_count; +extern Eina_Lock _ecore_main_loop_lock; + static inline void _ecore_lock(void) { +#ifdef HAVE_THREAD_SAFETY + eina_lock_take(&_ecore_main_loop_lock); +#else /* at least check we're not being called from a thread */ EINA_MAIN_LOOP_CHECK_RETURN; +#endif + _ecore_main_lock_count++; + assert(_ecore_main_lock_count == 1); } static inline void _ecore_unlock(void) { -} + _ecore_main_lock_count--; + assert(_ecore_main_lock_count == 0); +#ifdef HAVE_THREAD_SAFETY + eina_lock_release(&_ecore_main_loop_lock); #endif +} /* * Callback wrappers all assume that ecore _ecore_lock has been called diff --git a/src/lib/ecore/ecore_thread.c b/src/lib/ecore/ecore_thread.c index 625b448..987294b 100644 --- a/src/lib/ecore/ecore_thread.c +++ b/src/lib/ecore/ecore_thread.c @@ -390,7 +390,6 @@ static LRWK(_ecore_thread_global_hash_lock); static LK(_ecore_thread_global_hash_mutex); static CD(_ecore_thread_global_hash_cond); -static LK(_ecore_main_loop_mutex); static Eina_Bool have_main_loop_thread = 0; static Eina_Trash *_ecore_thread_worker_trash = NULL; @@ -794,7 +793,6 @@ _ecore_thread_init(void) LKI(_ecore_pending_job_threads_mutex); LRWKI(_ecore_thread_global_hash_lock); LKI(_ecore_thread_global_hash_mutex); - LKI(_ecore_main_loop_mutex); CDI(_ecore_thread_global_hash_cond); #endif } @@ -874,26 +872,6 @@ _ecore_thread_assert_main_loop_thread(const char *function) } } -#ifdef HAVE_THREAD_SAFETY -static int lock_count; - -void -_ecore_lock(void) -{ - LKL(_ecore_main_loop_mutex); - lock_count++; - assert(lock_count == 1); -} - -void -_ecore_unlock(void) -{ - lock_count--; - assert(lock_count == 0); - LKU(_ecore_main_loop_mutex); -} -#endif - EAPI Ecore_Thread * ecore_thread_run(Ecore_Thread_Cb func_blocking, Ecore_Thread_Cb func_end, -- 2.7.4