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);
|
return init_pthread_lock_cond_pair(&sctx->lcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sf_synchronize_counter_notify(SFSynchronizeContext *sctx,
|
static inline void sf_synchronize_counter_add(
|
||||||
const int count)
|
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_cond_signal(&sctx->lcp.cond);
|
||||||
}
|
}
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
|
static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
|
||||||
{
|
{
|
||||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
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_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
|
||||||
}
|
}
|
||||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,7 @@ typedef struct sf_synchronize_context {
|
||||||
union {
|
union {
|
||||||
bool finished;
|
bool finished;
|
||||||
int result;
|
int result;
|
||||||
volatile int waiting_count;
|
int waiting_count;
|
||||||
};
|
};
|
||||||
} SFSynchronizeContext;
|
} SFSynchronizeContext;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue