aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-03 12:44:02 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-03 12:44:02 -0700
commitc1a92ee76a3e9e70ecae4646763bade0c16e4807 (patch)
treec6cca5b8ff6227e38e1dc9dabec24a4b1373d799 /src/core/aio.c
parent14c8396d6954622de9e07b010810ee49f0496b2a (diff)
downloadnng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.tar.gz
nng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.tar.bz2
nng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.zip
inproc transport uses aio for connect/accept.
Diffstat (limited to 'src/core/aio.c')
-rw-r--r--src/core/aio.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index 6a57ad52..f4512a34 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -50,6 +50,7 @@ nni_aio_fini(nni_aio *aio)
nni_mtx_lock(&aio->a_lk);
aio->a_flags |= NNI_AIO_FINI; // this prevents us from being scheduled
cancelfn = aio->a_prov_cancel;
+ nni_cv_wake(&aio->a_cv);
nni_mtx_unlock(&aio->a_lk);
// Cancel the AIO if it was scheduled.
@@ -71,7 +72,15 @@ nni_aio_fini(nni_aio *aio)
int
nni_aio_result(nni_aio *aio)
{
- return (aio->a_result);
+ int rv;
+
+ nni_mtx_lock(&aio->a_lk);
+ rv = aio->a_result;
+ if (aio->a_flags & (NNI_AIO_FINI|NNI_AIO_STOP)) {
+ rv = NNG_ECANCELED;
+ }
+ nni_mtx_unlock(&aio->a_lk);
+ return (rv);
}
@@ -96,7 +105,7 @@ void
nni_aio_wait(nni_aio *aio)
{
nni_mtx_lock(&aio->a_lk);
- while ((aio->a_flags & NNI_AIO_WAKE) == 0) {
+ while ((aio->a_flags & (NNI_AIO_WAKE|NNI_AIO_FINI)) == 0) {
nni_cv_wait(&aio->a_cv);
}
nni_mtx_unlock(&aio->a_lk);
@@ -143,6 +152,7 @@ nni_aio_stop(nni_aio *aio)
nni_mtx_lock(&aio->a_lk);
aio->a_prov_data = NULL;
aio->a_prov_cancel = NULL;
+ nni_cv_wake(&aio->a_cv);
nni_mtx_unlock(&aio->a_lk);
// This either aborts the task, or waits for it to complete if already