diff options
| -rw-r--r-- | bgpd/bgp_io.c | 22 | ||||
| -rw-r--r-- | bgpd/bgp_io.h | 10 | ||||
| -rw-r--r-- | bgpd/bgpd.c | 8 | 
3 files changed, 24 insertions, 16 deletions
diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 548167b3a3..cc9c1bda56 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -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); diff --git a/bgpd/bgp_io.h b/bgpd/bgp_io.h index c4bd3c2dd9..73587366d7 100644 --- a/bgpd/bgp_io.h +++ b/bgpd/bgp_io.h @@ -37,6 +37,16 @@  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.   *   * @param arg - unused diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 6dcb603cb6..4d8e4ffe37 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -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);  }  | 
