summaryrefslogtreecommitdiffstats
path: root/lib/thread.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-05-16 17:46:41 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-05-16 17:59:51 +0200
commit56a94b366832f022db1f6dbd403dbdd82ac6eee9 (patch)
tree8e33f84676e1e4cb2cb89321d1cf038bee465705 /lib/thread.c
parentMerge pull request #539 from donaldsharp/arm (diff)
downloadfrr-56a94b366832f022db1f6dbd403dbdd82ac6eee9.tar.xz
frr-56a94b366832f022db1f6dbd403dbdd82ac6eee9.zip
lib: return thread pointer from thread_add*
Allow some more flexibility in case callers wish to manage their own thread pointers and don't require or don't want the thread to keep a back reference to its holding pointer. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/thread.c b/lib/thread.c
index aef9ac5cf..efc0dfb2a 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -777,7 +777,7 @@ fd_clear_read_write (struct thread *thread)
}
/* Add new read thread. */
-void
+struct thread *
funcname_thread_add_read_write (int dir, struct thread_master *m,
int (*func) (struct thread *), void *arg, int fd, struct thread **t_ptr,
debugargdef)
@@ -789,7 +789,7 @@ funcname_thread_add_read_write (int dir, struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return;
+ return NULL;
}
#if defined (HAVE_POLL_CALL)
@@ -839,9 +839,11 @@ funcname_thread_add_read_write (int dir, struct thread_master *m,
}
}
pthread_mutex_unlock (&m->mtx);
+
+ return thread;
}
-static void
+static struct thread *
funcname_thread_add_timer_timeval (struct thread_master *m,
int (*func) (struct thread *), int type, void *arg,
struct timeval *time_relative, struct thread **t_ptr, debugargdef)
@@ -859,7 +861,7 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return;
+ return NULL;
}
queue = ((type == THREAD_TIMER) ? m->timer : m->background);
@@ -879,11 +881,13 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
pthread_mutex_unlock (&thread->mtx);
}
pthread_mutex_unlock (&m->mtx);
+
+ return thread;
}
/* Add timer event thread. */
-void
+struct thread *
funcname_thread_add_timer (struct thread_master *m,
int (*func) (struct thread *), void *arg, long timer,
struct thread **t_ptr, debugargdef)
@@ -900,7 +904,7 @@ funcname_thread_add_timer (struct thread_master *m,
}
/* Add timer event thread with "millisecond" resolution */
-void
+struct thread *
funcname_thread_add_timer_msec (struct thread_master *m,
int (*func) (struct thread *), void *arg, long timer,
struct thread **t_ptr, debugargdef)
@@ -912,22 +916,22 @@ funcname_thread_add_timer_msec (struct thread_master *m,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000*(timer % 1000);
- funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel,
- t_ptr, debugargpass);
+ return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel,
+ t_ptr, debugargpass);
}
/* Add timer event thread with "millisecond" resolution */
-void
+struct thread *
funcname_thread_add_timer_tv (struct thread_master *m,
int (*func) (struct thread *), void *arg, struct timeval *tv,
struct thread **t_ptr, debugargdef)
{
- funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv, t_ptr,
- debugargpass);
+ return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv,
+ t_ptr, debugargpass);
}
/* Add a background thread, with an optional millisec delay */
-void
+struct thread *
funcname_thread_add_background (struct thread_master *m,
int (*func) (struct thread *), void *arg, long delay,
struct thread **t_ptr, debugargdef)
@@ -947,12 +951,12 @@ funcname_thread_add_background (struct thread_master *m,
trel.tv_usec = 0;
}
- funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, &trel,
- t_ptr, debugargpass);
+ return funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, &trel,
+ t_ptr, debugargpass);
}
/* Add simple event thread. */
-void
+struct thread *
funcname_thread_add_event (struct thread_master *m,
int (*func) (struct thread *), void *arg, int val,
struct thread **t_ptr, debugargdef)
@@ -966,7 +970,7 @@ funcname_thread_add_event (struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return;
+ return NULL;
}
thread = thread_get (m, THREAD_EVENT, func, arg, debugargpass);
@@ -984,6 +988,8 @@ funcname_thread_add_event (struct thread_master *m,
}
}
pthread_mutex_unlock (&m->mtx);
+
+ return thread;
}
static void