From c8ce57d668d73d92a071fa86f81e07ca403d8672 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 9 Dec 2024 13:33:11 -0800 Subject: 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. --- src/core/aio.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/core/aio.h') 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 -- cgit v1.2.3-70-g09d2