summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-10-06 22:06:23 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2021-10-20 20:07:15 +0300
commitee1455dd983e2b19018890c2da5e22bb97b3adb7 (patch)
tree2ad4cece5e23cd14e95073f5d35549d61b3e0b8b /lib/thread.c
parent5db95752c063a46a6ee8cdf5e65d45c68a8de77f (diff)
lib: change thread_add_* API
Do not return pointer to the newly created thread from various thread_add functions. This should prevent developers from storing a thread pointer into some variable without letting the lib know that the pointer is stored. When the lib doesn't know that the pointer is stored, it doesn't prevent rescheduling and it can lead to hard to find bugs. If someone wants to store the pointer, they should pass a double pointer as the last argument. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 71d7798af5..5dbba6363d 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -922,10 +922,10 @@ done:
}
/* Add new read thread. */
-struct thread *_thread_add_read_write(const struct xref_threadsched *xref,
- struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, int fd, struct thread **t_ptr)
+void _thread_add_read_write(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *), void *arg, int fd,
+ struct thread **t_ptr)
{
int dir = xref->thread_type;
struct thread *thread = NULL;
@@ -1000,15 +1000,13 @@ struct thread *_thread_add_read_write(const struct xref_threadsched *xref,
AWAKEN(m);
}
-
- return thread;
}
-static struct thread *
-_thread_add_timer_timeval(const struct xref_threadsched *xref,
- struct thread_master *m, int (*func)(struct thread *),
- void *arg, struct timeval *time_relative,
- struct thread **t_ptr)
+static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *), void *arg,
+ struct timeval *time_relative,
+ struct thread **t_ptr)
{
struct thread *thread;
struct timeval t;
@@ -1028,7 +1026,7 @@ _thread_add_timer_timeval(const struct xref_threadsched *xref,
frr_with_mutex(&m->mtx) {
if (t_ptr && *t_ptr)
/* thread is already scheduled; don't reschedule */
- return NULL;
+ return;
thread = thread_get(m, THREAD_TIMER, func, arg, xref);
@@ -1048,16 +1046,13 @@ _thread_add_timer_timeval(const struct xref_threadsched *xref,
if (thread_timer_list_first(&m->timer) == thread)
AWAKEN(m);
}
-
- return thread;
}
/* Add timer event thread. */
-struct thread *_thread_add_timer(const struct xref_threadsched *xref,
- struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, long timer, struct thread **t_ptr)
+void _thread_add_timer(const struct xref_threadsched *xref,
+ struct thread_master *m, int (*func)(struct thread *),
+ void *arg, long timer, struct thread **t_ptr)
{
struct timeval trel;
@@ -1066,15 +1061,14 @@ struct thread *_thread_add_timer(const struct xref_threadsched *xref,
trel.tv_sec = timer;
trel.tv_usec = 0;
- return _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "millisecond" resolution */
-struct thread *_thread_add_timer_msec(const struct xref_threadsched *xref,
- struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, long timer,
- struct thread **t_ptr)
+void _thread_add_timer_msec(const struct xref_threadsched *xref,
+ struct thread_master *m,
+ int (*func)(struct thread *), void *arg, long timer,
+ struct thread **t_ptr)
{
struct timeval trel;
@@ -1083,24 +1077,21 @@ struct thread *_thread_add_timer_msec(const struct xref_threadsched *xref,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000 * (timer % 1000);
- return _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "timeval" resolution */
-struct thread *_thread_add_timer_tv(const struct xref_threadsched *xref,
- struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, struct timeval *tv,
- struct thread **t_ptr)
+void _thread_add_timer_tv(const struct xref_threadsched *xref,
+ struct thread_master *m, int (*func)(struct thread *),
+ void *arg, struct timeval *tv, struct thread **t_ptr)
{
- return _thread_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
+ _thread_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
}
/* Add simple event thread. */
-struct thread *_thread_add_event(const struct xref_threadsched *xref,
- struct thread_master *m,
- int (*func)(struct thread *),
- void *arg, int val, struct thread **t_ptr)
+void _thread_add_event(const struct xref_threadsched *xref,
+ struct thread_master *m, int (*func)(struct thread *),
+ void *arg, int val, struct thread **t_ptr)
{
struct thread *thread = NULL;
@@ -1128,8 +1119,6 @@ struct thread *_thread_add_event(const struct xref_threadsched *xref,
AWAKEN(m);
}
-
- return thread;
}
/* Thread cancellation ------------------------------------------------------ */