forked from enlightenment/efl
eina: make sure eina_threads_init/eina_threads_shutdown are correctly called.
SVN revision: 59117
This commit is contained in:
parent
397acdd837
commit
a345a670b2
|
@ -111,6 +111,8 @@ EAPI int eina_shutdown(void);
|
||||||
*
|
*
|
||||||
* When the mutexes are not used anymore, call eina_threads_shutdown() to shut down
|
* When the mutexes are not used anymore, call eina_threads_shutdown() to shut down
|
||||||
* the mutexes.
|
* the mutexes.
|
||||||
|
*
|
||||||
|
* This function should never be called outside of the main loop.
|
||||||
*/
|
*/
|
||||||
EAPI int eina_threads_init(void);
|
EAPI int eina_threads_init(void);
|
||||||
|
|
||||||
|
@ -127,6 +129,8 @@ EAPI int eina_threads_init(void);
|
||||||
* Once this function succeeds (that is, @c 0 is returned), you must
|
* Once this function succeeds (that is, @c 0 is returned), you must
|
||||||
* not call any of the Eina function in a thread anymore. You must call
|
* not call any of the Eina function in a thread anymore. You must call
|
||||||
* eina_threads_init() again to use the Eina functions in a thread again.
|
* eina_threads_init() again to use the Eina functions in a thread again.
|
||||||
|
*
|
||||||
|
* This function should never be called outside of the main loop.
|
||||||
*/
|
*/
|
||||||
EAPI int eina_threads_shutdown(void);
|
EAPI int eina_threads_shutdown(void);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
# undef WIN32_LEAN_AND_MEAN
|
# undef WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "eina_lock.h"
|
||||||
#include "eina_config.h"
|
#include "eina_config.h"
|
||||||
#include "eina_private.h"
|
#include "eina_private.h"
|
||||||
#include "eina_types.h"
|
#include "eina_types.h"
|
||||||
|
@ -46,7 +47,6 @@
|
||||||
#include "eina_magic.h"
|
#include "eina_magic.h"
|
||||||
#include "eina_rectangle.h"
|
#include "eina_rectangle.h"
|
||||||
#include "eina_safety_checks.h"
|
#include "eina_safety_checks.h"
|
||||||
#include "eina_lock.h"
|
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Local *
|
* Local *
|
||||||
|
@ -78,6 +78,7 @@ EAPI Eina_Bool _eina_threads_activated = EINA_FALSE;
|
||||||
|
|
||||||
#ifdef EINA_HAVE_DEBUG_THREADS
|
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||||
EAPI int _eina_threads_debug = 0;
|
EAPI int _eina_threads_debug = 0;
|
||||||
|
EAPI pthread_t _eina_main_loop = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Eina_Lock _mutex;
|
static Eina_Lock _mutex;
|
||||||
|
@ -216,8 +217,11 @@ eina_init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
eina_lock_new(&_mutex);
|
eina_lock_new(&_mutex);
|
||||||
#ifdef EINA_HAVE_DEBUG_THREADS
|
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||||
|
_eina_main_loop = pthread_self();
|
||||||
|
|
||||||
if (getenv("EINA_DEBUG_THREADS"))
|
if (getenv("EINA_DEBUG_THREADS"))
|
||||||
_eina_threads_debug = atoi(getenv("EINA_DEBUG_THREADS");
|
_eina_threads_debug = atoi(getenv("EINA_DEBUG_THREADS");
|
||||||
#endif
|
#endif
|
||||||
|
@ -247,6 +251,9 @@ eina_threads_init(void)
|
||||||
#ifdef EFL_HAVE_THREADS
|
#ifdef EFL_HAVE_THREADS
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||||
|
assert(pthread_equal(_eina_main_loop, pthread_self()));
|
||||||
|
#endif
|
||||||
|
|
||||||
eina_lock_take(&_mutex);
|
eina_lock_take(&_mutex);
|
||||||
++_eina_main_thread_count;
|
++_eina_main_thread_count;
|
||||||
|
@ -276,6 +283,11 @@ eina_threads_shutdown(void)
|
||||||
#ifdef EFL_HAVE_THREADS
|
#ifdef EFL_HAVE_THREADS
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||||
|
assert(pthread_equal(_eina_main_loop, pthread_self()));
|
||||||
|
assert(_eina_main_thread_count > 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue