Skip to content

Commit

Permalink
improved wait_safe() loop
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Nov 21, 2023
1 parent 5a3e9a8 commit 16211d6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,28 +1736,27 @@ SEXP rnng_cv_wait_safe(SEXP cvar) {
nano_cv *ncv = (nano_cv *) R_ExternalPtrAddr(cvar);
nng_cv *cv = ncv->cv;
nng_mtx *mtx = ncv->mtx;
int signalled;
uint8_t flag;

do {
int signalled = 1;
signalled = 1;
nng_mtx_lock(mtx);
while (ncv->condition == 0) {
if (nng_cv_until(cv, 2000) == NNG_ETIMEDOUT) {
signalled = 0;
break;
}
}
if (signalled) {
ncv->condition--;
flag = ncv->flag;
nng_mtx_unlock(mtx);
break;
} else {
nng_mtx_unlock(mtx);
R_CheckUserInterrupt();
}
if (signalled) break;
nng_mtx_unlock(mtx);
R_CheckUserInterrupt();
} while (1);

ncv->condition--;
flag = ncv->flag;
nng_mtx_unlock(mtx);

return Rf_ScalarLogical(flag == 0);

}
Expand Down

0 comments on commit 16211d6

Please sign in to comment.