summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/lib/thread.c b/lib/thread.c
index db35a3f031..1765de9573 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -35,6 +35,7 @@
#include "frratomic.h"
#include "frr_pthread.h"
#include "lib_errors.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread")
DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master")
@@ -787,6 +788,13 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m,
struct thread *thread = NULL;
struct thread **thread_array;
+ if (dir == THREAD_READ)
+ frrtrace(9, frr_libfrr, schedule_read, m, funcname, schedfrom,
+ fromln, t_ptr, fd, 0, arg, 0);
+ else
+ frrtrace(9, frr_libfrr, schedule_write, m, funcname, schedfrom,
+ fromln, t_ptr, fd, 0, arg, 0);
+
assert(fd >= 0 && fd < m->fd_limit);
frr_with_mutex(&m->mtx) {
if (t_ptr && *t_ptr)
@@ -861,6 +869,9 @@ funcname_thread_add_timer_timeval(struct thread_master *m,
assert(type == THREAD_TIMER);
assert(time_relative);
+ frrtrace(9, frr_libfrr, schedule_timer, m, funcname, schedfrom, fromln,
+ t_ptr, 0, 0, arg, (long)time_relative->tv_sec);
+
frr_with_mutex(&m->mtx) {
if (t_ptr && *t_ptr)
/* thread is already scheduled; don't reschedule */
@@ -939,6 +950,9 @@ struct thread *funcname_thread_add_event(struct thread_master *m,
{
struct thread *thread = NULL;
+ frrtrace(9, frr_libfrr, schedule_event, m, funcname, schedfrom, fromln,
+ t_ptr, 0, val, arg, 0);
+
assert(m != NULL);
frr_with_mutex(&m->mtx) {
@@ -1163,19 +1177,30 @@ 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,
+ thread->u.val, thread->arg, thread->u.sands.tv_sec);
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;
}
/**
@@ -1206,6 +1231,17 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
void *eventobj)
{
assert(!(thread && eventobj) && (thread || eventobj));
+
+ if (thread && *thread)
+ frrtrace(9, frr_libfrr, thread_cancel_async, master,
+ (*thread)->funcname, (*thread)->schedfrom,
+ (*thread)->schedfrom_line, NULL, (*thread)->u.fd,
+ (*thread)->u.val, (*thread)->arg,
+ (*thread)->u.sands.tv_sec);
+ else
+ frrtrace(9, frr_libfrr, thread_cancel_async, master, NULL, NULL,
+ 0, NULL, 0, 0, eventobj, 0);
+
assert(master->owner != pthread_self());
frr_with_mutex(&master->mtx) {
@@ -1227,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;
}
/* ------------------------------------------------------------------------- */
@@ -1581,6 +1620,10 @@ void thread_call(struct thread *thread)
GETRUSAGE(&before);
thread->real = before.real;
+ frrtrace(9, frr_libfrr, thread_call, thread->master, thread->funcname,
+ thread->schedfrom, thread->schedfrom_line, NULL, thread->u.fd,
+ thread->u.val, thread->arg, thread->u.sands.tv_sec);
+
pthread_setspecific(thread_current, thread);
(*thread->func)(thread);
pthread_setspecific(thread_current, NULL);