add function sf_synchronize_counter_wait
parent
0eb483f68c
commit
cccb1c6d23
|
|
@ -19,6 +19,7 @@
|
||||||
#define _SF_FUNC_H
|
#define _SF_FUNC_H
|
||||||
|
|
||||||
#include "fastcommon/pthread_func.h"
|
#include "fastcommon/pthread_func.h"
|
||||||
|
#include "fastcommon/fc_atomic.h"
|
||||||
#include "sf_types.h"
|
#include "sf_types.h"
|
||||||
#include "sf_global.h"
|
#include "sf_global.h"
|
||||||
|
|
||||||
|
|
@ -71,9 +72,19 @@ static inline void sf_binlog_buffer_destroy(SFBinlogBuffer *buffer)
|
||||||
|
|
||||||
static inline int sf_synchronize_ctx_init(SFSynchronizeContext *sctx)
|
static inline int sf_synchronize_ctx_init(SFSynchronizeContext *sctx)
|
||||||
{
|
{
|
||||||
|
sctx->waiting_count = 0;
|
||||||
return init_pthread_lock_cond_pair(&sctx->lcp);
|
return init_pthread_lock_cond_pair(&sctx->lcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
|
||||||
|
{
|
||||||
|
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||||
|
while (FC_ATOMIC_GET(sctx->waiting_count) != 0) {
|
||||||
|
pthread_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
|
||||||
|
}
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ typedef struct sf_synchronize_context {
|
||||||
union {
|
union {
|
||||||
bool done;
|
bool done;
|
||||||
int result;
|
int result;
|
||||||
|
volatile int waiting_count;
|
||||||
};
|
};
|
||||||
} SFSynchronizeContext;
|
} SFSynchronizeContext;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue