summaryrefslogtreecommitdiff
path: root/nhrpd/nhrp_event.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-04-24 22:33:25 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-05-09 20:44:19 +0000
commitffa2c8986d204f4a3e7204258fd6906af4a57c93 (patch)
tree6242b8634bc2a264339a05dcfb20b94f63c252f4 /nhrpd/nhrp_event.c
parent7a78dea34d20e44539ccabb1b97e029003be4b40 (diff)
*: 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 'nhrpd/nhrp_event.c')
-rw-r--r--nhrpd/nhrp_event.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/nhrpd/nhrp_event.c b/nhrpd/nhrp_event.c
index aab9ec642f..da86c585a4 100644
--- a/nhrpd/nhrp_event.c
+++ b/nhrpd/nhrp_event.c
@@ -40,8 +40,8 @@ static void evmgr_connection_error(struct event_manager *evmgr)
close(evmgr->fd);
evmgr->fd = -1;
if (nhrp_event_socket_path)
- THREAD_TIMER_MSEC_ON(master, evmgr->t_reconnect, evmgr_reconnect,
- evmgr, 10);
+ thread_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
}
static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb)
@@ -85,7 +85,7 @@ static int evmgr_read(struct thread *t)
while (zbuf_may_pull_until(ibuf, "\n\n", &msg))
evmgr_recv_message(evmgr, &msg);
- THREAD_READ_ON(master, evmgr->t_read, evmgr_read, evmgr, evmgr->fd);
+ thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
return 0;
}
@@ -97,7 +97,8 @@ static int evmgr_write(struct thread *t)
evmgr->t_write = NULL;
r = zbufq_write(&evmgr->obuf, evmgr->fd);
if (r > 0) {
- THREAD_WRITE_ON(master, evmgr->t_write, evmgr_write, evmgr, evmgr->fd);
+ thread_add_write(master, evmgr_write, evmgr, evmgr->fd,
+ &evmgr->t_write);
} else if (r < 0) {
evmgr_connection_error(evmgr);
}
@@ -170,7 +171,8 @@ static void evmgr_submit(struct event_manager *evmgr, struct zbuf *obuf)
zbuf_put(obuf, "\n", 1);
zbufq_queue(&evmgr->obuf, obuf);
if (evmgr->fd >= 0)
- THREAD_WRITE_ON(master, evmgr->t_write, evmgr_write, evmgr, evmgr->fd);
+ thread_add_write(master, evmgr_write, evmgr, evmgr->fd,
+ &evmgr->t_write);
}
static int evmgr_reconnect(struct thread *t)
@@ -186,13 +188,14 @@ static int evmgr_reconnect(struct thread *t)
zlog_warn("%s: failure connecting nhrp-event socket: %s",
__PRETTY_FUNCTION__, strerror(errno));
zbufq_reset(&evmgr->obuf);
- THREAD_TIMER_ON(master, evmgr->t_reconnect, evmgr_reconnect, evmgr, 10);
+ thread_add_timer(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
return 0;
}
zlog_info("Connected to Event Manager");
evmgr->fd = fd;
- THREAD_READ_ON(master, evmgr->t_read, evmgr_read, evmgr, evmgr->fd);
+ thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
return 0;
}
@@ -206,7 +209,8 @@ void evmgr_init(void)
evmgr->fd = -1;
zbuf_init(&evmgr->ibuf, evmgr->ibuf_data, sizeof(evmgr->ibuf_data), 0);
zbufq_init(&evmgr->obuf);
- THREAD_TIMER_MSEC_ON(master, evmgr->t_reconnect, evmgr_reconnect, evmgr, 10);
+ thread_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
}
void evmgr_set_socket(const char *socket)