diff options
Diffstat (limited to 'src/core/aio.c')
| -rw-r--r-- | src/core/aio.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 3c85b78d..a39c0118 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -124,6 +124,7 @@ nni_aio_wait(nni_aio *aio) { nni_mtx_lock(&nni_aio_lk); while ((aio->a_active) && (!aio->a_done)) { + aio->a_waiting = 1; nni_cv_wait(&aio->a_cv); } nni_mtx_unlock(&nni_aio_lk); @@ -201,7 +202,10 @@ nni_aio_finish_impl( // still holding the reference. if (!aio->a_expiring) { aio->a_done = 1; - nni_cv_wake(&aio->a_cv); + if (aio->a_waiting) { + aio->a_waiting = 0; + nni_cv_wake(&aio->a_cv); + } nni_task_dispatch(&aio->a_task); } nni_mtx_unlock(&nni_aio_lk); @@ -337,7 +341,10 @@ nni_aio_expire_loop(void *arg) NNI_ASSERT(aio->a_prov_cancel == NULL); aio->a_expiring = 0; aio->a_done = 1; - nni_cv_wake(&aio->a_cv); + if (aio->a_waiting) { + aio->a_waiting = 0; + nni_cv_wake(&aio->a_cv); + } nni_task_dispatch(&aio->a_task); nni_mtx_unlock(&nni_aio_lk); } |
