diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-15 12:35:19 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-15 12:35:19 -0700 |
| commit | 959f4588a164f0a524c4a654b06fcade01f5e6d5 (patch) | |
| tree | e55ef823b6095c5215b21d2facc3a71e7aaf2f99 | |
| parent | 81808ce3d38cc7ce0131367e2187f0beb2cd1b43 (diff) | |
| download | nng-959f4588a164f0a524c4a654b06fcade01f5e6d5.tar.gz nng-959f4588a164f0a524c4a654b06fcade01f5e6d5.tar.bz2 nng-959f4588a164f0a524c4a654b06fcade01f5e6d5.zip | |
fixes #433 tasks can leak
While here I also improved the taskq.h comments (and removed a
stale prototype for nni_task_cancel), and addressed leaks in
the reqstress and multistress test programs.
| -rw-r--r-- | src/core/taskq.c | 2 | ||||
| -rw-r--r-- | src/core/taskq.h | 20 | ||||
| -rw-r--r-- | tests/multistress.c | 2 | ||||
| -rw-r--r-- | tests/reqstress.c | 2 |
4 files changed, 22 insertions, 4 deletions
diff --git a/src/core/taskq.c b/src/core/taskq.c index a87e4729..d945e713 100644 --- a/src/core/taskq.c +++ b/src/core/taskq.c @@ -285,7 +285,7 @@ nni_task_fini(nni_task *task) { NNI_ASSERT(!nni_list_node_active(&task->task_node)); nni_mtx_lock(&task->task_mtx); - if (task->task_run || task->task_exec) { + if ((task->task_run || task->task_exec) && (!task->task_done)) { // destroy later. task->task_fini = true; nni_mtx_unlock(&task->task_mtx); diff --git a/src/core/taskq.h b/src/core/taskq.h index 513b15bb..918c6705 100644 --- a/src/core/taskq.h +++ b/src/core/taskq.h @@ -23,15 +23,29 @@ extern void nni_taskq_fini(nni_taskq *); // 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_exec runs the task synchronously, if possible. (Under certain +// circumstances the task must be run asynchronously.) The caller is +// responsible for ensuring that it does not hold any resources which might +// be acquired by the task itself; otherwise deadlock may occur. (When in +// doubt, use nni_task_dispatch instead.) extern void nni_task_exec(nni_task *); + +// nni_task_prep and nni_task_unprep are used by and exclusively for the aio +// framework. nni_task_prep marks the task as "scheduled" without actually +// dispatching anything to it yet; nni_task_wait will block waiting for the +// task to complete normally (after a call to nni_task_dispatch or +// nni_task_exec), or for nni_task_unprep to be called. extern void nni_task_prep(nni_task *); extern void nni_task_unprep(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 int 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 +// callback must be stopped entirely before destroying the task (such as if +// it reschedules the task.) extern void nni_task_fini(nni_task *); extern int nni_taskq_sys_init(void); diff --git a/tests/multistress.c b/tests/multistress.c index 62838a73..1ec2bc6c 100644 --- a/tests/multistress.c +++ b/tests/multistress.c @@ -675,4 +675,6 @@ Main({ } }); }); + + free(cases); }) diff --git a/tests/reqstress.c b/tests/reqstress.c index f2ee502d..fa4b0975 100644 --- a/tests/reqstress.c +++ b/tests/reqstress.c @@ -290,4 +290,6 @@ Main({ } }); }); + + free(cases); }) |
