summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@users.noreply.github.com>2020-10-23 15:02:50 -0400
committerGitHub <noreply@github.com>2020-10-23 15:02:50 -0400
commit939bd6ac52aec8def971d19529d0e782aa794ff1 (patch)
tree9104cb9bbb58261935187e42f5fea8b3702e0f1f /lib/thread.c
parent1e4fa7f46cc1c2d1fcb5c427c2d284bd1110a406 (diff)
parent70c583eb819d93d8ec494880f4645be0f942c7a5 (diff)
Merge pull request #6788 from mjstapp/thread_cancel_off
*: unify thread/task cancel apis
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/thread.c b/lib/thread.c
index db35a3f031..012194a47b 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -1163,19 +1163,26 @@ void thread_cancel_event(struct thread_master *master, void *arg)
*
* @param thread task to cancel
*/
-void thread_cancel(struct thread *thread)
+void thread_cancel(struct thread **thread)
{
- struct thread_master *master = thread->master;
+ struct thread_master *master;
+
+ if (thread == NULL || *thread == NULL)
+ return;
+
+ master = (*thread)->master;
assert(master->owner == pthread_self());
frr_with_mutex(&master->mtx) {
struct cancel_req *cr =
XCALLOC(MTYPE_TMP, sizeof(struct cancel_req));
- cr->thread = thread;
+ cr->thread = *thread;
listnode_add(master->cancel_req, cr);
do_thread_cancel(master);
}
+
+ *thread = NULL;
}
/**
@@ -1227,6 +1234,9 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
while (!master->canceled)
pthread_cond_wait(&master->cancel_cond, &master->mtx);
}
+
+ if (thread)
+ *thread = NULL;
}
/* ------------------------------------------------------------------------- */