aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/taskq.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/src/core/taskq.c b/src/core/taskq.c
index 12a986b1..f9b08f30 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 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
@@ -16,10 +16,8 @@ struct nni_task {
void * task_arg;
nni_cb task_cb;
nni_taskq * task_tq;
- nni_thr * task_thr; // non-NULL if the task is running
unsigned task_busy;
bool task_prep;
- bool task_reap; // reap task on completion
nni_mtx task_mtx;
nni_cv task_cv;
};
@@ -49,11 +47,9 @@ nni_taskq_thread(void *self)
nni_mtx_lock(&tq->tq_mtx);
for (;;) {
if ((task = nni_list_first(&tq->tq_tasks)) != NULL) {
- bool reap;
nni_mtx_lock(&task->task_mtx);
nni_list_remove(&tq->tq_tasks, task);
- task->task_thr = &thr->tqt_thread;
nni_mtx_unlock(&task->task_mtx);
nni_mtx_unlock(&tq->tq_mtx);
@@ -62,16 +58,11 @@ nni_taskq_thread(void *self)
nni_mtx_lock(&task->task_mtx);
task->task_busy--;
- task->task_thr = NULL;
- reap = task->task_reap;
if (task->task_busy == 0) {
nni_cv_wake(&task->task_cv);
}
nni_mtx_unlock(&task->task_mtx);
- if (reap) {
- nni_task_fini(task);
- }
nni_mtx_lock(&tq->tq_mtx);
continue;
@@ -148,7 +139,6 @@ nni_taskq_fini(nni_taskq *tq)
void
nni_task_exec(nni_task *task)
{
- bool reap;
nni_mtx_lock(&task->task_mtx);
if (task->task_prep) {
task->task_prep = false;
@@ -166,12 +156,7 @@ nni_task_exec(nni_task *task)
if (task->task_busy == 0) {
nni_cv_wake(&task->task_cv);
}
- reap = task->task_reap;
nni_mtx_unlock(&task->task_mtx);
-
- if (reap) {
- nni_task_fini(task);
- }
}
void
@@ -230,7 +215,6 @@ nni_task_init(nni_task **taskp, nni_taskq *tq, nni_cb cb, void *arg)
nni_mtx_init(&task->task_mtx);
nni_cv_init(&task->task_cv, &task->task_mtx);
task->task_prep = false;
- task->task_reap = false;
task->task_busy = 0;
task->task_cb = cb;
task->task_arg = arg;
@@ -243,15 +227,6 @@ void
nni_task_fini(nni_task *task)
{
nni_mtx_lock(&task->task_mtx);
-
- // If we are being called from the task function, then
- // defer the reap until after the callback has finished.
- if (task->task_busy && (task->task_thr != NULL) &&
- nni_thr_is_self(task->task_thr)) {
- task->task_reap = true;
- nni_mtx_unlock(&task->task_mtx);
- return;
- }
while (task->task_busy) {
nni_cv_wait(&task->task_cv);
}
@@ -268,9 +243,6 @@ nni_taskq_sys_init(void)
#ifndef NNG_NUM_TASKQ_THREADS
nthrs = nni_plat_ncpu() * 2;
- if (nthrs < 2) {
- nthrs = 2;
- }
#else
nthrs = NNG_NUM_TASKQ_THREADS;
#endif