sf_synchronize_finished_notify_no_lock impl.
parent
7cfb8dc89d
commit
a966d1bf4d
|
|
@ -117,23 +117,32 @@ static inline void sf_synchronize_counter_wait(SFSynchronizeContext *sctx)
|
||||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define sf_synchronize_finished_notify_no_lock(sctx, err_no) \
|
||||||
|
(sctx)->finished = true; \
|
||||||
|
(sctx)->result = err_no; \
|
||||||
|
pthread_cond_signal(&(sctx)->lcp.cond)
|
||||||
|
|
||||||
static inline void sf_synchronize_finished_notify(
|
static inline void sf_synchronize_finished_notify(
|
||||||
SFSynchronizeContext *sctx)
|
SFSynchronizeContext *sctx, const int result)
|
||||||
{
|
{
|
||||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||||
sctx->finished = true;
|
sf_synchronize_finished_notify_no_lock(sctx, result);
|
||||||
pthread_cond_signal(&sctx->lcp.cond);
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sf_synchronize_finished_wait(SFSynchronizeContext *sctx)
|
static inline int sf_synchronize_finished_wait(SFSynchronizeContext *sctx)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_LOCK(&sctx->lcp.lock);
|
||||||
while (!sctx->finished && SF_G_CONTINUE_FLAG) {
|
while (!sctx->finished && SF_G_CONTINUE_FLAG) {
|
||||||
pthread_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
|
pthread_cond_wait(&sctx->lcp.cond, &sctx->lcp.lock);
|
||||||
}
|
}
|
||||||
|
result = sctx->result;
|
||||||
sctx->finished = false; //for next notify
|
sctx->finished = false; //for next notify
|
||||||
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
PTHREAD_MUTEX_UNLOCK(&sctx->lcp.lock);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -237,9 +237,9 @@ typedef struct sf_cluster_config {
|
||||||
|
|
||||||
typedef struct sf_synchronize_context {
|
typedef struct sf_synchronize_context {
|
||||||
pthread_lock_cond_pair_t lcp;
|
pthread_lock_cond_pair_t lcp;
|
||||||
|
int result;
|
||||||
union {
|
union {
|
||||||
bool finished;
|
bool finished;
|
||||||
int result;
|
|
||||||
int waiting_count;
|
int waiting_count;
|
||||||
};
|
};
|
||||||
} SFSynchronizeContext;
|
} SFSynchronizeContext;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue