sf_synchronize_counter_xxx use mutex lock all
parent
f4bfe9ad25
commit
97b64c67fb
|
|
@ -76,18 +76,37 @@ static inline int sf_synchronize_ctx_init(SFSynchronizeContext *sctx)
|
|||
return init_pthread_lock_cond_pair(&sctx->lcp);
|
||||
}
|
||||
|
||||
static inline void sf_synchronize_counter_notify(SFSynchronizeContext *sctx,
|
||||
const int count)
|
||||
static inline void sf_synchronize_counter_add(
|
||||
SFSynchronizeContext *sctx, const int count)
|
||||
{
|
||||
if (__sync_sub_and_fetch(&sctx->waiting_count, count) == 0) {
|
||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||
sctx->waiting_count += count;
|
||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||
}
|
||||
|
||||
static inline void sf_synchronize_counter_sub(
|
||||
SFSynchronizeContext *sctx, const int count)
|
||||
{
|
||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||
sctx->waiting_count -= count;
|
||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||
}
|
||||
|
||||
static inline void sf_synchronize_counter_notify(
|
||||
SFSynchronizeContext *sctx, const int count)
|
||||
{
|
||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||
sctx->waiting_count -= count;
|
||||
if (sctx->waiting_count == 0) {
|
||||
pthread_cond_signal(&sctx->lcp.cond);
|
||||
}
|
||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||
}
|
||||
|
||||
static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
|
||||
{
|
||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||
while (FC_ATOMIC_GET(sctx->waiting_count) != 0) {
|
||||
while (sctx->waiting_count != 0) {
|
||||
pthread_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
|
||||
}
|
||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ typedef struct sf_synchronize_context {
|
|||
union {
|
||||
bool finished;
|
||||
int result;
|
||||
volatile int waiting_count;
|
||||
int waiting_count;
|
||||
};
|
||||
} SFSynchronizeContext;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue