summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-04-16 07:18:07 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-11-30 22:17:59 +0100
commit0ca8b79f38c697c0c159518245f3bdb217157944 (patch)
treea80c7d83626b8bf2afff8a46daebbb8ee274a10c
parentbgpd: use hash table for bgp_keepalives.c (diff)
downloadfrr-0ca8b79f38c697c0c159518245f3bdb217157944.tar.xz
frr-0ca8b79f38c697c0c159518245f3bdb217157944.zip
bgpd: use new threading infra
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_keepalives.c10
-rw-r--r--bgpd/bgp_keepalives.h3
-rw-r--r--bgpd/bgp_packet.c10
-rw-r--r--bgpd/bgp_packet.h1
-rw-r--r--bgpd/bgpd.c32
-rw-r--r--bgpd/bgpd.h6
6 files changed, 39 insertions, 23 deletions
diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c
index dada5c3c2..23f3f5173 100644
--- a/bgpd/bgp_keepalives.c
+++ b/bgpd/bgp_keepalives.c
@@ -31,6 +31,7 @@
#include "vty.h"
#include "monotime.h"
#include "hash.h"
+#include "frr_pthread.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_keepalives.h"
@@ -273,3 +274,12 @@ void peer_keepalives_wake()
}
pthread_mutex_unlock(peerhash_mtx);
}
+
+int peer_keepalives_stop(void **result)
+{
+ struct frr_pthread *fpt = frr_pthread_get(PTHREAD_KEEPALIVES);
+ bgp_keepalives_thread_run = false;
+ peer_keepalives_wake();
+ pthread_join(fpt->thread, result);
+ return 0;
+}
diff --git a/bgpd/bgp_keepalives.h b/bgpd/bgp_keepalives.h
index 2bd3964db..d74b69e90 100644
--- a/bgpd/bgp_keepalives.h
+++ b/bgpd/bgp_keepalives.h
@@ -87,4 +87,7 @@ extern void *peer_keepalives_start(void *arg);
*/
extern void peer_keepalives_wake(void);
+/* stop function */
+int peer_keepalives_stop(void **result);
+
#endif /* _BGP_KEEPALIVES_H */
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 02ea92a4d..5994df23e 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -34,6 +34,7 @@
#include "plist.h"
#include "queue.h"
#include "filter.h"
+#include "lib/frr_pthread.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -2421,3 +2422,12 @@ void peer_writes_wake()
{
pthread_cond_signal(write_cond);
}
+
+int peer_writes_stop(void **result)
+{
+ struct frr_pthread *fpt = frr_pthread_get(PTHREAD_WRITE);
+ bgp_packet_writes_thread_run = false;
+ peer_writes_wake();
+ pthread_join(fpt->thread, result);
+ return 0;
+}
diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h
index bedfa629f..2c252012f 100644
--- a/bgpd/bgp_packet.h
+++ b/bgpd/bgp_packet.h
@@ -72,5 +72,6 @@ extern void *peer_writes_start(void *arg);
extern void peer_writes_on(struct peer *peer);
extern void peer_writes_off(struct peer *peer);
extern void peer_writes_wake(void);
+extern int peer_writes_stop(void **result);
#endif /* _QUAGGA_BGP_PACKET_H */
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index f2cb8f81f..306a31e40 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -42,6 +42,7 @@
#include "jhash.h"
#include "table.h"
#include "lib/json.h"
+#include "frr_pthread.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -7327,8 +7328,6 @@ void bgp_master_init(struct thread_master *master)
bm->start_time = bgp_clock();
bm->t_rmap_update = NULL;
bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
- bm->t_bgp_keepalives = XCALLOC(MTYPE_PTHREAD, sizeof(pthread_t));
- bm->t_bgp_packet_writes = XCALLOC(MTYPE_PTHREAD, sizeof(pthread_t));
bgp_process_queue_init();
@@ -7387,6 +7386,13 @@ static const struct cmd_variable_handler bgp_viewvrf_var_handlers[] = {
void bgp_pthreads_init()
{
+ frr_pthread_init();
+
+ frr_pthread_new("BGP write thread", PTHREAD_WRITE, peer_writes_start,
+ peer_writes_stop);
+ frr_pthread_new("BGP keepalives thread", PTHREAD_KEEPALIVES,
+ peer_keepalives_start, peer_keepalives_stop);
+
/* pre-run initialization */
peer_keepalives_init();
peer_writes_init();
@@ -7394,28 +7400,14 @@ void bgp_pthreads_init()
void bgp_pthreads_run()
{
- /* run threads */
- pthread_create(bm->t_bgp_keepalives, NULL, &peer_keepalives_start,
- NULL);
- pthread_create(bm->t_bgp_packet_writes, NULL, &peer_writes_start, NULL);
+ frr_pthread_run(PTHREAD_WRITE, NULL, NULL);
+ frr_pthread_run(PTHREAD_KEEPALIVES, NULL, NULL);
}
void bgp_pthreads_finish()
{
- /* set thread cancellation flags */
- bgp_keepalives_thread_run = false;
- bgp_packet_writes_thread_run = false;
-
- /* wake them up */
- peer_writes_wake();
- peer_keepalives_wake();
-
- /* join */
- pthread_join(*bm->t_bgp_keepalives, NULL);
- pthread_join(*bm->t_bgp_packet_writes, NULL);
-
- XFREE(MTYPE_PTHREAD, bm->t_bgp_keepalives);
- XFREE(MTYPE_PTHREAD, bm->t_bgp_packet_writes);
+ frr_pthread_stop_all();
+ frr_pthread_finish();
}
void bgp_init(void)
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 0767db58f..0e80226eb 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -100,9 +100,9 @@ struct bgp_master {
/* BGP thread master. */
struct thread_master *master;
- /* BGP pthreads. */
- pthread_t *t_bgp_keepalives;
- pthread_t *t_bgp_packet_writes;
+/* BGP pthreads. */
+#define PTHREAD_WRITE (1 << 1)
+#define PTHREAD_KEEPALIVES (1 << 2)
/* work queues */
struct work_queue *process_main_queue;