diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-04-24 22:33:25 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-05-09 20:44:19 +0000 |
| commit | ffa2c8986d204f4a3e7204258fd6906af4a57c93 (patch) | |
| tree | 6242b8634bc2a264339a05dcfb20b94f63c252f4 /lib | |
| parent | 7a78dea34d20e44539ccabb1b97e029003be4b40 (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')
| -rw-r--r-- | lib/agentx.c | 5 | ||||
| -rw-r--r-- | lib/sigevent.c | 8 | ||||
| -rw-r--r-- | lib/smux.c | 9 | ||||
| -rw-r--r-- | lib/spf_backoff.c | 16 | ||||
| -rw-r--r-- | lib/systemd.c | 4 | ||||
| -rw-r--r-- | lib/thread.c | 79 | ||||
| -rw-r--r-- | lib/thread.h | 69 | ||||
| -rw-r--r-- | lib/vty.c | 22 | ||||
| -rw-r--r-- | lib/wheel.c | 15 | ||||
| -rw-r--r-- | lib/workqueue.c | 4 | ||||
| -rw-r--r-- | lib/zclient.c | 20 |
11 files changed, 123 insertions, 128 deletions
diff --git a/lib/agentx.c b/lib/agentx.c index 11d5c9385d..f7b124f25b 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -86,7 +86,8 @@ agentx_events_update(void) snmp_select_info (&maxfd, &fds, &timeout, &block); if (!block) - timeout_thr = thread_add_timer_tv (agentx_tm, agentx_timeout, NULL, &timeout); + timeout_thr = thread_add_timer_tv(agentx_tm, agentx_timeout, NULL, + &timeout, NULL); ln = listhead (events); thr = ln ? listgetdata (ln) : NULL; @@ -114,7 +115,7 @@ agentx_events_update(void) else if (FD_ISSET (fd, &fds)) { struct listnode *newln; - thr = thread_add_read (agentx_tm, agentx_read, NULL, fd); + thr = thread_add_read(agentx_tm, agentx_read, NULL, fd, NULL); newln = listnode_add_before (events, ln, thr); thr->arg = newln; } diff --git a/lib/sigevent.c b/lib/sigevent.c index b2059a17bf..7eda2bcdde 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -132,8 +132,8 @@ quagga_signal_timer (struct thread *t) int i; sigm = THREAD_ARG (t); - sigm->t = thread_add_timer (sigm->t->master, quagga_signal_timer, &sigmaster, - QUAGGA_SIGNAL_TIMER_INTERVAL); + sigm->t = thread_add_timer(sigm->t->master, quagga_signal_timer, &sigmaster, + QUAGGA_SIGNAL_TIMER_INTERVAL, NULL); return quagga_sigevent_process (); } #endif /* SIGEVENT_SCHEDULE_THREAD */ @@ -379,7 +379,7 @@ signal_init (struct thread_master *m, int sigc, #ifdef SIGEVENT_SCHEDULE_THREAD sigmaster.t = - thread_add_timer (m, quagga_signal_timer, &sigmaster, - QUAGGA_SIGNAL_TIMER_INTERVAL); + thread_add_timer(m, quagga_signal_timer, &sigmaster, + QUAGGA_SIGNAL_TIMER_INTERVAL, NULL); #endif /* SIGEVENT_SCHEDULE_THREAD */ } diff --git a/lib/smux.c b/lib/smux.c index 370b8f138e..e0db87e4b0 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -1197,13 +1197,16 @@ smux_event (enum smux_event event, int sock) switch (event) { case SMUX_SCHEDULE: - smux_connect_thread = thread_add_event (smux_master, smux_connect, NULL, 0); + smux_connect_thread = thread_add_event(smux_master, smux_connect, NULL, + 0, NULL); break; case SMUX_CONNECT: - smux_connect_thread = thread_add_timer (smux_master, smux_connect, NULL, 10); + smux_connect_thread = thread_add_timer(smux_master, smux_connect, NULL, + 10, NULL); break; case SMUX_READ: - smux_read_thread = thread_add_read (smux_master, smux_read, NULL, sock); + smux_read_thread = thread_add_read(smux_master, smux_read, NULL, sock, + NULL); break; default: break; diff --git a/lib/spf_backoff.c b/lib/spf_backoff.c index e923f232b8..9a9af8db20 100644 --- a/lib/spf_backoff.c +++ b/lib/spf_backoff.c @@ -169,21 +169,19 @@ long spf_backoff_schedule(struct spf_backoff *backoff) { case SPF_BACKOFF_QUIET: backoff->state = SPF_BACKOFF_SHORT_WAIT; - THREAD_TIMER_MSEC_ON(backoff->m, backoff->t_timetolearn, - spf_backoff_timetolearn_elapsed, backoff, - backoff->timetolearn); - THREAD_TIMER_MSEC_ON(backoff->m, backoff->t_holddown, - spf_backoff_holddown_elapsed, backoff, - backoff->holddown); + thread_add_timer_msec(backoff->m, spf_backoff_timetolearn_elapsed, + backoff, backoff->timetolearn, + &backoff->t_timetolearn); + thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed, backoff, + backoff->holddown, &backoff->t_holddown); backoff->first_event_time = now; rv = backoff->init_delay; break; case SPF_BACKOFF_SHORT_WAIT: case SPF_BACKOFF_LONG_WAIT: THREAD_TIMER_OFF(backoff->t_holddown); - THREAD_TIMER_MSEC_ON(backoff->m, backoff->t_holddown, - spf_backoff_holddown_elapsed, backoff, - backoff->holddown); + thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed, backoff, + backoff->holddown, &backoff->t_holddown); if (backoff->state == SPF_BACKOFF_SHORT_WAIT) rv = backoff->short_delay; else diff --git a/lib/systemd.c b/lib/systemd.c index 4c78cf328c..e2329af93a 100644 --- a/lib/systemd.c +++ b/lib/systemd.c @@ -104,7 +104,7 @@ systemd_send_watchdog (struct thread *t) { systemd_send_information ("WATCHDOG=1"); - thread_add_timer (systemd_master, systemd_send_watchdog, NULL, wsecs); + thread_add_timer(systemd_master, systemd_send_watchdog, NULL, wsecs, NULL); return 1; } @@ -119,5 +119,5 @@ systemd_send_started (struct thread_master *m, int the_process) systemd_send_information ("READY=1"); if (wsecs != 0) - thread_add_timer (m, systemd_send_watchdog, m, wsecs); + thread_add_timer(m, systemd_send_watchdog, m, wsecs, NULL); } diff --git a/lib/thread.c b/lib/thread.c index 3fb28bce26..37a71824d7 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -725,6 +725,7 @@ fd_select (struct thread_master *m, int size, thread_fd_set *read, thread_fd_set num = poll (m->handler.pfds, m->handler.pfdcount + m->handler.pfdcountsnmp, timeout); #else struct timeval timeout; + if (m->selectpoll_timeout > 0) // use the user's timeout { timeout.tv_sec = m->selectpoll_timeout / 1000; @@ -776,13 +777,19 @@ fd_clear_read_write (struct thread *thread) /* Add new read thread. */ struct thread * funcname_thread_add_read_write (int dir, struct thread_master *m, - int (*func) (struct thread *), void *arg, int fd, - debugargdef) + int (*func) (struct thread *), void *arg, int fd, struct thread **t_ptr, + debugargdef) { struct thread *thread = NULL; pthread_mutex_lock (&m->mtx); { + if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule + { + pthread_mutex_unlock (&m->mtx); + return NULL; + } + #if defined (HAVE_POLL_CALL) thread = generic_thread_add(m, func, arg, fd, dir, debugargpass); #else @@ -822,6 +829,9 @@ funcname_thread_add_read_write (int dir, struct thread_master *m, } pthread_mutex_unlock (&thread->mtx); } + + if (t_ptr) + *t_ptr = thread; } pthread_mutex_unlock (&m->mtx); @@ -830,11 +840,8 @@ funcname_thread_add_read_write (int dir, struct thread_master *m, static struct thread * funcname_thread_add_timer_timeval (struct thread_master *m, - int (*func) (struct thread *), - int type, - void *arg, - struct timeval *time_relative, - debugargdef) + int (*func) (struct thread *), int type, void *arg, + struct timeval *time_relative, struct thread **t_ptr, debugargdef) { struct thread *thread; struct pqueue *queue; @@ -846,6 +853,12 @@ funcname_thread_add_timer_timeval (struct thread_master *m, pthread_mutex_lock (&m->mtx); { + if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule + { + pthread_mutex_unlock (&m->mtx); + return NULL; + } + queue = ((type == THREAD_TIMER) ? m->timer : m->background); thread = thread_get (m, type, func, arg, debugargpass); @@ -856,6 +869,9 @@ funcname_thread_add_timer_timeval (struct thread_master *m, pqueue_enqueue(thread, queue); } pthread_mutex_unlock (&thread->mtx); + + if (t_ptr) + *t_ptr = thread; } pthread_mutex_unlock (&m->mtx); @@ -866,9 +882,8 @@ funcname_thread_add_timer_timeval (struct thread_master *m, /* Add timer event thread. */ struct thread * funcname_thread_add_timer (struct thread_master *m, - int (*func) (struct thread *), - void *arg, long timer, - debugargdef) + int (*func) (struct thread *), void *arg, long timer, + struct thread **t_ptr, debugargdef) { struct timeval trel; @@ -877,16 +892,15 @@ funcname_thread_add_timer (struct thread_master *m, trel.tv_sec = timer; trel.tv_usec = 0; - return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, - &trel, debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel, + t_ptr, debugargpass); } /* Add timer event thread with "millisecond" resolution */ struct thread * funcname_thread_add_timer_msec (struct thread_master *m, - int (*func) (struct thread *), - void *arg, long timer, - debugargdef) + int (*func) (struct thread *), void *arg, long timer, + struct thread **t_ptr, debugargdef) { struct timeval trel; @@ -895,27 +909,25 @@ funcname_thread_add_timer_msec (struct thread_master *m, trel.tv_sec = timer / 1000; trel.tv_usec = 1000*(timer % 1000); - return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, - arg, &trel, debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel, + t_ptr, debugargpass); } /* Add timer event thread with "millisecond" resolution */ struct thread * funcname_thread_add_timer_tv (struct thread_master *m, - int (*func) (struct thread *), - void *arg, struct timeval *tv, - debugargdef) + int (*func) (struct thread *), void *arg, struct timeval *tv, + struct thread **t_ptr, debugargdef) { - return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, - arg, tv, 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 */ struct thread * funcname_thread_add_background (struct thread_master *m, - int (*func) (struct thread *), - void *arg, long delay, - debugargdef) + int (*func) (struct thread *), void *arg, long delay, + struct thread **t_ptr, debugargdef) { struct timeval trel; @@ -932,15 +944,15 @@ funcname_thread_add_background (struct thread_master *m, trel.tv_usec = 0; } - return funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, - arg, &trel, debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, + &trel, t_ptr, debugargpass); } /* Add simple event thread. */ struct thread * funcname_thread_add_event (struct thread_master *m, - int (*func) (struct thread *), void *arg, int val, - debugargdef) + int (*func) (struct thread *), void *arg, int val, + struct thread **t_ptr, debugargdef) { struct thread *thread; @@ -948,6 +960,12 @@ funcname_thread_add_event (struct thread_master *m, pthread_mutex_lock (&m->mtx); { + if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule + { + pthread_mutex_unlock (&m->mtx); + return NULL; + } + thread = thread_get (m, THREAD_EVENT, func, arg, debugargpass); pthread_mutex_lock (&thread->mtx); { @@ -955,6 +973,9 @@ funcname_thread_add_event (struct thread_master *m, thread_list_add (&m->event, thread); } pthread_mutex_unlock (&thread->mtx); + + if (t_ptr) + *t_ptr = thread; } pthread_mutex_unlock (&m->mtx); diff --git a/lib/thread.h b/lib/thread.h index 6fb6ad7c9d..fc345768f9 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -153,30 +153,6 @@ struct cpu_thread_history #define THREAD_FD(X) ((X)->u.fd) #define THREAD_VAL(X) ((X)->u.val) -#define THREAD_READ_ON(master,thread,func,arg,sock) \ - do { \ - if (! thread) \ - thread = thread_add_read (master, func, arg, sock); \ - } while (0) - -#define THREAD_WRITE_ON(master,thread,func,arg,sock) \ - do { \ - if (! thread) \ - thread = thread_add_write (master, func, arg, sock); \ - } while (0) - -#define THREAD_TIMER_ON(master,thread,func,arg,time) \ - do { \ - if (! thread) \ - thread = thread_add_timer (master, func, arg, time); \ - } while (0) - -#define THREAD_TIMER_MSEC_ON(master,thread,func,arg,time) \ - do { \ - if (! thread) \ - thread = thread_add_timer_msec (master, func, arg, time); \ - } while (0) - #define THREAD_OFF(thread) \ do { \ if (thread) \ @@ -192,16 +168,16 @@ struct cpu_thread_history #define debugargdef const char *funcname, const char *schedfrom, int fromln -#define thread_add_read(m,f,a,v) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_write(m,f,a,v) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer_tv(m,f,a,v) funcname_thread_add_timer_tv(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f,__FILE__,__LINE__) +#define thread_add_read(m,f,a,v,t) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_write(m,f,a,v,t) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer(m,f,a,v,t) funcname_thread_add_timer(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer_msec(m,f,a,v,t) funcname_thread_add_timer_msec(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer_tv(m,f,a,v,t) funcname_thread_add_timer_tv(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_event(m,f,a,v,t) funcname_thread_add_event(m,f,a,v,t,#f,__FILE__,__LINE__) #define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__) /* The 4th arg to thread_add_background is the # of milliseconds to delay. */ -#define thread_add_background(m,f,a,v) funcname_thread_add_background(m,f,a,v,#f,__FILE__,__LINE__) +#define thread_add_background(m,f,a,v,t) funcname_thread_add_background(m,f,a,v,t,#f,__FILE__,__LINE__) /* Prototypes. */ extern struct thread_master *thread_master_create (void); @@ -209,29 +185,26 @@ extern void thread_master_free (struct thread_master *); extern void thread_master_free_unused(struct thread_master *); extern struct thread *funcname_thread_add_read_write (int dir, struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + extern struct thread *funcname_thread_add_timer (struct thread_master *, - int (*)(struct thread *), - void *, long, debugargdef); + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + extern struct thread *funcname_thread_add_timer_msec (struct thread_master *, - int (*)(struct thread *), - void *, long, debugargdef); + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + extern struct thread *funcname_thread_add_timer_tv (struct thread_master *, - int (*)(struct thread *), - void *, struct timeval *, - debugargdef); + int (*)(struct thread *), void *, struct timeval *, struct thread **, debugargdef); + extern struct thread *funcname_thread_add_event (struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + extern struct thread *funcname_thread_add_background (struct thread_master *, - int (*func)(struct thread *), - void *arg, - long milliseconds_to_delay, - debugargdef); + int (*func)(struct thread *), void *arg, long milliseconds_to_delay, + struct thread **, debugargdef); + extern struct thread *funcname_thread_execute (struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); + int (*)(struct thread *), void *, int, debugargdef); #undef debugargdef extern void thread_cancel (struct thread *); @@ -2618,23 +2618,26 @@ vty_event (enum event event, int sock, struct vty *vty) switch (event) { case VTY_SERV: - vty_serv_thread = thread_add_read (vty_master, vty_accept, vty, sock); + vty_serv_thread = thread_add_read(vty_master, vty_accept, vty, sock, + NULL); vector_set_index (Vvty_serv_thread, sock, vty_serv_thread); break; #ifdef VTYSH case VTYSH_SERV: - vty_serv_thread = thread_add_read (vty_master, vtysh_accept, vty, sock); + vty_serv_thread = thread_add_read(vty_master, vtysh_accept, vty, sock, + NULL); vector_set_index (Vvty_serv_thread, sock, vty_serv_thread); break; case VTYSH_READ: - vty->t_read = thread_add_read (vty_master, vtysh_read, vty, sock); + vty->t_read = thread_add_read(vty_master, vtysh_read, vty, sock, NULL); break; case VTYSH_WRITE: - vty->t_write = thread_add_write (vty_master, vtysh_write, vty, sock); + vty->t_write = thread_add_write(vty_master, vtysh_write, vty, sock, + NULL); break; #endif /* VTYSH */ case VTY_READ: - vty->t_read = thread_add_read (vty_master, vty_read, vty, sock); + vty->t_read = thread_add_read(vty_master, vty_read, vty, sock, NULL); /* Time out treatment. */ if (vty->v_timeout) @@ -2642,12 +2645,12 @@ vty_event (enum event event, int sock, struct vty *vty) if (vty->t_timeout) thread_cancel (vty->t_timeout); vty->t_timeout = - thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout); + thread_add_timer(vty_master, vty_timeout, vty, vty->v_timeout, + NULL); } break; case VTY_WRITE: - if (! vty->t_write) - vty->t_write = thread_add_write (vty_master, vty_flush, vty, sock); + thread_add_write(vty_master, vty_flush, vty, sock, &vty->t_write); break; case VTY_TIMEOUT_RESET: if (vty->t_timeout) @@ -2658,7 +2661,8 @@ vty_event (enum event event, int sock, struct vty *vty) if (vty->v_timeout) { vty->t_timeout = - thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout); + thread_add_timer(vty_master, vty_timeout, vty, vty->v_timeout, + NULL); } break; } diff --git a/lib/wheel.c b/lib/wheel.c index fe53dea299..9bcb1b8743 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -60,9 +60,8 @@ wheel_timer_thread (struct thread *t) slots_to_skip++; wheel->slots_to_skip = slots_to_skip; - THREAD_TIMER_MSEC_ON (wheel->master, wheel->timer, - wheel_timer_thread, wheel, - wheel->nexttime * slots_to_skip); + thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel, + wheel->nexttime * slots_to_skip, &wheel->timer); return 0; } @@ -91,9 +90,8 @@ wheel_init (struct thread_master *master, int period, size_t slots, for (i = 0; i < slots; i++) wheel->wheel_slot_lists[i] = list_new (); - THREAD_TIMER_MSEC_ON (wheel->master, wheel->timer, - wheel_timer_thread, wheel, - wheel->nexttime); + thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel, + wheel->nexttime, &wheel->timer); return wheel; } @@ -124,9 +122,8 @@ int wheel_start (struct timer_wheel *wheel) { if (!wheel->timer) - THREAD_TIMER_MSEC_ON (wheel->master, wheel->timer, - wheel_timer_thread, wheel, - wheel->nexttime); + thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel, + wheel->nexttime, &wheel->timer); return 0; } diff --git a/lib/workqueue.c b/lib/workqueue.c index 51017b34ea..3d481aa899 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -126,8 +126,8 @@ work_queue_schedule (struct work_queue *wq, unsigned int delay) && (wq->thread == NULL) && (listcount (wq->items) > 0) ) { - wq->thread = thread_add_background (wq->master, work_queue_run, - wq, delay); + wq->thread = thread_add_background(wq->master, work_queue_run, wq, + delay, NULL); /* set thread yield time, if needed */ if (wq->thread && wq->spec.yield != THREAD_YIELD_TIME_SLOT) thread_set_yield_time (wq->thread, wq->spec.yield); 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; } } |
