Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
scount: change the signal API to return count
Browse files Browse the repository at this point in the history
This is useful for the caller to track the state of the waiting thread; count =
0 means the target thread is no longer waiting
  • Loading branch information
Halim Amer committed Jun 1, 2018
1 parent 539a18b commit 2ad749e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/cond/zm_scount.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ int zm_scount_wait(struct zm_scount *C, zm_lock_t *L) {
return 0;
}

int zm_scount_signal(struct zm_scount *C) {
int zm_scount_signal(struct zm_scount *C, int *out_count) {
int ret = 0;
if(C->count > 0) {
C->count--;
if(C->count == 0)
ret = zm_ccond_signal(&C->cvar);
}
*out_count = C->count;
return ret;
}

/* Forced wake up regardless of the counter */
int zm_scond_signalf(struct zm_scount *C) {
int ret = 0;
if(C->count > 0)
C->count--;
/* wakeup signal regardless of the counter value */
ret = zm_ccond_signal(&C->cvar);

Expand Down
2 changes: 1 addition & 1 deletion src/include/cond/zm_scount.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
int zm_scount_init(struct zm_scount *C, int);
int zm_scount_destroy(struct zm_scount *C);
int zm_scount_wait(struct zm_scount *C, zm_lock_t *L);
int zm_scount_signal(struct zm_scount *C);
int zm_scount_signal(struct zm_scount *C, int*);
int zm_scount_signalf(struct zm_scount *C);

#endif /* _ZM_SCOND_H */
3 changes: 2 additions & 1 deletion test/regres/cond/prio_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static void* run(void *arg) {
counter++;
for(int i = 1; i<TEST_NTHREADS; i++) {
int trg = (tid + i) % TEST_NTHREADS;
zm_scount_signal(&scounts[trg]);
int out_count; /* ignored */
zm_scount_signal(&scounts[trg], &out_count);
}

zm_lock_release(&glock); /* Release the lock */
Expand Down

0 comments on commit 2ad749e

Please sign in to comment.