raster pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=07924f26f123b952a5e5e71fb953fe8a7f1a449a
commit 07924f26f123b952a5e5e71fb953fe8a7f1a449a Author: Carsten Haitzler (Rasterman) <[email protected]> Date: Fri Aug 5 17:08:25 2016 +0900 eina thread queue - check returns fo semaphore new/lock/release to debug so openbsd may have issues with semaphores - maybe. this would catch them if it it. why - if sem_init/sem_wait are different... i dont know. --- src/lib/eina/eina_thread_queue.c | 47 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/lib/eina/eina_thread_queue.c b/src/lib/eina/eina_thread_queue.c index 43db73d..6bf0c53 100644 --- a/src/lib/eina/eina_thread_queue.c +++ b/src/lib/eina/eina_thread_queue.c @@ -6,6 +6,9 @@ #include "Eina.h" #include "eina_thread_queue.h" #include "eina_safety_checks.h" +#include "eina_log.h" + +#include "eina_private.h" #ifdef __ATOMIC_RELAXED #define ATOMIC 1 @@ -69,10 +72,21 @@ struct _Eina_Thread_Queue_Msg_Block // a pool of spare message blocks that are only of the minimum size so we // avoid reallocation via malloc/free etc. to avoid free memory pages and // pressure on the malloc subsystem +static int _eina_thread_queue_log_dom = -1; static int _eina_thread_queue_block_pool_count = 0; static Eina_Spinlock _eina_thread_queue_block_pool_lock; static Eina_Thread_Queue_Msg_Block *_eina_thread_queue_block_pool = NULL; +#ifdef ERR +# undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(_eina_thread_queue_log_dom, __VA_ARGS__) + +#ifdef DBG +# undef DBG +#endif +#define DBG(...) EINA_LOG_DOM_DBG(_eina_thread_queue_log_dom, __VA_ARGS__) + // api's to get message blocks from the pool or put them back in static Eina_Thread_Queue_Msg_Block * _eina_thread_queue_msg_block_new(int size) @@ -148,10 +162,10 @@ _eina_thread_queue_msg_block_free(Eina_Thread_Queue_Msg_Block *blk) else _eina_thread_queue_msg_block_real_free(blk); } -static void +static Eina_Bool _eina_thread_queue_msg_block_pool_init(void) { - eina_spinlock_new(&_eina_thread_queue_block_pool_lock); + return eina_spinlock_new(&_eina_thread_queue_block_pool_lock); } static void @@ -179,13 +193,15 @@ _eina_thread_queue_msg_block_pool_shutdown(void) static void _eina_thread_queue_wait(Eina_Thread_Queue *thq) { - eina_semaphore_lock(&(thq->sem)); + if (!eina_semaphore_lock(&(thq->sem))) + ERR("Thread queue semaphore lock/wait failed - bad things will happen"); } static void _eina_thread_queue_wake(Eina_Thread_Queue *thq) { - eina_semaphore_release(&(thq->sem), 1); + if (!eina_semaphore_release(&(thq->sem), 1)) + ERR("Thread queue semaphore release/wakeup faile - bad things will happen"); } // how to allocate or release memory within one of the message blocks for @@ -335,7 +351,18 @@ _eina_thread_queue_msg_fetch_done(Eina_Thread_Queue_Msg_Block *blk) Eina_Bool eina_thread_queue_init(void) { - _eina_thread_queue_msg_block_pool_init(); + _eina_thread_queue_log_dom = eina_log_domain_register("eina_thread_queue", + EINA_LOG_COLOR_DEFAULT); + if (_eina_thread_queue_log_dom < 0) + { + EINA_LOG_ERR("Could not register log domain: eina_thread_queue"); + return EINA_FALSE; + } + if (!_eina_thread_queue_msg_block_pool_init()) + { + ERR("Cannot init thread queue block pool spinlock"); + return EINA_FALSE; + } return EINA_TRUE; } @@ -343,6 +370,7 @@ Eina_Bool eina_thread_queue_shutdown(void) { _eina_thread_queue_msg_block_pool_shutdown(); + eina_log_domain_unregister(_eina_thread_queue_log_dom); return EINA_TRUE; } @@ -354,7 +382,12 @@ eina_thread_queue_new(void) thq = calloc(1, sizeof(Eina_Thread_Queue)); if (!thq) return NULL; thq->fd = -1; - eina_semaphore_new(&(thq->sem), 0); + if (!eina_semaphore_new(&(thq->sem), 0)) + { + ERR("Cannot init new semaphore for eina_threadqueue"); + free(thq); + return NULL; + } RWLOCK_NEW(&(thq->lock_read)); RWLOCK_NEW(&(thq->lock_write)); #ifndef ATOMIC @@ -419,7 +452,7 @@ eina_thread_queue_send_done(Eina_Thread_Queue *thq, void *allocref) { char dummy = 0; if (write(thq->fd, &dummy, 1) != 1) - fprintf(stderr, "Eina Threadqueue write to fd %i failed\n", thq->fd); + ERR("Eina Threadqueue write to fd %i failed", thq->fd); } } --
