]> git.proxmox.com Git - mirror_frr.git/commitdiff
* : update signature of thread_cancel api
authorMark Stapp <mjs@voltanet.io>
Mon, 6 Jul 2020 16:55:03 +0000 (12:55 -0400)
committerMark Stapp <mjs@voltanet.io>
Fri, 23 Oct 2020 12:59:34 +0000 (08:59 -0400)
Change thread_cancel to take a ** to an event, NULL-check
before dereferencing, and NULL the caller's pointer. Update
many callers to use the new signature.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
38 files changed:
babeld/babeld.c
bfdd/control.c
bgpd/bgp_damp.c
bgpd/bgp_dump.c
bgpd/bgp_evpn_mh.c
bgpd/rfapi/rfapi_import.c
bgpd/rfapi/rfapi_monitor.c
bgpd/rfapi/rfapi_rib.c
bgpd/rfapi/vnc_export_bgp.c
eigrpd/eigrp_filter.c
eigrpd/eigrp_interface.c
isisd/fabricd.c
isisd/isis_pdu.c
isisd/isis_tx_queue.c
lib/agentx.c
lib/frr_zmq.c
lib/thread.c
lib/thread.h
lib/workqueue.c
ospfd/ospf_apiserver.c
ospfd/ospf_ism.h
ospfd/ospf_nsm.h
ospfd/ospf_packet.c
ospfd/ospfd.c
ospfd/ospfd.h
ripd/rip_interface.c
ripd/rip_peer.c
ripngd/ripng_interface.c
ripngd/ripng_peer.c
ripngd/ripngd.c
ripngd/ripngd.h
tests/lib/test_timer_correctness.c
tests/lib/test_timer_performance.c
watchfrr/watchfrr.c
zebra/irdp_main.c
zebra/zebra_netns_notify.c
zebra/zebra_ptm.c
zebra/zebra_routemap.c

index 09955cfbef28e4ec3f690b3293db1e7998b293c8..895ede704044727f771c4d9291ada33e11a45828 100644 (file)
@@ -317,13 +317,9 @@ babel_clean_routing_process(void)
     flush_all_routes();
     babel_interface_close_all();
 
-    /* cancel threads */
-    if (babel_routing_process->t_read != NULL) {
-        thread_cancel(babel_routing_process->t_read);
-    }
-    if (babel_routing_process->t_update != NULL) {
-        thread_cancel(babel_routing_process->t_update);
-    }
+    /* cancel events */
+    thread_cancel(&babel_routing_process->t_read);
+    thread_cancel(&babel_routing_process->t_update);
 
     distribute_list_delete(&babel_routing_process->distribute_ctx);
     XFREE(MTYPE_BABEL, babel_routing_process);
@@ -503,9 +499,7 @@ static void
 babel_set_timer(struct timeval *timeout)
 {
     long msecs = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
-    if (babel_routing_process->t_update != NULL) {
-        thread_cancel(babel_routing_process->t_update);
-    }
+    thread_cancel(&(babel_routing_process->t_update));
     thread_add_timer_msec(master, babel_main_loop, NULL, msecs, &babel_routing_process->t_update);
 }
 
index 3b954c64f823b0b35c9316e47891702384cc36a9..4929bf1998478456d28a36f1f45e7986ad4c129a 100644 (file)
@@ -145,10 +145,7 @@ void control_shutdown(void)
 {
        struct bfd_control_socket *bcs;
 
-       if (bglobal.bg_csockev) {
-               thread_cancel(bglobal.bg_csockev);
-               bglobal.bg_csockev = NULL;
-       }
+       thread_cancel(&bglobal.bg_csockev);
 
        socket_close(&bglobal.bg_csock);
 
@@ -204,15 +201,8 @@ static void control_free(struct bfd_control_socket *bcs)
        struct bfd_control_queue *bcq;
        struct bfd_notify_peer *bnp;
 
-       if (bcs->bcs_ev) {
-               thread_cancel(bcs->bcs_ev);
-               bcs->bcs_ev = NULL;
-       }
-
-       if (bcs->bcs_outev) {
-               thread_cancel(bcs->bcs_outev);
-               bcs->bcs_outev = NULL;
-       }
+       thread_cancel(&(bcs->bcs_ev));
+       thread_cancel(&(bcs->bcs_outev));
 
        close(bcs->bcs_sd);
 
@@ -318,10 +308,7 @@ static int control_queue_dequeue(struct bfd_control_socket *bcs)
        return 1;
 
 empty_list:
-       if (bcs->bcs_outev) {
-               thread_cancel(bcs->bcs_outev);
-               bcs->bcs_outev = NULL;
-       }
+       thread_cancel(&(bcs->bcs_outev));
        bcs->bcs_bout = NULL;
        return 0;
 }
index 999216818224c19ec70c9539370128c734e90271..94a27ead0e454ce6e296e66e1f3b51bf48bb0487 100644 (file)
@@ -467,10 +467,8 @@ int bgp_damp_disable(struct bgp *bgp, afi_t afi, safi_t safi)
        if (!CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
                return 0;
 
-       /* Cancel reuse thread. */
-       if (bdc->t_reuse)
-               thread_cancel(bdc->t_reuse);
-       bdc->t_reuse = NULL;
+       /* Cancel reuse event. */
+       thread_cancel(&(bdc->t_reuse));
 
        /* Clean BGP dampening information.  */
        bgp_damp_info_clean(afi, safi);
index abd349a18880a4c3fe016a46312f845411da55c1..975bba93147b7d2b21918240523423fad964aa7e 100644 (file)
@@ -677,11 +677,8 @@ static int bgp_dump_unset(struct bgp_dump *bgp_dump)
                bgp_dump->fp = NULL;
        }
 
-       /* Removing interval thread. */
-       if (bgp_dump->t_interval) {
-               thread_cancel(bgp_dump->t_interval);
-               bgp_dump->t_interval = NULL;
-       }
+       /* Removing interval event. */
+       thread_cancel(&bgp_dump->t_interval);
 
        bgp_dump->interval = 0;
 
index 1a58541a71e3690afe00838cb7df09d9d692ebf8..8f81278dee01398707d772795cde0194297c6583 100644 (file)
@@ -2911,7 +2911,7 @@ void bgp_evpn_mh_finish(void)
                         es_next) {
                bgp_evpn_es_local_info_clear(es);
        }
-       thread_cancel(bgp_mh_info->t_cons_check);
+       thread_cancel(&bgp_mh_info->t_cons_check);
        list_delete(&bgp_mh_info->local_es_list);
        list_delete(&bgp_mh_info->pend_es_list);
 
index 68d4f622ed4e939d62e5f9734fe8d1432b2e1ad6..e3581addee13909e146b04e0e72c68d021d4643a 100644 (file)
@@ -858,9 +858,9 @@ static void rfapiBgpInfoChainFree(struct bgp_path_info *bpi)
                if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
                    && bpi->extra->vnc.import.timer) {
 
-                       struct thread *t =
-                               (struct thread *)bpi->extra->vnc.import.timer;
-                       struct rfapi_withdraw *wcb = t->arg;
+                       struct thread **t =
+                               &(bpi->extra->vnc.import.timer);
+                       struct rfapi_withdraw *wcb = (*t)->arg;
 
                        XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
                        thread_cancel(t);
@@ -3093,10 +3093,9 @@ static void rfapiBgpInfoFilteredImportEncap(
                                if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
                                    && bpi->extra->vnc.import.timer) {
 
-                                       struct thread *t =
-                                               (struct thread *)bpi->extra->vnc
-                                                       .import.timer;
-                                       struct rfapi_withdraw *wcb = t->arg;
+                                       struct thread **t =
+                                               &(bpi->extra->vnc.import.timer);
+                                       struct rfapi_withdraw *wcb = (*t)->arg;
 
                                        XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
                                        thread_cancel(t);
@@ -3186,9 +3185,9 @@ static void rfapiBgpInfoFilteredImportEncap(
                        "%s: removing holddown bpi matching NVE of new route",
                        __func__);
                if (bpi->extra->vnc.import.timer) {
-                       struct thread *t =
-                               (struct thread *)bpi->extra->vnc.import.timer;
-                       struct rfapi_withdraw *wcb = t->arg;
+                       struct thread **t =
+                               &(bpi->extra->vnc.import.timer);
+                       struct rfapi_withdraw *wcb = (*t)->arg;
 
                        XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
                        thread_cancel(t);
@@ -3549,10 +3548,9 @@ void rfapiBgpInfoFilteredImportVPN(
                                if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
                                    && bpi->extra->vnc.import.timer) {
 
-                                       struct thread *t =
-                                               (struct thread *)bpi->extra->vnc
-                                                       .import.timer;
-                                       struct rfapi_withdraw *wcb = t->arg;
+                                       struct thread **t =
+                                               &(bpi->extra->vnc.import.timer);
+                                       struct rfapi_withdraw *wcb = (*t)->arg;
 
                                        XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
                                        thread_cancel(t);
@@ -3768,9 +3766,9 @@ void rfapiBgpInfoFilteredImportVPN(
                        "%s: removing holddown bpi matching NVE of new route",
                        __func__);
                if (bpi->extra->vnc.import.timer) {
-                       struct thread *t =
-                               (struct thread *)bpi->extra->vnc.import.timer;
-                       struct rfapi_withdraw *wcb = t->arg;
+                       struct thread **t =
+                               &(bpi->extra->vnc.import.timer);
+                       struct rfapi_withdraw *wcb = (*t)->arg;
 
                        XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
                        thread_cancel(t);
@@ -4498,12 +4496,11 @@ static void rfapiDeleteRemotePrefixesIt(
                                                continue;
                                        if (bpi->extra->vnc.import.timer) {
 
-                                               struct thread *t =
-                                                       (struct thread *)bpi
-                                                               ->extra->vnc
-                                                               .import.timer;
+                                               struct thread **t =
+                                                       &(bpi->extra->vnc
+                                                               .import.timer);
                                                struct rfapi_withdraw *wcb =
-                                                       t->arg;
+                                                       (*t)->arg;
 
                                                wcb->import_table
                                                        ->holddown_count[afi] -=
index a4b0eff03ed3cc2b7ac69c4a9afee3ddc87f2b73..ce916c104b3b7c1f90be7a6eef74c851a0655ec5 100644 (file)
@@ -620,10 +620,7 @@ void rfapiMonitorDel(struct bgp *bgp, struct rfapi_descriptor *rfd,
                rfapiMonitorDetachImport(m);
        }
 
-       if (m->timer) {
-               thread_cancel(m->timer);
-               m->timer = NULL;
-       }
+       thread_cancel(&m->timer);
 
        /*
         * remove from rfd list
@@ -660,10 +657,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd)
                                        rfapiMonitorDetachImport(m);
                                }
 
-                               if (m->timer) {
-                                       thread_cancel(m->timer);
-                                       m->timer = NULL;
-                               }
+                               thread_cancel(&m->timer);
 
                                XFREE(MTYPE_RFAPI_MONITOR, m);
                                rn->info = NULL;
@@ -697,10 +691,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd)
 #endif
                        }
 
-                       if (mon_eth->timer) {
-                               thread_cancel(mon_eth->timer);
-                               mon_eth->timer = NULL;
-                       }
+                       thread_cancel(&mon_eth->timer);
 
                        /*
                         * remove from rfd list
@@ -766,8 +757,7 @@ static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m)
                if (m->rfd->response_lifetime - remain < 2)
                        return;
 
-               thread_cancel(m->timer);
-               m->timer = NULL;
+               thread_cancel(&m->timer);
        }
 
        {
@@ -1078,8 +1068,7 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m)
                if (m->rfd->response_lifetime - remain < 2)
                        return;
 
-               thread_cancel(m->timer);
-               m->timer = NULL;
+               thread_cancel(&m->timer);
        }
 
        {
@@ -1418,10 +1407,7 @@ void rfapiMonitorEthDel(struct bgp *bgp, struct rfapi_descriptor *rfd,
                rfapiMonitorEthDetachImport(bgp, val);
        }
 
-       if (val->timer) {
-               thread_cancel(val->timer);
-               val->timer = NULL;
-       }
+       thread_cancel(&val->timer);
 
        /*
         * remove from rfd list
index 09832b32ac1c142938347e5f82ac530e6a44e9e5..630a379ec2163e1a5f8af12faca97867fbb0bc36 100644 (file)
@@ -269,9 +269,8 @@ static void rfapi_info_free(struct rfapi_info *goner)
                        struct rfapi_rib_tcb *tcb;
 
                        tcb = goner->timer->arg;
-                       thread_cancel(goner->timer);
+                       thread_cancel(&goner->timer);
                        XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
-                       goner->timer = NULL;
                }
                XFREE(MTYPE_RFAPI_INFO, goner);
        }
@@ -338,13 +337,11 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd,
                               struct agg_node *rn, /* route node attached to */
                               int deleted)
 {
-       struct thread *t = ri->timer;
        struct rfapi_rib_tcb *tcb = NULL;
 
-       if (t) {
-               tcb = t->arg;
-               thread_cancel(t);
-               ri->timer = NULL;
+       if (ri->timer) {
+               tcb = ri->timer->arg;
+               thread_cancel(&ri->timer);
        } else {
                tcb = XCALLOC(MTYPE_RFAPI_RECENT_DELETE,
                              sizeof(struct rfapi_rib_tcb));
@@ -917,10 +914,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
                                if (ri->timer) {
                                        struct rfapi_rib_tcb *tcb;
 
-                                       tcb = ((struct thread *)ri->timer)->arg;
-                                       thread_cancel(ri->timer);
+                                       tcb = ri->timer->arg;
+                                       thread_cancel(&ri->timer);
                                        XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
-                                       ri->timer = NULL;
                                }
 
                                vnc_zlog_debug_verbose(
@@ -1003,11 +999,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
                                if (ori->timer) {
                                        struct rfapi_rib_tcb *tcb;
 
-                                       tcb = ((struct thread *)ori->timer)
-                                                     ->arg;
-                                       thread_cancel(ori->timer);
+                                       tcb = ori->timer->arg;
+                                       thread_cancel(&ori->timer);
                                        XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
-                                       ori->timer = NULL;
                                }
 
 #if DEBUG_PROCESS_PENDING_NODE
@@ -1351,11 +1345,9 @@ callback:
                                if (ri->timer) {
                                        struct rfapi_rib_tcb *tcb;
 
-                                       tcb = ((struct thread *)ri->timer)->arg;
-                                       thread_cancel(
-                                               (struct thread *)ri->timer);
+                                       tcb = ri->timer->arg;
+                                       thread_cancel(&ri->timer);
                                        XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
-                                       ri->timer = NULL;
                                }
                                RFAPI_RIB_CHECK_COUNTS(0, delete_list->count);
 
index b56261669c347f1853b6fd63339d9d96f9ecccc0..11f39b2b82a379ce94cf70af4350d780a0282006 100644 (file)
@@ -1711,14 +1711,11 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi,
        rfapiGetVncLifetime(attr, &eti->lifetime);
        eti->lifetime = rfapiGetHolddownFromLifetime(eti->lifetime);
 
-       if (eti->timer) {
-               /*
-                * export expiration timer is already running on
-                * this route: cancel it
-                */
-               thread_cancel(eti->timer);
-               eti->timer = NULL;
-       }
+       /*
+        * export expiration timer is already running on
+        * this route: cancel it
+        */
+       thread_cancel(&eti->timer);
 
        bgp_update(peer, prefix, /* prefix */
                   0,            /* addpath_id */
@@ -1947,15 +1944,12 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi)
                                        rfapiGetVncLifetime(ri->attr,
                                                            &eti->lifetime);
 
-                                       if (eti->timer) {
-                                               /*
-                                                * export expiration timer is
-                                                * already running on
-                                                * this route: cancel it
-                                                */
-                                               thread_cancel(eti->timer);
-                                               eti->timer = NULL;
-                                       }
+                                       /*
+                                        * export expiration timer is
+                                        * already running on
+                                        * this route: cancel it
+                                        */
+                                       thread_cancel(&eti->timer);
 
                                        vnc_zlog_debug_verbose(
                                                "%s: calling bgp_update",
@@ -2024,8 +2018,7 @@ void vnc_direct_bgp_rh_vpn_disable(struct bgp *bgp, afi_t afi)
                                        ZEBRA_ROUTE_VNC_DIRECT_RH,
                                        BGP_ROUTE_REDISTRIBUTE);
                                if (eti) {
-                                       if (eti->timer)
-                                               thread_cancel(eti->timer);
+                                       thread_cancel(&eti->timer);
                                        vnc_eti_delete(eti);
                                }
 
index 9d5d45ca50f044582119b713ce67d04c5958b1d1..010fd2d3abbb97689669703e04f178294044322f 100644 (file)
@@ -159,13 +159,10 @@ void eigrp_distribute_update(struct distribute_ctx *ctx,
 #endif
                // TODO: check Graceful restart after 10sec
 
-               /* check if there is already GR scheduled */
-               if (e->t_distribute != NULL) {
-                       /* if is, cancel schedule */
-                       thread_cancel(e->t_distribute);
-               }
+               /* cancel GR scheduled */
+               thread_cancel(&(e->t_distribute));
+
                /* schedule Graceful restart for whole process in 10sec */
-               e->t_distribute = NULL;
                thread_add_timer(master, eigrp_distribute_timer_process, e,
                                 (10), &e->t_distribute);
 
@@ -267,11 +264,8 @@ void eigrp_distribute_update(struct distribute_ctx *ctx,
 #endif
        // TODO: check Graceful restart after 10sec
 
-       /* check if there is already GR scheduled */
-       if (ei->t_distribute != NULL) {
-               /* if is, cancel schedule */
-               thread_cancel(ei->t_distribute);
-       }
+       /* Cancel GR scheduled */
+       thread_cancel(&(ei->t_distribute));
        /* schedule Graceful restart for interface in 10sec */
        e->t_distribute = NULL;
        thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10,
index 2f3f3474236747fe5447046fdd89341dac2403d6..e7c6b2e07217236b0d34d4d70629ebd2f1661654 100644 (file)
@@ -358,7 +358,7 @@ void eigrp_if_stream_unset(struct eigrp_interface *ei)
        if (ei->on_write_q) {
                listnode_delete(eigrp->oi_write_q, ei);
                if (list_isempty(eigrp->oi_write_q))
-                       thread_cancel(eigrp->t_write);
+                       thread_cancel(&(eigrp->t_write));
                ei->on_write_q = 0;
        }
 }
index 1a081bbea669e4a8526b472b977af6d3c2e802cb..57e9e91c1510c1fa8eb44299ae3dbea9db22e346 100644 (file)
@@ -239,14 +239,11 @@ struct fabricd *fabricd_new(struct isis_area *area)
 
 void fabricd_finish(struct fabricd *f)
 {
-       if (f->initial_sync_timeout)
-               thread_cancel(f->initial_sync_timeout);
+       thread_cancel(&(f->initial_sync_timeout));
 
-       if (f->tier_calculation_timer)
-               thread_cancel(f->tier_calculation_timer);
+       thread_cancel(&(f->tier_calculation_timer));
 
-       if (f->tier_set_timer)
-               thread_cancel(f->tier_set_timer);
+       thread_cancel(&(f->tier_set_timer));
 
        isis_spftree_del(f->spftree);
        neighbor_lists_clear(f);
@@ -340,8 +337,7 @@ void fabricd_initial_sync_finish(struct isis_area *area)
                  f->initial_sync_circuit->interface->name);
        f->initial_sync_state = FABRICD_SYNC_COMPLETE;
        f->initial_sync_circuit = NULL;
-       thread_cancel(f->initial_sync_timeout);
-       f->initial_sync_timeout = NULL;
+       thread_cancel(&(f->initial_sync_timeout));
 }
 
 static void fabricd_bump_tier_calculation_timer(struct fabricd *f);
@@ -437,22 +433,15 @@ static int fabricd_tier_calculation_cb(struct thread *thread)
 static void fabricd_bump_tier_calculation_timer(struct fabricd *f)
 {
        /* Cancel timer if we already know our tier */
-       if (f->tier != ISIS_TIER_UNDEFINED
-           || f->tier_set_timer) {
-               if (f->tier_calculation_timer) {
-                       thread_cancel(f->tier_calculation_timer);
-                       f->tier_calculation_timer = NULL;
-               }
+       if (f->tier != ISIS_TIER_UNDEFINED || f->tier_set_timer) {
+               thread_cancel(&(f->tier_calculation_timer));
                return;
        }
 
        /* If we need to calculate the tier, wait some
         * time for the topology to settle before running
         * the calculation */
-       if (f->tier_calculation_timer) {
-               thread_cancel(f->tier_calculation_timer);
-               f->tier_calculation_timer = NULL;
-       }
+       thread_cancel(&(f->tier_calculation_timer));
 
        thread_add_timer(master, fabricd_tier_calculation_cb, f,
                         2 * f->area->lsp_gen_interval[ISIS_LEVEL2 - 1],
@@ -737,7 +726,7 @@ void fabricd_trigger_csnp(struct isis_area *area, bool circuit_scoped)
                if (!circuit->t_send_csnp[1])
                        continue;
 
-               thread_cancel(circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
+               thread_cancel(&(circuit->t_send_csnp[ISIS_LEVEL2 - 1]));
                thread_add_timer_msec(master, send_l2_csnp, circuit,
                                      isis_jitter(f->csnp_delay, CSNP_JITTER),
                                      &circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
index d6f2571178ba80d4328cfcd1e66c99f02b74d42b..63be8841c3949f3954b0815a65f231cc7e45fc73 100644 (file)
@@ -1987,7 +1987,7 @@ static void _send_hello_sched(struct isis_circuit *circuit,
                if (thread_timer_remain_msec(*threadp) < (unsigned long)delay)
                        return;
 
-               thread_cancel(*threadp);
+               thread_cancel(threadp);
        }
 
        thread_add_timer_msec(master, send_hello_cb,
index 1424b55bdce4580f88a356f2e912504173de4121..5c87e39157df4df8dc613b1a236ff7fb30260393 100644 (file)
@@ -93,8 +93,7 @@ static void tx_queue_element_free(void *element)
 {
        struct isis_tx_queue_entry *e = element;
 
-       if (e->retry)
-               thread_cancel(e->retry);
+       thread_cancel(&(e->retry));
 
        XFREE(MTYPE_TX_QUEUE_ENTRY, e);
 }
@@ -166,8 +165,7 @@ void _isis_tx_queue_add(struct isis_tx_queue *queue,
 
        e->type = type;
 
-       if (e->retry)
-               thread_cancel(e->retry);
+       thread_cancel(&(e->retry));
        thread_add_event(master, tx_queue_send_event, e, 0, &e->retry);
 
        e->is_retry = false;
@@ -190,8 +188,7 @@ void _isis_tx_queue_del(struct isis_tx_queue *queue, struct isis_lsp *lsp,
                           func, file, line);
        }
 
-       if (e->retry)
-               thread_cancel(e->retry);
+       thread_cancel(&(e->retry));
 
        hash_release(queue->hash, e);
        XFREE(MTYPE_TX_QUEUE_ENTRY, e);
index 7c4bdcbe27d02f565c9390b975d56831ce012d34..07f146bae4fc8a6f93ac2429343b5ce22ed83b6b 100644 (file)
@@ -130,7 +130,7 @@ static void agentx_events_update(void)
                if (thr_fd == fd) {
                        struct listnode *nextln = listnextnode(ln);
                        if (!FD_ISSET(fd, &fds)) {
-                               thread_cancel(thr);
+                               thread_cancel(&thr);
                                list_delete_node(events, ln);
                        }
                        ln = nextln;
@@ -151,7 +151,8 @@ static void agentx_events_update(void)
         */
        while (ln) {
                struct listnode *nextln = listnextnode(ln);
-               thread_cancel(listgetdata(ln));
+               thr = listgetdata(ln);
+               thread_cancel(&thr);
                list_delete_node(events, ln);
                ln = nextln;
        }
index 565936a41026d209b920cb7a714bb46fecaade45..cc11d76700986ce4d5761f992a2d78580bf2f4a0 100644 (file)
@@ -190,10 +190,8 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master,
        cb->read.cancelled = false;
 
        if (events & ZMQ_POLLIN) {
-               if (cb->read.thread) {
-                       thread_cancel(cb->read.thread);
-                       cb->read.thread = NULL;
-               }
+               thread_cancel(&cb->read.thread);
+
                funcname_thread_add_event(master, frrzmq_read_msg, cbp, fd,
                                          &cb->read.thread, funcname, schedfrom,
                                          fromln);
@@ -298,10 +296,8 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master,
        cb->write.cancelled = false;
 
        if (events & ZMQ_POLLOUT) {
-               if (cb->write.thread) {
-                       thread_cancel(cb->write.thread);
-                       cb->write.thread = NULL;
-               }
+               thread_cancel(&cb->write.thread);
+
                funcname_thread_add_event(master, frrzmq_write_msg, cbp, fd,
                                          &cb->write.thread, funcname,
                                          schedfrom, fromln);
@@ -317,10 +313,8 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core)
        if (!cb || !*cb)
                return;
        core->cancelled = true;
-       if (core->thread) {
-               thread_cancel(core->thread);
-               core->thread = NULL;
-       }
+       thread_cancel(&core->thread);
+
        if ((*cb)->read.cancelled && !(*cb)->read.thread
            && (*cb)->write.cancelled && (*cb)->write.thread)
                XFREE(MTYPE_ZEROMQ_CB, *cb);
@@ -344,8 +338,8 @@ void frrzmq_check_events(struct frrzmq_cb **cbp, struct cb_core *core,
                return;
        if (events & event && core->thread && !core->cancelled) {
                struct thread_master *tm = core->thread->master;
-               thread_cancel(core->thread);
-               core->thread = NULL;
+               thread_cancel(&core->thread);
+
                thread_add_event(tm, (event == ZMQ_POLLIN ? frrzmq_read_msg
                                                          : frrzmq_write_msg),
                                 cbp, cb->fd, &core->thread);
index db35a3f031d094958725a78345fb25fbe7b77f13..90c6c6f0a85a08197c85a6bd0c9754b2f42c49ca 100644 (file)
@@ -1163,19 +1163,26 @@ void thread_cancel_event(struct thread_master *master, void *arg)
  *
  * @param thread task to cancel
  */
-void thread_cancel(struct thread *thread)
+void thread_cancel(struct thread **thread)
 {
-       struct thread_master *master = thread->master;
+       struct thread_master *master;
+
+       if (thread == NULL || *thread == NULL)
+               return;
+
+       master = (*thread)->master;
 
        assert(master->owner == pthread_self());
 
        frr_with_mutex(&master->mtx) {
                struct cancel_req *cr =
                        XCALLOC(MTYPE_TMP, sizeof(struct cancel_req));
-               cr->thread = thread;
+               cr->thread = *thread;
                listnode_add(master->cancel_req, cr);
                do_thread_cancel(master);
        }
+
+       *thread = NULL;
 }
 
 /**
index c22b2105cd43969215d4a597fc29dcc3ed670e3f..a581796d30ed9ccee3dc32abe50ff929330c4067 100644 (file)
@@ -89,6 +89,8 @@ struct thread_master {
        pthread_t owner;
 };
 
+typedef struct thread_master event_master;
+
 /* Thread itself. */
 struct thread {
        uint8_t type;             /* thread type */
@@ -147,17 +149,10 @@ struct cpu_thread_history {
 #define THREAD_FD(X)  ((X)->u.fd)
 #define THREAD_VAL(X) ((X)->u.val)
 
-#define THREAD_OFF(thread)                                                     \
-       do {                                                                   \
-               if (thread) {                                                  \
-                       thread_cancel(thread);                                 \
-                       thread = NULL;                                         \
-               }                                                              \
-       } while (0)
-
-#define THREAD_READ_OFF(thread)  THREAD_OFF(thread)
-#define THREAD_WRITE_OFF(thread)  THREAD_OFF(thread)
-#define THREAD_TIMER_OFF(thread)  THREAD_OFF(thread)
+#define THREAD_OFF(thread) thread_cancel(&(thread))
+#define THREAD_READ_OFF(thread)  thread_cancel(&(thread))
+#define THREAD_WRITE_OFF(thread)  thread_cancel(&(thread))
+#define THREAD_TIMER_OFF(thread)  thread_cancel(&(thread))
 
 #define debugargdef  const char *funcname, const char *schedfrom, int fromln
 
@@ -207,7 +202,7 @@ extern void funcname_thread_execute(struct thread_master *,
                                    debugargdef);
 #undef debugargdef
 
-extern void thread_cancel(struct thread *);
+extern void thread_cancel(struct thread **event);
 extern void thread_cancel_async(struct thread_master *, struct thread **,
                                void *);
 extern void thread_cancel_event(struct thread_master *, void *);
index 54090d0d0f82720852ffa150e1786c431e3eb736..f8e4677220f77a46b305054f51b7c189466ce6e3 100644 (file)
@@ -104,7 +104,7 @@ void work_queue_free_and_null(struct work_queue **wqp)
        struct work_queue *wq = *wqp;
 
        if (wq->thread != NULL)
-               thread_cancel(wq->thread);
+               thread_cancel(&(wq->thread));
 
        while (!work_queue_empty(wq)) {
                struct work_queue_item *item = work_queue_last_item(wq);
@@ -215,7 +215,7 @@ void workqueue_cmd_init(void)
 void work_queue_plug(struct work_queue *wq)
 {
        if (wq->thread)
-               thread_cancel(wq->thread);
+               thread_cancel(&(wq->thread));
 
        wq->thread = NULL;
 
index 9d3493e910407ed316eeb9fbd41b2e398d7e4b6d..c01ecdd1d4d7a017448e07e1e4fad57a7b4164b9 100644 (file)
@@ -317,21 +317,12 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
        struct listnode *node;
 
        /* Cancel read and write threads. */
-       if (apiserv->t_sync_read) {
-               thread_cancel(apiserv->t_sync_read);
-       }
+       thread_cancel(&apiserv->t_sync_read);
 #ifdef USE_ASYNC_READ
-       if (apiserv->t_async_read) {
-               thread_cancel(apiserv->t_async_read);
-       }
+       thread_cancel(&apiserv->t_async_read);
 #endif /* USE_ASYNC_READ */
-       if (apiserv->t_sync_write) {
-               thread_cancel(apiserv->t_sync_write);
-       }
-
-       if (apiserv->t_async_write) {
-               thread_cancel(apiserv->t_async_write);
-       }
+       thread_cancel(&apiserv->t_sync_write);
+       thread_cancel(&apiserv->t_async_write);
 
        /* Unregister all opaque types that application registered
           and flush opaque LSAs if still in LSDB. */
index 67ea4c4684f5d929d8affd9051c388e767c443c4..6c0df9a1ee1cc48a0f1232d0b41c5b25265bcebd 100644 (file)
        } while (0)
 
 /* Macro for OSPF ISM timer turn off. */
-#define OSPF_ISM_TIMER_OFF(X)                                                  \
-       do {                                                                   \
-               if (X) {                                                       \
-                       thread_cancel(X);                                      \
-                       (X) = NULL;                                            \
-               }                                                              \
-       } while (0)
+#define OSPF_ISM_TIMER_OFF(X) thread_cancel(&(X));
 
 /* Macro for OSPF schedule event. */
 #define OSPF_ISM_EVENT_SCHEDULE(I, E)                                          \
index c219ba7386e2d2e3a11468feae906a9949bea0fe..24cf05009ce231b4caaba777c6988fa3f77450b4 100644 (file)
 #define OSPF_NSM_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr, (V), &(T))
 
 /* Macro for OSPF NSM timer turn off. */
-#define OSPF_NSM_TIMER_OFF(X)                                                  \
-       do {                                                                   \
-               if (X) {                                                       \
-                       thread_cancel(X);                                      \
-                       (X) = NULL;                                            \
-               }                                                              \
-       } while (0)
+#define OSPF_NSM_TIMER_OFF(X) thread_cancel(&(X))
 
 /* Macro for OSPF NSM schedule event. */
 #define OSPF_NSM_EVENT_SCHEDULE(N, E)                                          \
index 8cb0062ea4a55dbc5cddaf24acbb289645c4e28b..ef39b6c2f67c1e118b64ada6dec57016c47665d0 100644 (file)
@@ -468,11 +468,7 @@ static int ospf_ls_req_timer(struct thread *thread)
 
 void ospf_ls_req_event(struct ospf_neighbor *nbr)
 {
-       if (nbr->t_ls_req) {
-               thread_cancel(nbr->t_ls_req);
-               nbr->t_ls_req = NULL;
-       }
-       nbr->t_ls_req = NULL;
+       thread_cancel(&nbr->t_ls_req);
        thread_add_event(master, ospf_ls_req_timer, nbr, 0, &nbr->t_ls_req);
 }
 
index ce3bc33c1afaaeca437987cb0b12a9cf16f9e1d4..3718f82c05caea919cf55205d159513601ba2654 100644 (file)
@@ -1324,10 +1324,7 @@ void ospf_ls_upd_queue_empty(struct ospf_interface *oi)
                }
 
        /* remove update event */
-       if (oi->t_ls_upd_event) {
-               thread_cancel(oi->t_ls_upd_event);
-               oi->t_ls_upd_event = NULL;
-       }
+       thread_cancel(&oi->t_ls_upd_event);
 }
 
 void ospf_if_update(struct ospf *ospf, struct interface *ifp)
@@ -2158,7 +2155,7 @@ static int ospf_vrf_disable(struct vrf *vrf)
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__,
                                   old_vrf_id);
-               thread_cancel(ospf->t_read);
+               thread_cancel(&ospf->t_read);
                close(ospf->fd);
                ospf->fd = -1;
        }
index 5009355d48d3f2414631253e950f7ab9fd91b9fa..5535cb40ab7efda2ea4c72668a0f30ad98e510dd 100644 (file)
@@ -535,13 +535,7 @@ struct ospf_nbr_nbma {
 #define OSPF_AREA_TIMER_ON(T,F,V) thread_add_timer (master, (F), area, (V), &(T))
 #define OSPF_POLL_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr_nbma, (V), &(T))
 #define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
-#define OSPF_TIMER_OFF(X)                                                      \
-       do {                                                                   \
-               if (X) {                                                       \
-                       thread_cancel(X);                                      \
-                       (X) = NULL;                                            \
-               }                                                              \
-       } while (0)
+#define OSPF_TIMER_OFF(X) thread_cancel(&(X))
 
 /* Extern variables. */
 extern struct ospf_master *om;
index c2cee4d69da1387559228d51431b0c497f5d9b59..c601ab404737a8470bf125a5eaf36c75f6cc34c4 100644 (file)
@@ -468,10 +468,7 @@ static void rip_interface_clean(struct rip_interface *ri)
        ri->enable_interface = 0;
        ri->running = 0;
 
-       if (ri->t_wakeup) {
-               thread_cancel(ri->t_wakeup);
-               ri->t_wakeup = NULL;
-       }
+       thread_cancel(&ri->t_wakeup);
 }
 
 void rip_interfaces_clean(struct rip *rip)
index 4c5233c82c505126a1881db31b0ad1ace3243f86..23599f08779019435a3eeeaa5a2e5a73968f4d75 100644 (file)
@@ -86,8 +86,7 @@ static struct rip_peer *rip_peer_get(struct rip *rip, struct in_addr *addr)
        peer = rip_peer_lookup(rip, addr);
 
        if (peer) {
-               if (peer->t_timeout)
-                       thread_cancel(peer->t_timeout);
+               thread_cancel(&peer->t_timeout);
        } else {
                peer = rip_peer_new();
                peer->rip = rip;
index 16859c2d29dcf80a0b9176e9634a9d7eca46c37e..115d7a6b993f94ff0d86dd416bb1e79afa158392 100644 (file)
@@ -321,10 +321,7 @@ void ripng_interface_clean(struct ripng *ripng)
                ri->enable_interface = 0;
                ri->running = 0;
 
-               if (ri->t_wakeup) {
-                       thread_cancel(ri->t_wakeup);
-                       ri->t_wakeup = NULL;
-               }
+               thread_cancel(&ri->t_wakeup);
        }
 }
 
index e6ff58dd0c39f7a1c6898e177860e64037409972..0ac489c67ee2232ab88b00ceac02e5dfc83c7596 100644 (file)
@@ -95,8 +95,7 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
        peer = ripng_peer_lookup(ripng, addr);
 
        if (peer) {
-               if (peer->t_timeout)
-                       thread_cancel(peer->t_timeout);
+               thread_cancel(&peer->t_timeout);
        } else {
                peer = ripng_peer_new();
                peer->ripng = ripng;
@@ -105,7 +104,6 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
        }
 
        /* Update timeout thread. */
-       peer->t_timeout = NULL;
        thread_add_timer(master, ripng_peer_timeout, peer,
                         RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout);
 
index 060477010b0a0ec8c89898dedb192a073a991409..8d9249e4ae2b15aa7bfa4f03bce98e10684bdbd1 100644 (file)
@@ -1463,10 +1463,7 @@ static int ripng_update(struct thread *t)
 
        /* Triggered updates may be suppressed if a regular update is due by
           the time the triggered update would be sent. */
-       if (ripng->t_triggered_interval) {
-               thread_cancel(ripng->t_triggered_interval);
-               ripng->t_triggered_interval = NULL;
-       }
+       thread_cancel(&ripng->t_triggered_interval);
        ripng->trigger = 0;
 
        /* Reset flush event. */
@@ -1500,10 +1497,7 @@ int ripng_triggered_update(struct thread *t)
        ripng->t_triggered_update = NULL;
 
        /* Cancel interval timer. */
-       if (ripng->t_triggered_interval) {
-               thread_cancel(ripng->t_triggered_interval);
-               ripng->t_triggered_interval = NULL;
-       }
+       thread_cancel(&ripng->t_triggered_interval);
        ripng->trigger = 0;
 
        /* Logging triggered update. */
@@ -1952,10 +1946,8 @@ void ripng_event(struct ripng *ripng, enum ripng_event event, int sock)
                                &ripng->t_read);
                break;
        case RIPNG_UPDATE_EVENT:
-               if (ripng->t_update) {
-                       thread_cancel(ripng->t_update);
-                       ripng->t_update = NULL;
-               }
+               thread_cancel(&ripng->t_update);
+
                /* Update timer jitter. */
                jitter = ripng_update_jitter(ripng->update_time);
 
@@ -2719,10 +2711,7 @@ static void ripng_instance_disable(struct ripng *ripng)
        RIPNG_TIMER_OFF(ripng->t_triggered_interval);
 
        /* Cancel the read thread */
-       if (ripng->t_read) {
-               thread_cancel(ripng->t_read);
-               ripng->t_read = NULL;
-       }
+       thread_cancel(&ripng->t_read);
 
        /* Close the RIPng socket */
        if (ripng->sock >= 0) {
index 70508d5cb04ada785caf02cec9c241a42e1ff0eb..97291829bd81a6acfea0095be7824ccd003793d3 100644 (file)
@@ -351,13 +351,7 @@ enum ripng_event {
 /* RIPng timer on/off macro. */
 #define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
 
-#define RIPNG_TIMER_OFF(T)                                                     \
-       do {                                                                   \
-               if (T) {                                                       \
-                       thread_cancel(T);                                      \
-                       (T) = NULL;                                            \
-               }                                                              \
-       } while (0)
+#define RIPNG_TIMER_OFF(T)  thread_cancel(&(T));
 
 #define RIPNG_OFFSET_LIST_IN  0
 #define RIPNG_OFFSET_LIST_OUT 1
index cbf9b05546d1d733a438e4630cfdab21ccb0a7e5..416ea39772796de470433d07da968f85467e45f7 100644 (file)
@@ -153,7 +153,7 @@ int main(int argc, char **argv)
                        continue;
 
                XFREE(MTYPE_TMP, timers[index]->arg);
-               thread_cancel(timers[index]);
+               thread_cancel(&timers[index]);
                timers[index] = NULL;
                timers_pending--;
        }
index 2960e0d81e2382e081bb9578ecae58cd5d590260..45b29b92b1ec30204afc9351ee5c2a1610bde310 100644 (file)
@@ -59,7 +59,7 @@ int main(int argc, char **argv)
                thread_add_timer_msec(master, dummy_func, NULL, 0, &timers[i]);
        }
        for (i = 0; i < SCHEDULE_TIMERS; i++)
-               thread_cancel(timers[i]);
+               thread_cancel(&timers[i]);
 
        monotime(&tv_start);
 
@@ -78,8 +78,7 @@ int main(int argc, char **argv)
                int index;
 
                index = prng_rand(prng) % SCHEDULE_TIMERS;
-               if (timers[index])
-                       thread_cancel(timers[index]);
+               thread_cancel(&timers[index]);
                timers[index] = NULL;
        }
 
index af243f7ca57f52110ffa8ac1305402be3af6db8e..cd5ec6725d40081609f4f91a4087f5516c854840 100644 (file)
@@ -409,8 +409,8 @@ static void sigchild(void)
                what = restart->what;
                restart->pid = 0;
                gs.numpids--;
-               thread_cancel(restart->t_kill);
-               restart->t_kill = NULL;
+               thread_cancel(&restart->t_kill);
+
                /* Update restart time to reflect the time the command
                 * completed. */
                gettimeofday(&restart->time, NULL);
@@ -678,8 +678,7 @@ static int handle_read(struct thread *t_read)
                           dmn->name, (long)delay.tv_sec, (long)delay.tv_usec);
 
        SET_READ_HANDLER(dmn);
-       if (dmn->t_wakeup)
-               thread_cancel(dmn->t_wakeup);
+       thread_cancel(&dmn->t_wakeup);
        SET_WAKEUP_ECHO(dmn);
 
        return 0;
@@ -866,9 +865,8 @@ static int phase_hanging(struct thread *t_hanging)
 static void set_phase(restart_phase_t new_phase)
 {
        gs.phase = new_phase;
-       if (gs.t_phase_hanging)
-               thread_cancel(gs.t_phase_hanging);
-       gs.t_phase_hanging = NULL;
+       thread_cancel(&gs.t_phase_hanging);
+
        thread_add_timer(master, phase_hanging, NULL, PHASE_TIMEOUT,
                         &gs.t_phase_hanging);
 }
index 710a32c45289a1bf1700cf3131c822d08b75d975..936206641f9dcf7a9ce436c83a99ebe3cf84b5c1 100644 (file)
@@ -263,9 +263,7 @@ void irdp_advert_off(struct interface *ifp)
        if (!irdp)
                return;
 
-       if (irdp->t_advertise)
-               thread_cancel(irdp->t_advertise);
-       irdp->t_advertise = NULL;
+       thread_cancel(&irdp->t_advertise);
 
        if (ifp->connected)
                for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
@@ -300,9 +298,7 @@ void process_solicit(struct interface *ifp)
                return;
 
        irdp->flags |= IF_SOLICIT;
-       if (irdp->t_advertise)
-               thread_cancel(irdp->t_advertise);
-       irdp->t_advertise = NULL;
+       thread_cancel(&irdp->t_advertise);
 
        timer = (frr_weak_random() % MAX_RESPONSE_DELAY) + 1;
 
index 995fa6fb5af6cbc5410d342713e205aa26a2c180..ee2dc7a0edc11505e9486316cc298f74fdb8b676 100644 (file)
@@ -378,7 +378,7 @@ void zebra_ns_notify_close(void)
                fd = zebra_netns_notify_current->u.fd;
 
        if (zebra_netns_notify_current->master != NULL)
-               thread_cancel(zebra_netns_notify_current);
+               thread_cancel(&zebra_netns_notify_current);
 
        /* auto-removal of notify items */
        if (fd > 0)
index 9a3b567b5aa2b3e80495579d39d25125358e982b..013cb6449cdd9d9d26b38a0f20619f4aa02ccaa7 100644 (file)
@@ -156,13 +156,10 @@ void zebra_ptm_finish(void)
        if (ptm_cb.in_data)
                free(ptm_cb.in_data);
 
-       /* Release threads. */
-       if (ptm_cb.t_read)
-               thread_cancel(ptm_cb.t_read);
-       if (ptm_cb.t_write)
-               thread_cancel(ptm_cb.t_write);
-       if (ptm_cb.t_timer)
-               thread_cancel(ptm_cb.t_timer);
+       /* Cancel events. */
+       thread_cancel(&ptm_cb.t_read);
+       thread_cancel(&ptm_cb.t_write);
+       thread_cancel(&ptm_cb.t_timer);
 
        if (ptm_cb.wb)
                buffer_free(ptm_cb.wb);
index 8155f9acfe058d6f079d9efa6aca467edc02e7c6..cf8cd0639e9f9d2d26d2d9d4394219ecec74bb9d 100644 (file)
@@ -1695,7 +1695,7 @@ static void zebra_route_map_set_delay_timer(uint32_t value)
        if (!value && zebra_t_rmap_update) {
                /* Event driven route map updates is being disabled */
                /* But there's a pending timer. Fire it off now */
-               thread_cancel(zebra_t_rmap_update);
+               thread_cancel(&zebra_t_rmap_update);
                zebra_route_map_update_timer(zebra_t_rmap_update);
        }
 }