summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
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 9a5453b185..1765de9573 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -1177,9 +1177,14 @@ 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;
frrtrace(9, frr_libfrr, thread_cancel, master, thread->funcname,
thread->schedfrom, thread->schedfrom_line, NULL, thread->u.fd,
@@ -1190,10 +1195,12 @@ void thread_cancel(struct thread *thread)
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;
}
/**
@@ -1256,6 +1263,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;
}
/* ------------------------------------------------------------------------- */