}
/* 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);
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);
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);
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);
*/
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.
*
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);
}