diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-07-21 02:46:01 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-07-21 02:46:01 -0700 |
| commit | 537e2eda8d9fda2001295c835a4720def6a237f1 (patch) | |
| tree | 615d05096e0fe4c8bfbccf31f37c7256381ccd8e /src/core/taskq.h | |
| parent | 07078e1cf761cb6e56e46bde3ade6f792368d7dd (diff) | |
| download | nng-537e2eda8d9fda2001295c835a4720def6a237f1.tar.gz nng-537e2eda8d9fda2001295c835a4720def6a237f1.tar.bz2 nng-537e2eda8d9fda2001295c835a4720def6a237f1.zip | |
Simpler taskq API.
The queue is bound at initialization time of the task, and we call
entries just tasks, so we don't have to pass around a taskq pointer
across all the calls. Further, nni_task_dispatch is now guaranteed
to succeed.
Diffstat (limited to 'src/core/taskq.h')
| -rw-r--r-- | src/core/taskq.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/core/taskq.h b/src/core/taskq.h index e6399706..89b7be4a 100644 --- a/src/core/taskq.h +++ b/src/core/taskq.h @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore <garrett@damore.org> +// Copyright 2017 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -13,23 +14,30 @@ #include "core/defs.h" #include "core/list.h" -typedef struct nni_taskq nni_taskq; -typedef struct nni_taskq_ent nni_taskq_ent; +typedef struct nni_taskq nni_taskq; +typedef struct nni_task nni_task; -struct nni_taskq_ent { - nni_list_node tqe_node; - void * tqe_arg; - nni_cb tqe_cb; - nni_taskq * tqe_tq; +// nni_task is a structure representing a task. Its intended to inlined +// into structures so that taskq_dispatch can be a guaranteed operation. +struct nni_task { + nni_list_node task_node; + void * task_arg; + nni_cb task_cb; + nni_taskq * task_tq; }; extern int nni_taskq_init(nni_taskq **, int); extern void nni_taskq_fini(nni_taskq *); -extern int nni_taskq_dispatch(nni_taskq *, nni_taskq_ent *); -extern int nni_taskq_cancel(nni_taskq *, nni_taskq_ent *); -extern void nni_taskq_wait(nni_taskq *, nni_taskq_ent *); -extern void nni_taskq_ent_init(nni_taskq_ent *, nni_cb, void *); +// nni_task_dispatch sends the task to the queue. It is guaranteed to +// succeed. (If the queue is shutdown, then the behavior is undefined.) +extern void nni_task_dispatch(nni_task *); + +// nni_task_cancel cancels the task. It will wait for the task to complete +// if it is already running. +extern int nni_task_cancel(nni_task *); +extern void nni_task_wait(nni_task *); +extern void nni_task_init(nni_taskq *, nni_task *, nni_cb, void *); extern int nni_taskq_sys_init(void); extern void nni_taskq_sys_fini(void); |
