eina_threadqueue: simplify/unify some locking code
Summary: this moves lock calls outside #ifdef blocks to make the code more readable no functional changes Depends on D6298 Reviewers: ManMower, devilhorns Reviewed By: ManMower Subscribers: cedric, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D6299
This commit is contained in:
parent
df2f614431
commit
a446fb86fc
|
@ -220,6 +220,7 @@ _eina_thread_queue_msg_alloc(Eina_Thread_Queue *thq, int size, Eina_Thread_Queue
|
||||||
{
|
{
|
||||||
Eina_Thread_Queue_Msg_Block *blk;
|
Eina_Thread_Queue_Msg_Block *blk;
|
||||||
Eina_Thread_Queue_Msg *msg = NULL;
|
Eina_Thread_Queue_Msg *msg = NULL;
|
||||||
|
int ref;
|
||||||
|
|
||||||
// round up to nearest 8
|
// round up to nearest 8
|
||||||
size = ((size + 7) >> 3) << 3;
|
size = ((size + 7) >> 3) << 3;
|
||||||
|
@ -261,16 +262,14 @@ _eina_thread_queue_msg_alloc(Eina_Thread_Queue *thq, int size, Eina_Thread_Queue
|
||||||
}
|
}
|
||||||
msg->size = size;
|
msg->size = size;
|
||||||
#ifdef ATOMIC
|
#ifdef ATOMIC
|
||||||
{
|
ref = __atomic_add_fetch(&(blk->ref), 1, __ATOMIC_RELAXED);
|
||||||
int ref = __atomic_add_fetch(&(blk->ref), 1, __ATOMIC_RELAXED);
|
|
||||||
if (ref == 1) eina_lock_take(&(blk->lock_non_0_ref));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
eina_spinlock_take(&(blk->lock_ref));
|
eina_spinlock_take(&(blk->lock_ref));
|
||||||
blk->ref++;
|
blk->ref++;
|
||||||
if (blk->ref == 1) eina_lock_take(&(blk->lock_non_0_ref));
|
ref = blk->ref;
|
||||||
eina_spinlock_release(&(blk->lock_ref));
|
eina_spinlock_release(&(blk->lock_ref));
|
||||||
#endif
|
#endif
|
||||||
|
if (ref == 1) eina_lock_take(&(blk->lock_non_0_ref));
|
||||||
*blkret = blk;
|
*blkret = blk;
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -278,17 +277,16 @@ _eina_thread_queue_msg_alloc(Eina_Thread_Queue *thq, int size, Eina_Thread_Queue
|
||||||
static void
|
static void
|
||||||
_eina_thread_queue_msg_alloc_done(Eina_Thread_Queue_Msg_Block *blk)
|
_eina_thread_queue_msg_alloc_done(Eina_Thread_Queue_Msg_Block *blk)
|
||||||
{
|
{
|
||||||
|
int ref;
|
||||||
#ifdef ATOMIC
|
#ifdef ATOMIC
|
||||||
{
|
ref = __atomic_sub_fetch(&(blk->ref), 1, __ATOMIC_RELAXED);
|
||||||
int ref = __atomic_sub_fetch(&(blk->ref), 1, __ATOMIC_RELAXED);
|
|
||||||
if (ref == 0) eina_lock_release(&(blk->lock_non_0_ref));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
eina_spinlock_take(&(blk->lock_ref));
|
eina_spinlock_take(&(blk->lock_ref));
|
||||||
blk->ref--;
|
blk->ref--;
|
||||||
if (blk->ref == 0) eina_lock_release(&(blk->lock_non_0_ref));
|
ref = blk->ref;
|
||||||
eina_spinlock_release(&(blk->lock_ref));
|
eina_spinlock_release(&(blk->lock_ref));
|
||||||
#endif
|
#endif
|
||||||
|
if (ref == 0) eina_lock_release(&(blk->lock_non_0_ref));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Thread_Queue_Msg *
|
static Eina_Thread_Queue_Msg *
|
||||||
|
|
Loading…
Reference in New Issue