diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-04-25 00:33:25 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-05-09 22:44:19 +0200 |
commit | ffa2c8986d204f4a3e7204258fd6906af4a57c93 (patch) | |
tree | 6242b8634bc2a264339a05dcfb20b94f63c252f4 /zebra/zebra_ptm.c | |
parent | Merge pull request #478 from opensourcerouting/test-extension (diff) | |
download | frr-ffa2c8986d204f4a3e7204258fd6906af4a57c93.tar.xz frr-ffa2c8986d204f4a3e7204258fd6906af4a57c93.zip |
*: remove THREAD_ON macros, add nullity check
The way thread.c is written, a caller who wishes to be able to cancel a
thread or avoid scheduling it twice must keep a reference to the thread.
Typically this is done with a long lived pointer whose value is checked
for null in order to know if the thread is currently scheduled. The
check-and-schedule idiom is so common that several wrapper macros in
thread.h existed solely to provide it.
This patch removes those macros and adds a new parameter to all
thread_add_* functions which is a pointer to the struct thread * to
store the result of a scheduling call. If the value passed is non-null,
the thread will only be scheduled if the value is null. This helps with
consistency.
A Coccinelle spatch has been used to transform code of the form:
if (t == NULL)
t = thread_add_* (...)
to the form
thread_add_* (..., &t)
The THREAD_ON macros have also been transformed to the underlying
thread.c calls.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_ptm.c')
-rw-r--r-- | zebra/zebra_ptm.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index bc924842d..85f3efae8 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -182,12 +182,13 @@ zebra_ptm_flush_messages (struct thread *thread) close(ptm_cb.ptm_sock); ptm_cb.ptm_sock = -1; zebra_ptm_reset_status(0); - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return (-1); case BUFFER_PENDING: - ptm_cb.t_write = thread_add_write(zebrad.master, zebra_ptm_flush_messages, - NULL, ptm_cb.ptm_sock); + ptm_cb.t_write = thread_add_write(zebrad.master, + zebra_ptm_flush_messages, NULL, + ptm_cb.ptm_sock, NULL); break; case BUFFER_EMPTY: break; @@ -207,15 +208,15 @@ zebra_ptm_send_message(char *data, int size) close(ptm_cb.ptm_sock); ptm_cb.ptm_sock = -1; zebra_ptm_reset_status(0); - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return -1; case BUFFER_EMPTY: THREAD_OFF(ptm_cb.t_write); break; case BUFFER_PENDING: - THREAD_WRITE_ON(zebrad.master, ptm_cb.t_write, - zebra_ptm_flush_messages, NULL, ptm_cb.ptm_sock); + thread_add_write(zebrad.master, zebra_ptm_flush_messages, NULL, + ptm_cb.ptm_sock, &ptm_cb.t_write); break; } @@ -234,8 +235,8 @@ zebra_ptm_connect (struct thread *t) if (ptm_cb.ptm_sock != -1) { if (init) { - ptm_cb.t_read = thread_add_read (zebrad.master, zebra_ptm_sock_read, - NULL, ptm_cb.ptm_sock); + ptm_cb.t_read = thread_add_read(zebrad.master, zebra_ptm_sock_read, + NULL, ptm_cb.ptm_sock, NULL); zebra_bfd_peer_replay_req(); } zebra_ptm_send_status_req(); @@ -245,8 +246,8 @@ zebra_ptm_connect (struct thread *t) if (ptm_cb.reconnect_time > ZEBRA_PTM_RECONNECT_TIME_MAX) ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_MAX; - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, NULL, - ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, NULL, + ptm_cb.reconnect_time, NULL); } else if (ptm_cb.reconnect_time >= ZEBRA_PTM_RECONNECT_TIME_MAX){ ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL; } @@ -653,14 +654,14 @@ zebra_ptm_sock_read (struct thread *thread) close (ptm_cb.ptm_sock); ptm_cb.ptm_sock = -1; zebra_ptm_reset_status(0); - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return (-1); } } - ptm_cb.t_read = thread_add_read (zebrad.master, zebra_ptm_sock_read, - NULL, ptm_cb.ptm_sock); + ptm_cb.t_read = thread_add_read(zebrad.master, zebra_ptm_sock_read, NULL, + ptm_cb.ptm_sock, NULL); return 0; } @@ -697,8 +698,8 @@ zebra_ptm_bfd_dst_register (struct zserv *client, int sock, u_short length, if (ptm_cb.ptm_sock == -1) { - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return -1; } @@ -854,8 +855,8 @@ zebra_ptm_bfd_dst_deregister (struct zserv *client, int sock, u_short length, if (ptm_cb.ptm_sock == -1) { - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return -1; } @@ -976,8 +977,8 @@ zebra_ptm_bfd_client_register (struct zserv *client, int sock, u_short length) if (ptm_cb.ptm_sock == -1) { - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return -1; } @@ -1026,8 +1027,8 @@ zebra_ptm_bfd_client_deregister (int proto) if (ptm_cb.ptm_sock == -1) { - ptm_cb.t_timer = thread_add_timer (zebrad.master, zebra_ptm_connect, - NULL, ptm_cb.reconnect_time); + ptm_cb.t_timer = thread_add_timer(zebrad.master, zebra_ptm_connect, + NULL, ptm_cb.reconnect_time, NULL); return; } |