eina: add generic macro to generate error when outside of the main loop.

SVN revision: 62240
This commit is contained in:
Cedric BAIL 2011-08-09 08:48:57 +00:00
parent 9838bda52f
commit fb56b5f5e3
2 changed files with 41 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "eina_config.h"
#include "eina_types.h"
#include "eina_error.h"
/**
* @addtogroup Eina_Tools_Group Tools
@ -53,6 +54,8 @@ typedef enum
# include "eina_inline_lock_void.x"
#endif
EAPI extern Eina_Error EINA_ERROR_NOT_MAIN_LOOP;
static inline Eina_Bool eina_lock_new(Eina_Lock *mutex);
static inline void eina_lock_free(Eina_Lock *mutex);
static inline Eina_Lock_Result eina_lock_take(Eina_Lock *mutex);
@ -73,6 +76,38 @@ static inline Eina_Lock_Result eina_rwlock_take_read(Eina_RWLock *mutex);
static inline Eina_Lock_Result eina_rwlock_take_write(Eina_RWLock *mutex);
static inline Eina_Lock_Result eina_rwlock_release(Eina_RWLock *mutex);
#ifdef EINA_HAVE_DEBUG_THREADS
# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val) \
do { \
if (EINA_UNLIKELY(eina_main_loop_is())) \
{ \
eina_error_set(EINA_ERROR_NOT_MAIN_LOOP); \
EINA_LOG_ERR("You are calling %s from outside" \
"of the main loop threads in %s at line %i", \
__FUNCTION__, \
__FILE__, \
__LINE__); \
return val; \
} \
} while (0)
# define EINA_MAIN_LOOP_CHECK_RETURN \
do { \
if (EINA_UNLIKELY(eina_main_loop_is())) \
{ \
eina_error_set(EINA_ERROR_NOT_MAIN_LOOP); \
EINA_LOG_ERR("You are calling %s from outside" \
"of the main loop threads in %s at line %i", \
__FUNCTION__, \
__FILE__, \
__LINE__); \
return ; \
} \
} while (0)
#else
# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val)
# define EINA_MAIN_LOOP_CHECK_RETURN
#endif
/**
* @}
*/

View File

@ -82,6 +82,9 @@ static int _eina_log_dom = -1;
#define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__)
EAPI Eina_Bool _eina_threads_activated = EINA_FALSE;
EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0;
static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed.";
#ifdef EFL_HAVE_THREADS
# ifdef _WIN32_WCE
@ -222,6 +225,9 @@ eina_init(void)
return 0;
}
EINA_ERROR_NOT_MAIN_LOOP = eina_error_msg_static_register(
EINA_ERROR_NOT_MAIN_LOOP_STR);
#ifdef EFL_HAVE_THREADS
# ifdef _WIN32_CE
_eina_main_loop = (HANDLE) GetCurrentThreadId();