* eina_log: Fallback to mutex when spinlock doesn't exist.

SVN revision: 42489
This commit is contained in:
Cedric BAIL 2009-09-14 16:06:18 +00:00
parent d117093a55
commit 8e6a393cf9
2 changed files with 33 additions and 13 deletions

View File

@ -49,6 +49,12 @@ EFL_CHECK_CPU_ALTIVEC([have_altivec="yes"], [have_altivec="no"])
EFL_CHECK_PTHREAD([have_pthread="yes"], [have_pthread="no"]) EFL_CHECK_PTHREAD([have_pthread="yes"], [have_pthread="no"])
if test "x${have_pthread}" = "xyes"; then
AC_CHECK_LIB(pthread, pthread_spin_init,
[
AC_DEFINE(EINA_PTHREAD_SPIN, 1, [Build eina_log lock using pthread_spin])
])
fi
### Additional options to configure ### Additional options to configure

View File

@ -337,6 +337,20 @@ static Eina_Bool _abort_on_critical = EINA_FALSE;
#include <pthread.h> #include <pthread.h>
static Eina_Bool _threads_enabled = EINA_FALSE; static Eina_Bool _threads_enabled = EINA_FALSE;
static pthread_t _main_thread; static pthread_t _main_thread;
#define IS_MAIN(t) pthread_equal(t, _main_thread)
#define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
#define CHECK_MAIN(...) \
do { \
if (!IS_MAIN(pthread_self())) { \
fprintf(stderr, \
"ERR: not main thread! current=%lu, main=%lu\n", \
pthread_self(), _main_thread); \
return __VA_ARGS__; \
} \
} while (0)
#ifdef EINA_PTHREAD_SPIN
static pthread_spinlock_t _log_lock; static pthread_spinlock_t _log_lock;
#define LOCK() \ #define LOCK() \
do { \ do { \
@ -355,23 +369,23 @@ static pthread_spinlock_t _log_lock;
"---LOG UNLOCKED! [%s, %lu]\n", \ "---LOG UNLOCKED! [%s, %lu]\n", \
__FUNCTION__, pthread_self()); \ __FUNCTION__, pthread_self()); \
} while (0) } while (0)
#define IS_MAIN(t) pthread_equal(t, _main_thread) #define INIT() pthread_spin_init(&_log_lock, PTHREAD_PROCESS_PRIVATE);
#define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t)) #define SHUTDOWN() pthread_spin_destroy(&_log_lock);
#define CHECK_MAIN(...) \ #else
do { \ static pthread_mutex_t _log_mutex = PTHREAD_MUTEX_INITIALIZER;
if (!IS_MAIN(pthread_self())) { \ #define LOCK() pthread_mutex_lock(&_log_mutex);
fprintf(stderr, \ #define UNLOCK() pthread_mutex_unlock(&_log_mutex);
"ERR: not main thread! current=%lu, main=%lu\n", \ #define INIT() do {} while (0)
pthread_self(), _main_thread); \ #define SHUTDOWN() do {} while (0)
return __VA_ARGS__; \ #endif
} \
} while (0)
#else #else
#define LOCK() do {} while (0) #define LOCK() do {} while (0)
#define UNLOCK() do {} while (0) #define UNLOCK() do {} while (0)
#define IS_MAIN(t) (1) #define IS_MAIN(t) (1)
#define IS_OTHER(t) (0) #define IS_OTHER(t) (0)
#define CHECK_MAIN(...) do {} while (0) #define CHECK_MAIN(...) do {} while (0)
#define INIT() do {} while (0)
#define SHUTDOWN() do {} while (0)
#endif #endif
@ -892,7 +906,7 @@ eina_log_init(void)
#ifdef EFL_HAVE_PTHREAD #ifdef EFL_HAVE_PTHREAD
_main_thread = pthread_self(); _main_thread = pthread_self();
pthread_spin_init(&_log_lock, PTHREAD_PROCESS_PRIVATE); INIT();
#endif #endif
// Check if color is disabled // Check if color is disabled
@ -972,7 +986,7 @@ eina_log_shutdown(void)
} }
#ifdef EFL_HAVE_PTHREAD #ifdef EFL_HAVE_PTHREAD
pthread_spin_destroy(&_log_lock); SHUTDOWN();
_threads_enabled = 0; _threads_enabled = 0;
#endif #endif