aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-09 13:33:11 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-22 21:31:28 -0800
commitc8ce57d668d73d92a071fa86f81e07ca403d8672 (patch)
treead7e602e43fefa64067fdac5fcd23987a50c3a90 /src/core/aio.h
parent013bb69c6be2f0a4572f4200de05e664692b6704 (diff)
downloadnng-c8ce57d668d73d92a071fa86f81e07ca403d8672.tar.gz
nng-c8ce57d668d73d92a071fa86f81e07ca403d8672.tar.bz2
nng-c8ce57d668d73d92a071fa86f81e07ca403d8672.zip
aio: introduce nni_aio_defer
This will replace nni_aio_schedule, and it includes finishing the task if needed. It does so without dropping the lock and so is more efficient and race free. This includes some conversion of some subsystems to it.
Diffstat (limited to 'src/core/aio.h')
-rw-r--r--src/core/aio.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/aio.h b/src/core/aio.h
index 9491a2fa..8628d8ef 100644
--- a/src/core/aio.h
+++ b/src/core/aio.h
@@ -164,8 +164,17 @@ extern void nni_aio_bump_count(nni_aio *, size_t);
// is returned. (In that case the caller should probably either return an
// error to its caller, or possibly cause an asynchronous error by calling
// nni_aio_finish_error on this aio.)
+//
+// NB: This function should be called while holding the lock that will be used
+// to cancel the operation. Otherwise a race can occur where the operation
+// cannot be canceled, which can lead to apparent hangs.
extern int nni_aio_schedule(nni_aio *, nni_aio_cancel_fn, void *);
+// nni_aio_defer is just like nni_io_schedule, but it also calls the callback
+// automatically if the operation cannot be started because the AIO is stopped
+// or was canceled before this call (but after nni_aio_begin).
+extern bool nni_aio_defer(nni_aio *, nni_aio_cancel_fn, void *);
+
extern void nni_sleep_aio(nni_duration, nni_aio *);
// nni_aio_completion_list is used after removing the aio from an