diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-05 21:13:14 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-06 07:20:58 -0800 |
| commit | 8479b4c8861c77cfd9eb64e724615605bdd1cbcb (patch) | |
| tree | 6fdd38384831ff9d2bcb6552b122c404fc9713cb /src | |
| parent | 758a9e8295251ddaf9cebd973f8394a4b25eb9d4 (diff) | |
| download | nng-8479b4c8861c77cfd9eb64e724615605bdd1cbcb.tar.gz nng-8479b4c8861c77cfd9eb64e724615605bdd1cbcb.tar.bz2 nng-8479b4c8861c77cfd9eb64e724615605bdd1cbcb.zip | |
fixes #1117 task structures should be inlined
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/aio.c | 26 | ||||
| -rw-r--r-- | src/core/taskq.c | 22 | ||||
| -rw-r--r-- | src/core/taskq.h | 16 |
3 files changed, 28 insertions, 36 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 738dd48b..9f025f4c 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -68,10 +68,10 @@ struct nng_aio { nni_time a_expire; // Absolute timeout nni_duration a_timeout; // Relative timeout - bool a_stop; // shutting down (no new operations) - bool a_sleep; // sleeping with no action - bool a_expire_ok; // expire from sleep is ok - nni_task *a_task; + bool a_stop; // shutting down (no new operations) + bool a_sleep; // sleeping with no action + bool a_expire_ok; // expire from sleep is ok + nni_task a_task; // Read/write operations. nni_iov a_iov[8]; @@ -112,15 +112,11 @@ int nni_aio_init(nni_aio **aiop, nni_cb cb, void *arg) { nni_aio *aio; - int rv; if ((aio = NNI_ALLOC_STRUCT(aio)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_task_init(&aio->a_task, NULL, cb, arg)) != 0) { - NNI_FREE_STRUCT(aio); - return (rv); - } + nni_task_init(&aio->a_task, NULL, cb, arg); aio->a_expire = NNI_TIME_NEVER; aio->a_timeout = NNG_DURATION_INFINITE; *aiop = aio; @@ -164,7 +160,7 @@ nni_aio_fini(nni_aio *aio) } nni_mtx_unlock(&nni_aio_lk); - nni_task_fini(aio->a_task); + nni_task_fini(&aio->a_task); NNI_FREE_STRUCT(aio); } @@ -323,7 +319,7 @@ nni_aio_count(nni_aio *aio) void nni_aio_wait(nni_aio *aio) { - nni_task_wait(aio->a_task); + nni_task_wait(&aio->a_task); } int @@ -342,7 +338,7 @@ nni_aio_begin(nni_aio *aio) aio->a_expire_ok = false; nni_mtx_unlock(&nni_aio_lk); - nni_task_dispatch(aio->a_task); + nni_task_dispatch(&aio->a_task); return (NNG_ECANCELED); } aio->a_result = 0; @@ -352,7 +348,7 @@ nni_aio_begin(nni_aio *aio) for (unsigned i = 0; i < NNI_NUM_ELEMENTS(aio->a_outputs); i++) { aio->a_outputs[i] = NULL; } - nni_task_prep(aio->a_task); + nni_task_prep(&aio->a_task); nni_mtx_unlock(&nni_aio_lk); return (0); } @@ -436,9 +432,9 @@ nni_aio_finish_impl( nni_mtx_unlock(&nni_aio_lk); if (synch) { - nni_task_exec(aio->a_task); + nni_task_exec(&aio->a_task); } else { - nni_task_dispatch(aio->a_task); + nni_task_dispatch(&aio->a_task); } } diff --git a/src/core/taskq.c b/src/core/taskq.c index f9b08f30..09e822df 100644 --- a/src/core/taskq.c +++ b/src/core/taskq.c @@ -11,16 +11,6 @@ #include "core/nng_impl.h" typedef struct nni_taskq_thr nni_taskq_thr; -struct nni_task { - nni_list_node task_node; - void * task_arg; - nni_cb task_cb; - nni_taskq * task_tq; - unsigned task_busy; - bool task_prep; - nni_mtx task_mtx; - nni_cv task_cv; -}; struct nni_taskq_thr { nni_taskq *tqt_tq; nni_thr tqt_thread; @@ -203,14 +193,9 @@ nni_task_wait(nni_task *task) nni_mtx_unlock(&task->task_mtx); } -int -nni_task_init(nni_task **taskp, nni_taskq *tq, nni_cb cb, void *arg) +void +nni_task_init(nni_task *task, nni_taskq *tq, nni_cb cb, void *arg) { - nni_task *task; - - if ((task = NNI_ALLOC_STRUCT(task)) == NULL) { - return (NNG_ENOMEM); - } NNI_LIST_NODE_INIT(&task->task_node); nni_mtx_init(&task->task_mtx); nni_cv_init(&task->task_cv, &task->task_mtx); @@ -219,8 +204,6 @@ nni_task_init(nni_task **taskp, nni_taskq *tq, nni_cb cb, void *arg) task->task_cb = cb; task->task_arg = arg; task->task_tq = tq != NULL ? tq : nni_taskq_systq; - *taskp = task; - return (0); } void @@ -233,7 +216,6 @@ nni_task_fini(nni_task *task) nni_mtx_unlock(&task->task_mtx); nni_cv_fini(&task->task_cv); nni_mtx_fini(&task->task_mtx); - NNI_FREE_STRUCT(task); } int diff --git a/src/core/taskq.h b/src/core/taskq.h index 8328e4eb..53f9d35b 100644 --- a/src/core/taskq.h +++ b/src/core/taskq.h @@ -39,7 +39,7 @@ extern void nni_task_exec(nni_task *); extern void nni_task_prep(nni_task *); extern void nni_task_wait(nni_task *); -extern int nni_task_init(nni_task **, nni_taskq *, nni_cb, void *); +extern void nni_task_init(nni_task *, nni_taskq *, nni_cb, void *); // nni_task_fini destroys the task. It will reap resources asynchronously // if the task is currently executing. Use nni_task_wait() first if the @@ -50,4 +50,18 @@ extern void nni_task_fini(nni_task *); extern int nni_taskq_sys_init(void); extern void nni_taskq_sys_fini(void); +// nni_task implementation details are not to be used except by the +// nni_task_framework. Placing here allows for inlining this in +// consuming structures. +struct nni_task { + nni_list_node task_node; + void * task_arg; + nni_cb task_cb; + nni_taskq * task_tq; + unsigned task_busy; + bool task_prep; + nni_mtx task_mtx; + nni_cv task_cv; +}; + #endif // CORE_TASKQ_H |
