]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: use new threading infra
authorQuentin Young <qlyoung@cumulusnetworks.com>
Sun, 16 Apr 2017 05:18:07 +0000 (05:18 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 30 Nov 2017 21:17:59 +0000 (16:17 -0500)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
bgpd/bgp_keepalives.c
bgpd/bgp_keepalives.h
bgpd/bgp_packet.c
bgpd/bgp_packet.h
bgpd/bgpd.c
bgpd/bgpd.h

index dada5c3c265a10cc5cc772101c8db25cadddacc8..23f3f517325f21402f95b9368123b9593b7d33b5 100644 (file)
@@ -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;
+}
index 2bd3964dbe1f01f3ddc6d401dd444373f3d61414..d74b69e90867a06f8907d5ffdabc531e4934e7f2 100644 (file)
@@ -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 */
index 02ea92a4d122a5039eb2f8a67414df5fa479ddfb..5994df23ece07754002eeb11bff07fcfa3ca3d7d 100644 (file)
@@ -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;
+}
index bedfa629fcf942744219334d6add09fbac8c2b9d..2c252012f9e6b6538b0677c903a2323e03108bdf 100644 (file)
@@ -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 */
index f2cb8f81f7d522039f9822aab40b23064e2d72f8..306a31e409baec1d9f45d190caa34f30651ac8e3 100644 (file)
@@ -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)
index 0767db58f34f7813c8a132af8497783f39666117..0e80226ebeeaddb6505327e8e7648f345603fd4c 100644 (file)
@@ -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;