aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-02-23 20:26:48 -0800
committerGarrett D'Amore <garrett@damore.org>2017-02-23 20:26:48 -0800
commit13fe0a4424b55a75b20efb6a056f8cbb39739b24 (patch)
treebfa889abe3d54f870111c62e4f85aa228563dac1 /src/core/aio.c
parent1981675919003f2ea01971bb4fccbe99c57a2caf (diff)
downloadnng-13fe0a4424b55a75b20efb6a056f8cbb39739b24.tar.gz
nng-13fe0a4424b55a75b20efb6a056f8cbb39739b24.tar.bz2
nng-13fe0a4424b55a75b20efb6a056f8cbb39739b24.zip
Rename ioev to aio. Eliminate generic cancel handling (not needed).
We will still need some kind of specific handling of cancellation for msg queues, but it will be simpler to just implement that for the queues, and not worry about cancellation in the general case around poll etc. (The low level poll and I/O routines will get notified by their underlying transport pipes/descriptors closing.)
Diffstat (limited to 'src/core/aio.c')
-rw-r--r--src/core/aio.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
new file mode 100644
index 00000000..b8304e8a
--- /dev/null
+++ b/src/core/aio.c
@@ -0,0 +1,90 @@
+//
+// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+//
+// This software is supplied under the terms of the MIT License, a
+// copy of which should be located in the distribution where this
+// file was obtained (LICENSE.txt). A copy of the license may also be
+// found online at https://opensource.org/licenses/MIT.
+//
+
+#include <string.h>
+#include "core/nng_impl.h"
+
+#define NNI_AIO_WAKE (1<<0)
+
+void
+nni_aio_init(nni_aio *aio, nni_cb cb, void *arg)
+{
+ if (cb == NULL) {
+ cb = (nni_cb) nni_aio_wake;
+ arg = aio;
+ }
+ memset(aio, 0, sizeof (*aio));
+ nni_mtx_init(&aio->a_lk);
+ nni_cv_init(&aio->a_cv, &aio->a_lk);
+ aio->a_cb = cb;
+ aio->a_cbarg = arg;
+}
+
+
+void
+nni_aio_fini(nni_aio *aio)
+{
+ nni_cv_fini(&aio->a_cv);
+ nni_mtx_fini(&aio->a_lk);
+}
+
+
+int
+nni_aio_result(nni_aio *aio)
+{
+ return (aio->a_result);
+}
+
+
+size_t
+nni_aio_count(nni_aio *aio)
+{
+ return (aio->a_count);
+}
+
+
+void
+nni_aio_wake(nni_aio *aio)
+{
+ nni_mtx_lock(&aio->a_lk);
+ aio->a_flags |= NNI_AIO_WAKE;
+ nni_cv_wake(&aio->a_cv);
+ nni_mtx_unlock(&aio->a_lk);
+}
+
+
+void
+nni_aio_wait(nni_aio *aio)
+{
+ nni_mtx_lock(&aio->a_lk);
+ while ((aio->a_flags & NNI_AIO_WAKE) == 0) {
+ nni_cv_wait(&aio->a_cv);
+ }
+ nni_mtx_unlock(&aio->a_lk);
+}
+
+
+// I/O provider related functions.
+
+void
+nni_aio_finish(nni_aio *aio, int result, size_t count)
+{
+ nni_cb cb;
+ void *arg;
+
+ nni_mtx_lock(&aio->a_lk);
+ aio->a_result = result;
+ aio->a_count = count;
+ cb = aio->a_cb;
+ arg = aio->a_cbarg;
+ nni_cv_wake(&aio->a_cv);
+ nni_mtx_unlock(&aio->a_lk);
+
+ cb(arg);
+}