From: Jorge Boncompte Date: Mon, 7 Aug 2017 11:40:10 +0000 (+0200) Subject: bgpd: inline bgp_lock()/bgp_unlock() X-Git-Tag: frr-4.0-dev~386^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=92375c917edb63c32d5441f6a264e73af5b2a2a0;p=mirror%2Ffrr.git bgpd: inline bgp_lock()/bgp_unlock() Signed-off-by: Jorge Boncompte --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 35f793f861..741fa5ceeb 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2248,8 +2248,7 @@ void bgp_process(struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) /* all unlocked in bgp_processq_del */ bgp_table_lock(bgp_node_table(rn)); pqnode->rn = bgp_lock_node(rn); - pqnode->bgp = bgp; - bgp_lock(bgp); + pqnode->bgp = bgp_lock(bgp); pqnode->afi = afi; pqnode->safi = safi; work_queue_add(bm->process_main_queue, pqnode); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index d7733fbacd..9d7c38c871 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1116,9 +1116,8 @@ struct peer *peer_new(struct bgp *bgp) peer->status = Idle; peer->ostatus = Idle; peer->cur_event = peer->last_event = peer->last_major_event = 0; - peer->bgp = bgp; + peer->bgp = bgp_lock(bgp); peer = peer_lock(peer); /* initial reference */ - bgp_lock(bgp); peer->password = NULL; /* Set default flags. */ @@ -3106,21 +3105,7 @@ int bgp_delete(struct bgp *bgp) return 0; } -static void bgp_free(struct bgp *); - -void bgp_lock(struct bgp *bgp) -{ - ++bgp->lock; -} - -void bgp_unlock(struct bgp *bgp) -{ - assert(bgp->lock > 0); - if (--bgp->lock == 0) - bgp_free(bgp); -} - -static void bgp_free(struct bgp *bgp) +void bgp_free(struct bgp *bgp) { afi_t afi; safi_t safi; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index bfdddc69b1..f6e7b2277f 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1252,9 +1252,6 @@ extern int bgp_flag_set(struct bgp *, int); extern int bgp_flag_unset(struct bgp *, int); extern int bgp_flag_check(struct bgp *, int); -extern void bgp_lock(struct bgp *); -extern void bgp_unlock(struct bgp *); - extern void bgp_router_id_zebra_bump(vrf_id_t, const struct prefix *); extern int bgp_router_id_static_set(struct bgp *, struct in_addr); @@ -1395,6 +1392,20 @@ extern struct peer_af *peer_af_find(struct peer *, afi_t, safi_t); extern int peer_af_delete(struct peer *, afi_t, safi_t); extern void bgp_close(void); +extern void bgp_free(struct bgp *); + +static inline struct bgp *bgp_lock(struct bgp *bgp) +{ + bgp->lock++; + return bgp; +} + +static inline void bgp_unlock(struct bgp *bgp) +{ + assert(bgp->lock > 0); + if (--bgp->lock == 0) + bgp_free(bgp); +} static inline int afindex(afi_t afi, safi_t safi) { @@ -1540,10 +1551,8 @@ static inline struct vrf *bgp_vrf_lookup_by_instance_type(struct bgp *bgp) static inline void bgp_vrf_link(struct bgp *bgp, struct vrf *vrf) { bgp->vrf_id = vrf->vrf_id; - if (vrf->info != (void *)bgp) { - bgp_lock(bgp); - vrf->info = (void *)bgp; - } + if (vrf->info != (void *)bgp) + vrf->info = (void *)bgp_lock(bgp); } /* Unlink BGP instance from VRF. */