summaryrefslogtreecommitdiff
path: root/bgpd/bgp_keepalives.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-06-21 10:58:02 +0200
committerDavid Lamparter <equinox@diac24.net>2019-09-03 17:15:17 +0200
commit00dffa8cde7661e00245ebe1b1eea248b8dd6802 (patch)
treea1e698d6b613b63407b3ad786565d09c7e7b7382 /bgpd/bgp_keepalives.c
parent48373d46f1e82fb0413831fa85304cea5c1db766 (diff)
lib: add frr_with_mutex() block-wrapper
frr_with_mutex(...) { ... } locks and automatically unlocks the listed mutex(es) when the block is exited. This adds a bit of safety against forgetting the unlock in error paths & co. and makes the code a slight bit more readable. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_keepalives.c')
-rw-r--r--bgpd/bgp_keepalives.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c
index bec3bdcb8d..6de1c216a6 100644
--- a/bgpd/bgp_keepalives.c
+++ b/bgpd/bgp_keepalives.c
@@ -245,8 +245,7 @@ void bgp_keepalives_on(struct peer *peer)
*/
assert(peerhash_mtx);
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
holder.peer = peer;
if (!hash_lookup(peerhash, &holder)) {
struct pkat *pkat = pkat_new(peer);
@@ -255,7 +254,6 @@ void bgp_keepalives_on(struct peer *peer)
}
SET_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON);
}
- pthread_mutex_unlock(peerhash_mtx);
bgp_keepalives_wake();
}
@@ -275,8 +273,7 @@ void bgp_keepalives_off(struct peer *peer)
*/
assert(peerhash_mtx);
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
holder.peer = peer;
struct pkat *res = hash_release(peerhash, &holder);
if (res) {
@@ -285,16 +282,13 @@ void bgp_keepalives_off(struct peer *peer)
}
UNSET_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON);
}
- pthread_mutex_unlock(peerhash_mtx);
}
void bgp_keepalives_wake(void)
{
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
pthread_cond_signal(peerhash_cond);
}
- pthread_mutex_unlock(peerhash_mtx);
}
int bgp_keepalives_stop(struct frr_pthread *fpt, void **result)