summaryrefslogtreecommitdiff
path: root/lib/zclient.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 /lib/zclient.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 'lib/zclient.c')
-rw-r--r--lib/zclient.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/zclient.c b/lib/zclient.c
index e3eadf22a4..60e35c66fa 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -311,7 +311,7 @@ zclient_flush_data(struct thread *thread)
break;
case BUFFER_PENDING:
zclient->t_write = thread_add_write(zclient->master, zclient_flush_data,
- zclient, zclient->sock);
+ zclient, zclient->sock, NULL);
break;
case BUFFER_EMPTY:
break;
@@ -336,8 +336,8 @@ zclient_send_message(struct zclient *zclient)
THREAD_OFF(zclient->t_write);
break;
case BUFFER_PENDING:
- THREAD_WRITE_ON(zclient->master, zclient->t_write,
- zclient_flush_data, zclient, zclient->sock);
+ thread_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
break;
}
return 0;
@@ -2012,22 +2012,20 @@ zclient_event (enum event event, struct zclient *zclient)
switch (event)
{
case ZCLIENT_SCHEDULE:
- if (! zclient->t_connect)
- zclient->t_connect =
- thread_add_event (zclient->master, zclient_connect, zclient, 0);
+ thread_add_event(zclient->master, zclient_connect, zclient, 0,
+ &zclient->t_connect);
break;
case ZCLIENT_CONNECT:
if (zclient_debug)
zlog_debug ("zclient connect failures: %d schedule interval is now %d",
zclient->fail, zclient->fail < 3 ? 10 : 60);
- if (! zclient->t_connect)
- zclient->t_connect =
- thread_add_timer (zclient->master, zclient_connect, zclient,
- zclient->fail < 3 ? 10 : 60);
+ thread_add_timer(zclient->master, zclient_connect, zclient,
+ zclient->fail < 3 ? 10 : 60, &zclient->t_connect);
break;
case ZCLIENT_READ:
zclient->t_read =
- thread_add_read (zclient->master, zclient_read, zclient, zclient->sock);
+ thread_add_read(zclient->master, zclient_read, zclient, zclient->sock,
+ NULL);
break;
}
}