aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/aio.c8
-rw-r--r--src/core/aio.h6
-rw-r--r--src/core/aio_test.c15
-rw-r--r--src/core/taskq.c20
-rw-r--r--src/core/taskq.h9
-rw-r--r--src/nng.c8
6 files changed, 56 insertions, 10 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index 65d8b984..771cbc95 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -314,6 +314,12 @@ nni_aio_wait(nni_aio *aio)
nni_task_wait(&aio->a_task);
}
+bool
+nni_aio_busy(nni_aio *aio)
+{
+ return (nni_task_busy(&aio->a_task));
+}
+
int
nni_aio_begin(nni_aio *aio)
{
diff --git a/src/core/aio.h b/src/core/aio.h
index d1d4cf79..6315e90c 100644
--- a/src/core/aio.h
+++ b/src/core/aio.h
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -93,6 +93,10 @@ extern int nni_aio_result(nni_aio *);
// completed.
extern size_t nni_aio_count(nni_aio *);
+// nni_aio_busy returns true if the aio is still busy processing work.
+// This is a non-blocking form of the check used by nni_aio_wait().
+extern bool nni_aio_busy(nni_aio *);
+
// nni_aio_wait blocks the caller until the operation is complete.
// The operation must have already been started. This routine will
// block until the AIO, as well as any callback, has completed execution.
diff --git a/src/core/aio_test.c b/src/core/aio_test.c
index a94978bc..bbc997b5 100644
--- a/src/core/aio_test.c
+++ b/src/core/aio_test.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -364,6 +364,18 @@ test_sleep_cancel(void)
nng_mtx_free(sl.mx);
}
+void
+ test_aio_busy(void)
+{
+ nng_aio *aio;
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ nng_sleep_aio(100, aio);
+ NUTS_ASSERT(nng_aio_busy(aio));
+ nng_aio_wait(aio);
+ NUTS_ASSERT(!nng_aio_busy(aio));
+ nng_aio_free(aio);
+}
+
NUTS_TESTS = {
{ "sleep", test_sleep },
{ "sleep timeout", test_sleep_timeout },
@@ -377,5 +389,6 @@ NUTS_TESTS = {
{ "aio reap", test_aio_reap },
{ "sleep loop", test_sleep_loop },
{ "sleep cancel", test_sleep_cancel },
+ { "aio busy", test_aio_busy },
{ NULL, NULL },
}; \ No newline at end of file
diff --git a/src/core/taskq.c b/src/core/taskq.c
index e06bc264..d914093b 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -31,12 +31,12 @@ static void
nni_taskq_thread(void *self)
{
nni_taskq_thr *thr = self;
- nni_taskq * tq = thr->tqt_tq;
- nni_task * task;
+ nni_taskq *tq = thr->tqt_tq;
+ nni_task *task;
- nni_thr_set_name(NULL, "nng:task");
+ nni_thr_set_name(NULL, "nng:task");
- nni_mtx_lock(&tq->tq_mtx);
+ nni_mtx_lock(&tq->tq_mtx);
for (;;) {
if ((task = nni_list_first(&tq->tq_tasks)) != NULL) {
@@ -207,6 +207,16 @@ nni_task_wait(nni_task *task)
nni_mtx_unlock(&task->task_mtx);
}
+bool
+nni_task_busy(nni_task *task)
+{
+ bool busy;
+ nni_mtx_lock(&task->task_mtx);
+ busy = task->task_busy;
+ nni_mtx_unlock(&task->task_mtx);
+ return (busy);
+}
+
void
nni_task_init(nni_task *task, nni_taskq *tq, nni_cb cb, void *arg)
{
diff --git a/src/core/taskq.h b/src/core/taskq.h
index 9cabfd9b..2ff449cf 100644
--- a/src/core/taskq.h
+++ b/src/core/taskq.h
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -43,6 +43,13 @@ extern void nni_task_prep(nni_task *);
// returns an error.
extern void nni_task_abort(nni_task *);
+// nni_task_busy checks to see if a task is still busy.
+// This is uses the same check that nni_task_wait uses.
+extern bool nni_task_busy(nni_task *);
+
+// nni_task_wait waits for the task to complete. If additional
+// work is scheduled on the task then it will not return until that
+// work (or any other work subsequently scheduled) is complete.
extern void nni_task_wait(nni_task *);
extern void nni_task_init(nni_task *, nni_taskq *, nni_cb, void *);
diff --git a/src/nng.c b/src/nng.c
index c48ccd0b..79259568 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -1883,6 +1883,12 @@ nng_aio_wait(nng_aio *aio)
nni_aio_wait(aio);
}
+bool
+nng_aio_busy(nng_aio *aio)
+{
+ return (nni_aio_busy(aio));
+}
+
void
nng_aio_abort(nng_aio *aio, int err_code)
{