Removes the WiP shim and implements proper thread lifecycle management.
* Declare necessary pthread_t's in bgp_master
* Define new MTYPE in lib/thread.c for pthreads
* Allocate and free BGP's pthreads appropriately
* Terminate and join threads appropriately
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
/* reverse bgp_attr_init */
bgp_attr_finish();
+ /* stop pthreads */
+ bgp_pthreads_finish();
+
/* reverse access_list_init */
access_list_add_hook(NULL);
access_list_delete_hook(NULL);
snprintf(bgpd_di.startinfo, sizeof(bgpd_di.startinfo), ", bgp@%s:%d",
(bm->address ? bm->address : "<all>"), bm->port);
- pthread_t packet_writes, keepalives;
- pthread_create(&packet_writes, NULL, &peer_writes_start, NULL);
- pthread_create(&keepalives, NULL, &keepalives_start, NULL);
-
frr_config_fork();
+ /* must be called after fork() */
+ bgp_pthreads_init();
frr_run(bm->master);
/* Not reached. */
bgp_write(peer);
}
pthread_mutex_unlock(&peer->obuf_mtx);
+
+ if (!bgp_packet_writes_thread_run)
+ break;
}
// schedule update packet generation on main thread
#include "bgpd/bgp_bfd.h"
#include "bgpd/bgp_memory.h"
#include "bgpd/bgp_evpn_vty.h"
+#include "bgpd/bgp_keepalives.h"
DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)");
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();
{.completions = NULL},
};
+void bgp_pthreads_init()
+{
+ /* init write & keepalive threads */
+ pthread_create(bm->t_bgp_keepalives, NULL, &peer_keepalives_start,
+ NULL);
+ pthread_create(bm->t_bgp_packet_writes, NULL, &peer_writes_start, 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);
+}
+
void bgp_init(void)
{
/* BGP thread master. */
struct thread_master *master;
+ /* BGP pthreads. */
+ pthread_t *t_bgp_keepalives;
+ pthread_t *t_bgp_packet_writes;
+
/* work queues */
struct work_queue *process_main_queue;
extern void bgp_master_init(struct thread_master *master);
extern void bgp_init(void);
+extern void bgp_pthreads_init(void);
+extern void bgp_pthreads_finish(void);
extern void bgp_route_map_init(void);
extern void bgp_session_reset(struct peer *);
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread")
DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master")
DEFINE_MTYPE_STATIC(LIB, THREAD_STATS, "Thread stats")
+DEFINE_MTYPE(LIB, PTHREAD, "POSIX Thread")
#if defined(__APPLE__)
#include <mach/mach.h>
#include <poll.h>
#include "monotime.h"
+#include "memory.h"
+DECLARE_MTYPE(PTHREAD)
+
struct rusage_t {
struct rusage cpu;
struct timeval real;