add functions sf_synchronize_finished_notify/wait

replication_quorum
YuQing 2022-07-04 11:01:24 +08:00
parent d95e3ed679
commit 7cfb8dc89d
1 changed files with 19 additions and 0 deletions

View File

@ -117,6 +117,25 @@ static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock); PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
} }
static inline void sf_synchronize_finished_notify(
SFSynchronizeContext *sctx)
{
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
sctx->finished = true;
pthread_cond_signal(&sctx->lcp.cond);
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
}
static inline void sf_synchronize_finished_wait(SFSynchronizeContext *sctx)
{
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
while (!sctx->finished && SF_G_CONTINUE_FLAG) {
pthread_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
}
sctx->finished = false; //for next notify
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif