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 /pimd | |
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 'pimd')
-rw-r--r-- | pimd/pim_assert.c | 5 | ||||
-rw-r--r-- | pimd/pim_ifchannel.c | 37 | ||||
-rw-r--r-- | pimd/pim_igmp.c | 18 | ||||
-rw-r--r-- | pimd/pim_igmpv3.c | 10 | ||||
-rw-r--r-- | pimd/pim_mroute.c | 4 | ||||
-rw-r--r-- | pimd/pim_msdp.c | 20 | ||||
-rw-r--r-- | pimd/pim_msdp.h | 7 | ||||
-rw-r--r-- | pimd/pim_msdp_socket.c | 7 | ||||
-rw-r--r-- | pimd/pim_neighbor.c | 15 | ||||
-rw-r--r-- | pimd/pim_pim.c | 14 | ||||
-rw-r--r-- | pimd/pim_ssmpingd.c | 4 | ||||
-rw-r--r-- | pimd/pim_upstream.c | 25 | ||||
-rw-r--r-- | pimd/pim_zebra.c | 6 | ||||
-rw-r--r-- | pimd/pim_zlookup.c | 7 |
14 files changed, 81 insertions, 98 deletions
diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 17f5fcfe0..a11cce943 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -576,9 +576,8 @@ static void pim_assert_timer_set(struct pim_ifchannel *ch, ch->sg_str, interval, ch->interface->name); } - THREAD_TIMER_ON(master, ch->t_ifassert_timer, - on_assert_timer, - ch, interval); + thread_add_timer(master, on_assert_timer, ch, interval, + &ch->t_ifassert_timer); } static void pim_assert_timer_reset(struct pim_ifchannel *ch) diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index f4fe60960..9f9863133 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -855,9 +855,8 @@ void pim_ifchannel_join_add(struct interface *ifp, } if (holdtime != 0xFFFF) { - THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer, - on_ifjoin_expiry_timer, - ch, holdtime); + thread_add_timer(master, on_ifjoin_expiry_timer, ch, holdtime, + &ch->t_ifjoin_expiry_timer); } } @@ -907,12 +906,11 @@ void pim_ifchannel_prune(struct interface *ifp, THREAD_OFF(ch->t_ifjoin_prune_pending_timer); THREAD_OFF(ch->t_ifjoin_expiry_timer); - THREAD_TIMER_MSEC_ON(master, ch->t_ifjoin_prune_pending_timer, - on_ifjoin_prune_pending_timer, - ch, jp_override_interval_msec); - THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer, - on_ifjoin_expiry_timer, - ch, holdtime); + thread_add_timer_msec(master, on_ifjoin_prune_pending_timer, ch, + jp_override_interval_msec, + &ch->t_ifjoin_prune_pending_timer); + thread_add_timer(master, on_ifjoin_expiry_timer, ch, holdtime, + &ch->t_ifjoin_expiry_timer); pim_upstream_update_join_desired(ch->upstream); } break; @@ -932,17 +930,16 @@ void pim_ifchannel_prune(struct interface *ifp, be taken not to use "ch" afterwards since it would be deleted. */ THREAD_OFF(ch->t_ifjoin_prune_pending_timer); - THREAD_TIMER_MSEC_ON(master, ch->t_ifjoin_prune_pending_timer, - on_ifjoin_prune_pending_timer, - ch, jp_override_interval_msec); + thread_add_timer_msec(master, on_ifjoin_prune_pending_timer, ch, + jp_override_interval_msec, + &ch->t_ifjoin_prune_pending_timer); break; case PIM_IFJOIN_PRUNE: if (source_flags & PIM_ENCODE_RPT_BIT) { THREAD_OFF(ch->t_ifjoin_prune_pending_timer); - THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer, - on_ifjoin_expiry_timer, - ch, holdtime); + thread_add_timer(master, on_ifjoin_expiry_timer, ch, holdtime, + &ch->t_ifjoin_expiry_timer); } break; case PIM_IFJOIN_PRUNE_TMP: @@ -950,9 +947,8 @@ void pim_ifchannel_prune(struct interface *ifp, { ch->ifjoin_state = PIM_IFJOIN_PRUNE; THREAD_OFF(ch->t_ifjoin_expiry_timer); - THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer, - on_ifjoin_expiry_timer, - ch, holdtime); + thread_add_timer(master, on_ifjoin_expiry_timer, ch, holdtime, + &ch->t_ifjoin_expiry_timer); } break; case PIM_IFJOIN_PRUNE_PENDING_TMP: @@ -960,9 +956,8 @@ void pim_ifchannel_prune(struct interface *ifp, { ch->ifjoin_state = PIM_IFJOIN_PRUNE_PENDING; THREAD_OFF(ch->t_ifjoin_expiry_timer); - THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer, - on_ifjoin_expiry_timer, - ch, holdtime); + thread_add_timer(master, on_ifjoin_expiry_timer, ch, holdtime, + &ch->t_ifjoin_expiry_timer); } break; } diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index ee88e7d8e..af0ddef23 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -247,9 +247,9 @@ void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp) other_querier_present_interval_msec % 1000); } - THREAD_TIMER_MSEC_ON(master, igmp->t_other_querier_timer, - pim_igmp_other_querier_expire, - igmp, other_querier_present_interval_msec); + thread_add_timer_msec(master, pim_igmp_other_querier_expire, igmp, + other_querier_present_interval_msec, + &igmp->t_other_querier_timer); } void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp) @@ -551,9 +551,8 @@ void pim_igmp_general_query_on(struct igmp_sock *igmp) igmp->fd); } igmp->t_igmp_query_timer = NULL; - THREAD_TIMER_ON(master, igmp->t_igmp_query_timer, - pim_igmp_general_query, - igmp, query_interval); + thread_add_timer(master, pim_igmp_general_query, igmp, query_interval, + &igmp->t_igmp_query_timer); } void pim_igmp_general_query_off(struct igmp_sock *igmp) @@ -896,7 +895,7 @@ igmp_read_on (struct igmp_sock *igmp) igmp->fd); } igmp->t_igmp_read = NULL; - THREAD_READ_ON(master, igmp->t_igmp_read, pim_igmp_read, igmp, igmp->fd); + thread_add_read(master, pim_igmp_read, igmp, igmp->fd, &igmp->t_igmp_read); } @@ -1029,9 +1028,8 @@ void igmp_group_timer_on(struct igmp_group *group, */ zassert(group->group_filtermode_isexcl); - THREAD_TIMER_MSEC_ON(master, group->t_group_timer, - igmp_group_timer, - group, interval_msec); + thread_add_timer_msec(master, igmp_group_timer, group, interval_msec, + &group->t_group_timer); } struct igmp_group * diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 86509a20c..e0b1d3fc2 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -215,9 +215,8 @@ static void igmp_source_timer_on(struct igmp_group *group, group->group_igmp_sock->interface->name); } - THREAD_TIMER_MSEC_ON(master, source->t_source_timer, - igmp_source_timer, - source, interval_msec); + thread_add_timer_msec(master, igmp_source_timer, source, interval_msec, + &source->t_source_timer); zassert(source->t_source_timer); /* @@ -1328,9 +1327,8 @@ static void group_retransmit_timer_on(struct igmp_group *group) igmp->interface->name); } - THREAD_TIMER_MSEC_ON(master, group->t_group_query_retransmit_timer, - igmp_group_retransmit, - group, lmqi_msec); + thread_add_timer_msec(master, igmp_group_retransmit, group, lmqi_msec, + &group->t_group_query_retransmit_timer); } static long igmp_group_timer_remain_msec(struct igmp_group *group) diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index ce2f98f31..76851fa81 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -636,8 +636,8 @@ static void mroute_read_on() { zassert(!qpim_mroute_socket_reader); - THREAD_READ_ON(master, qpim_mroute_socket_reader, - mroute_read, 0, qpim_mroute_socket_fd); + thread_add_read(master, mroute_read, 0, qpim_mroute_socket_fd, + &qpim_mroute_socket_reader); } static void mroute_read_off() diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index 93141f39d..06cc24ddb 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -82,8 +82,8 @@ pim_msdp_sa_adv_timer_setup(bool start) { THREAD_OFF(msdp->sa_adv_timer); if (start) { - THREAD_TIMER_ON(msdp->master, msdp->sa_adv_timer, - pim_msdp_sa_adv_timer_cb, NULL, PIM_MSDP_SA_ADVERTISMENT_TIME); + thread_add_timer(msdp->master, pim_msdp_sa_adv_timer_cb, NULL, + PIM_MSDP_SA_ADVERTISMENT_TIME, &msdp->sa_adv_timer); } } @@ -108,8 +108,8 @@ pim_msdp_sa_state_timer_setup(struct pim_msdp_sa *sa, bool start) { THREAD_OFF(sa->sa_state_timer); if (start) { - THREAD_TIMER_ON(msdp->master, sa->sa_state_timer, - pim_msdp_sa_state_timer_cb, sa, PIM_MSDP_SA_HOLD_TIME); + thread_add_timer(msdp->master, pim_msdp_sa_state_timer_cb, sa, + PIM_MSDP_SA_HOLD_TIME, &sa->sa_state_timer); } } @@ -920,8 +920,8 @@ pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->hold_timer); if (start) { - THREAD_TIMER_ON(msdp->master, mp->hold_timer, - pim_msdp_peer_hold_timer_cb, mp, PIM_MSDP_PEER_HOLD_TIME); + thread_add_timer(msdp->master, pim_msdp_peer_hold_timer_cb, mp, + PIM_MSDP_PEER_HOLD_TIME, &mp->hold_timer); } } @@ -948,8 +948,8 @@ pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->ka_timer); if (start) { - THREAD_TIMER_ON(msdp->master, mp->ka_timer, - pim_msdp_peer_ka_timer_cb, mp, PIM_MSDP_PEER_KA_TIME); + thread_add_timer(msdp->master, pim_msdp_peer_ka_timer_cb, mp, + PIM_MSDP_PEER_KA_TIME, &mp->ka_timer); } } @@ -1013,8 +1013,8 @@ pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->cr_timer); if (start) { - THREAD_TIMER_ON(msdp->master, mp->cr_timer, - pim_msdp_peer_cr_timer_cb, mp, PIM_MSDP_PEER_CONNECT_RETRY_TIME); + thread_add_timer(msdp->master, pim_msdp_peer_cr_timer_cb, mp, + PIM_MSDP_PEER_CONNECT_RETRY_TIME, &mp->cr_timer); } } diff --git a/pimd/pim_msdp.h b/pimd/pim_msdp.h index 33c1d88a4..57a7c2244 100644 --- a/pimd/pim_msdp.h +++ b/pimd/pim_msdp.h @@ -197,8 +197,11 @@ struct pim_msdp { struct pim_msdp_mg *mg; }; -#define PIM_MSDP_PEER_READ_ON(mp) THREAD_READ_ON(msdp->master, mp->t_read, pim_msdp_read, mp, mp->fd); -#define PIM_MSDP_PEER_WRITE_ON(mp) THREAD_WRITE_ON(msdp->master, mp->t_write, pim_msdp_write, mp, mp->fd); +#define PIM_MSDP_PEER_READ_ON(mp) \ + thread_add_read (msdp->master, pim_msdp_read, mp, mp->fd, &mp->t_read) + +#define PIM_MSDP_PEER_WRITE_ON(mp) \ + thread_add_write (msdp->master, pim_msdp_write, mp, mp->fd, &mp->t_write) #define PIM_MSDP_PEER_READ_OFF(mp) THREAD_READ_OFF(mp->t_read) #define PIM_MSDP_PEER_WRITE_OFF(mp) THREAD_WRITE_OFF(mp->t_write) diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index 805e812ca..b09dd635a 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -70,8 +70,8 @@ pim_msdp_sock_accept(struct thread *thread) zlog_err ("accept_sock is negative value %d", accept_sock); return -1; } - listener->thread = thread_add_read(master, pim_msdp_sock_accept, - listener, accept_sock); + listener->thread = thread_add_read(master, pim_msdp_sock_accept, listener, + accept_sock, NULL); /* accept client connection. */ msdp_sock = sockunion_accept(accept_sock, &su); @@ -173,7 +173,8 @@ pim_msdp_sock_listen(void) /* add accept thread */ listener->fd = sock; memcpy(&listener->su, &sin, socklen); - listener->thread = thread_add_read(msdp->master, pim_msdp_sock_accept, listener, sock); + listener->thread = thread_add_read(msdp->master, pim_msdp_sock_accept, + listener, sock, NULL); msdp->flags |= PIM_MSDPF_LISTENER; return 0; diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index de0f75e38..5dccc3cfb 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -262,9 +262,8 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime) neigh->holdtime, src_str, neigh->interface->name); } - THREAD_TIMER_ON(master, neigh->t_expire_timer, - on_neighbor_timer, - neigh, neigh->holdtime); + thread_add_timer(master, on_neighbor_timer, neigh, neigh->holdtime, + &neigh->t_expire_timer); } static int @@ -286,9 +285,8 @@ on_neighbor_jp_timer (struct thread *t) rpf.rpf_addr.u.prefix4 = neigh->source_addr; pim_joinprune_send(&rpf, neigh->upstream_jp_agg); - THREAD_TIMER_ON(master, neigh->jp_timer, - on_neighbor_jp_timer, - neigh, qpim_t_periodic); + thread_add_timer(master, on_neighbor_jp_timer, neigh, qpim_t_periodic, + &neigh->jp_timer); return 0; } @@ -297,9 +295,8 @@ static void pim_neighbor_start_jp_timer (struct pim_neighbor *neigh) { THREAD_TIMER_OFF(neigh->jp_timer); - THREAD_TIMER_ON(master, neigh->jp_timer, - on_neighbor_jp_timer, - neigh, qpim_t_periodic); + thread_add_timer(master, on_neighbor_jp_timer, neigh, qpim_t_periodic, + &neigh->jp_timer); } static struct pim_neighbor *pim_neighbor_new(struct interface *ifp, diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 9886cd6ad..57b9e6c79 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -383,8 +383,8 @@ static void pim_sock_read_on(struct interface *ifp) pim_ifp->pim_sock_fd); } pim_ifp->t_pim_sock_read = NULL; - THREAD_READ_ON(master, pim_ifp->t_pim_sock_read, pim_sock_read, ifp, - pim_ifp->pim_sock_fd); + thread_add_read(master, pim_sock_read, ifp, pim_ifp->pim_sock_fd, + &pim_ifp->t_pim_sock_read); } static int pim_sock_open(struct interface *ifp) @@ -703,9 +703,8 @@ static void hello_resched(struct interface *ifp) pim_ifp->pim_hello_period, ifp->name); } THREAD_OFF(pim_ifp->t_pim_hello_timer); - THREAD_TIMER_ON(master, pim_ifp->t_pim_hello_timer, - on_pim_hello_send, - ifp, pim_ifp->pim_hello_period); + thread_add_timer(master, on_pim_hello_send, ifp, pim_ifp->pim_hello_period, + &pim_ifp->t_pim_hello_timer); } /* @@ -814,9 +813,8 @@ void pim_hello_restart_triggered(struct interface *ifp) random_msec, ifp->name); } - THREAD_TIMER_MSEC_ON(master, pim_ifp->t_pim_hello_timer, - on_pim_hello_send, - ifp, random_msec); + thread_add_timer_msec(master, on_pim_hello_send, ifp, random_msec, + &pim_ifp->t_pim_hello_timer); } int pim_sock_add(struct interface *ifp) diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index 76b327ab0..eda044f18 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -331,8 +331,8 @@ static int ssmpingd_sock_read(struct thread *t) static void ssmpingd_read_on(struct ssmpingd_sock *ss) { zassert(!ss->t_sock_read); - THREAD_READ_ON(master, ss->t_sock_read, - ssmpingd_sock_read, ss, ss->sock_fd); + thread_add_read(master, ssmpingd_sock_read, ss, ss->sock_fd, + &ss->t_sock_read); } static struct ssmpingd_sock *ssmpingd_new(struct in_addr source_addr) diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index dd6eab9cf..88b669414 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -340,9 +340,8 @@ join_timer_start(struct pim_upstream *up) else { THREAD_OFF (up->t_join_timer); - THREAD_TIMER_ON(master, up->t_join_timer, - on_join_timer, - up, qpim_t_periodic); + thread_add_timer(master, on_join_timer, up, qpim_t_periodic, + &up->t_join_timer); } pim_jp_agg_upstream_verification (up, true); } @@ -371,9 +370,8 @@ static void pim_upstream_join_timer_restart_msec(struct pim_upstream *up, } THREAD_OFF(up->t_join_timer); - THREAD_TIMER_MSEC_ON(master, up->t_join_timer, - on_join_timer, - up, interval_msec); + thread_add_timer_msec(master, on_join_timer, up, interval_msec, + &up->t_join_timer); } void pim_upstream_join_suppress(struct pim_upstream *up, @@ -1119,10 +1117,8 @@ pim_upstream_keep_alive_timer_start (struct pim_upstream *up, zlog_debug ("kat start on %s with no stream reference", up->sg_str); } THREAD_OFF (up->t_ka_timer); - THREAD_TIMER_ON (master, - up->t_ka_timer, - pim_upstream_keep_alive_timer, - up, time); + thread_add_timer(master, pim_upstream_keep_alive_timer, up, time, + &up->t_ka_timer); /* any time keepalive is started against a SG we will have to * re-evaluate our active source database */ @@ -1146,8 +1142,8 @@ void pim_upstream_msdp_reg_timer_start(struct pim_upstream *up) { THREAD_OFF(up->t_msdp_reg_timer); - THREAD_TIMER_ON(master, up->t_msdp_reg_timer, - pim_upstream_msdp_reg_timer, up, PIM_MSDP_REG_RXED_PERIOD); + thread_add_timer(master, pim_upstream_msdp_reg_timer, up, + PIM_MSDP_REG_RXED_PERIOD, &up->t_msdp_reg_timer); pim_msdp_sa_local_update(up); } @@ -1408,9 +1404,8 @@ pim_upstream_start_register_stop_timer (struct pim_upstream *up, int null_regist zlog_debug ("%s: (S,G)=%s Starting upstream register stop timer %d", __PRETTY_FUNCTION__, up->sg_str, time); } - THREAD_TIMER_ON (master, up->t_rs_timer, - pim_upstream_register_stop_timer, - up, time); + thread_add_timer(master, pim_upstream_register_stop_timer, up, time, + &up->t_rs_timer); } int diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index b2a7319bf..62be3a69d 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -617,9 +617,9 @@ void sched_rpf_cache_refresh(void) qpim_rpf_cache_refresh_delay_msec); } - THREAD_TIMER_MSEC_ON(master, qpim_rpf_cache_refresher, - on_rpf_cache_refresh, - 0, qpim_rpf_cache_refresh_delay_msec); + thread_add_timer_msec(master, on_rpf_cache_refresh, 0, + qpim_rpf_cache_refresh_delay_msec, + &qpim_rpf_cache_refresher); } static void diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index 27bd13704..01632182d 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -77,9 +77,8 @@ static void zclient_lookup_sched(struct zclient *zlookup, int delay) { zassert(!zlookup->t_connect); - THREAD_TIMER_ON(master, zlookup->t_connect, - zclient_lookup_connect, - zlookup, delay); + thread_add_timer(master, zclient_lookup_connect, zlookup, delay, + &zlookup->t_connect); zlog_notice("%s: zclient lookup connection scheduled for %d seconds", __PRETTY_FUNCTION__, delay); @@ -91,7 +90,7 @@ static void zclient_lookup_sched_now(struct zclient *zlookup) zassert(!zlookup->t_connect); zlookup->t_connect = thread_add_event(master, zclient_lookup_connect, - zlookup, 0); + zlookup, 0, NULL); zlog_notice("%s: zclient lookup immediate connection scheduled", __PRETTY_FUNCTION__); |