]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Ensure that io thread is running after start
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 6 Jan 2018 19:04:35 +0000 (14:04 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 6 Jan 2018 19:09:29 +0000 (14:09 -0500)
The BGP IO thread must be running before other threads
can start using it.  So at startup check to see
that it running once, instead of before every
function call into.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_io.c
bgpd/bgp_io.h
bgpd/bgpd.c

index 548167b3a38878cb301617fdb69ef82c1c0eed5f..cc9c1bda5692737076efcb5efd020afc8008b1cf 100644 (file)
@@ -109,13 +109,15 @@ int bgp_io_stop(void **result, struct frr_pthread *fpt)
 }
 
 /* Extern API -------------------------------------------------------------- */
+void bgp_io_running(void)
+{
+       while (!atomic_load_explicit(&bgp_io_thread_started,
+                                    memory_order_seq_cst))
+               frr_pthread_yield();
+}
 
 void bgp_writes_on(struct peer *peer)
 {
-       while (
-           !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst))
-               ;
-
        assert(peer->status != Deleted);
        assert(peer->obuf);
        assert(peer->ibuf);
@@ -133,10 +135,6 @@ void bgp_writes_on(struct peer *peer)
 
 void bgp_writes_off(struct peer *peer)
 {
-       while (
-           !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst))
-               ;
-
        struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
 
        thread_cancel_async(fpt->master, &peer->t_write, NULL);
@@ -147,10 +145,6 @@ void bgp_writes_off(struct peer *peer)
 
 void bgp_reads_on(struct peer *peer)
 {
-       while (
-           !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst))
-               ;
-
        assert(peer->status != Deleted);
        assert(peer->ibuf);
        assert(peer->fd);
@@ -170,10 +164,6 @@ void bgp_reads_on(struct peer *peer)
 
 void bgp_reads_off(struct peer *peer)
 {
-       while (
-           !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst))
-               ;
-
        struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
 
        thread_cancel_async(fpt->master, &peer->t_read, NULL);
index c4bd3c2dd97cf8bad382f37fe8e3b8fcfd9f4eeb..73587366d7871ebb3460f6e4bf62d5628a93fb33 100644 (file)
  */
 extern void bgp_io_init(void);
 
+/**
+ * Ensure that the BGP IO thread is actually up and running
+ *
+ * This function must be called immediately after the thread
+ * has been created for running.  This is because we want
+ * to make sure that the io thread is ready before other
+ * threads start attempting to use it.
+ */
+extern void bgp_io_running(void);
+
 /**
  * Start function for write thread.
  *
index 6dcb603cb68c4ff65ebdbcc7b4d79baec5f6b992..4d8e4ffe37bac8cfdc6ec499953fe51cac07f8e4 100644 (file)
@@ -7437,7 +7437,15 @@ void bgp_pthreads_run()
        pthread_attr_init(&attr);
        pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
 
+       /*
+        * Please ensure that the io thread is running
+        * by calling bgp_io_running.  The BGP threads
+        * depend on it being running when we start
+        * looking for it.
+        */
        frr_pthread_run(PTHREAD_IO, &attr, NULL);
+       bgp_io_running();
+
        frr_pthread_run(PTHREAD_KEEPALIVES, &attr, NULL);
 }