From 255754eb5f7e2565dd44864515de9ef1af1a0e6b Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 28 Oct 2021 16:19:02 +0800 Subject: [PATCH] add function sf_synchronize_counter_notify --- src/sf_func.h | 8 ++++++++ src/sf_types.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sf_func.h b/src/sf_func.h index a3536e3..688c31b 100644 --- a/src/sf_func.h +++ b/src/sf_func.h @@ -76,6 +76,14 @@ 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) +{ + if (__sync_sub_and_fetch(&sctx->waiting_count, count) == 0) { + pthread_cond_signal(&sctx->lcp.cond); + } +} + static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx) { PTHREAD_MUTEX_LOCK(&sctx->lcp.lock); diff --git a/src/sf_types.h b/src/sf_types.h index 6597cf4..bbe199c 100644 --- a/src/sf_types.h +++ b/src/sf_types.h @@ -238,7 +238,7 @@ typedef struct sf_cluster_config { typedef struct sf_synchronize_context { pthread_lock_cond_pair_t lcp; union { - bool done; + bool finished; int result; volatile int waiting_count; };