summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/agentx.c42
-rw-r--r--lib/bfd.c26
-rw-r--r--lib/bfd.h5
-rw-r--r--lib/command.c4
-rw-r--r--lib/event.c (renamed from lib/thread.c)609
-rw-r--r--lib/frr_pthread.c20
-rw-r--r--lib/frr_pthread.h4
-rw-r--r--lib/frr_zmq.c77
-rw-r--r--lib/frr_zmq.h53
-rw-r--r--lib/frrevent.h295
-rw-r--r--lib/grammar_sandbox_main.c10
-rw-r--r--lib/ldp_sync.c4
-rw-r--r--lib/ldp_sync.h2
-rw-r--r--lib/libfrr.c42
-rw-r--r--lib/libfrr.h16
-rw-r--r--lib/libfrr_trace.h12
-rw-r--r--lib/log.c4
-rw-r--r--lib/mgmt_be_client.c54
-rw-r--r--lib/mgmt_be_client.h5
-rw-r--r--lib/mgmt_fe_client.c54
-rw-r--r--lib/mgmt_fe_client.h7
-rw-r--r--lib/mgmt_msg.c2
-rw-r--r--lib/mgmt_msg.h2
-rw-r--r--lib/northbound.c2
-rw-r--r--lib/northbound.h4
-rw-r--r--lib/northbound_cli.c25
-rw-r--r--lib/northbound_cli.h2
-rw-r--r--lib/northbound_confd.c47
-rw-r--r--lib/northbound_grpc.cpp23
-rw-r--r--lib/northbound_sysrepo.c22
-rw-r--r--lib/pullwr.c25
-rw-r--r--lib/pullwr.h10
-rw-r--r--lib/qobj.c2
-rw-r--r--lib/resolver.c60
-rw-r--r--lib/resolver.h6
-rw-r--r--lib/sigevent.c17
-rw-r--r--lib/sigevent.h6
-rw-r--r--lib/smux.h4
-rw-r--r--lib/spf_backoff.c46
-rw-r--r--lib/spf_backoff.h4
-rw-r--r--lib/subdir.am6
-rw-r--r--lib/systemd.c12
-rw-r--r--lib/systemd.h4
-rw-r--r--lib/thread.h291
-rw-r--r--lib/vty.c92
-rw-r--r--lib/vty.h12
-rw-r--r--lib/wheel.c32
-rw-r--r--lib/wheel.h6
-rw-r--r--lib/workqueue.c39
-rw-r--r--lib/workqueue.h8
-rw-r--r--lib/xref.h2
-rw-r--r--lib/yang.h2
-rw-r--r--lib/zclient.c46
-rw-r--r--lib/zclient.h10
-rw-r--r--lib/zlog.c4
-rw-r--r--lib/zlog_5424.c26
-rw-r--r--lib/zlog_5424.h8
-rw-r--r--lib/zlog_5424_cli.c6
58 files changed, 1132 insertions, 1128 deletions
diff --git a/lib/agentx.c b/lib/agentx.c
index 2f45ae8332..45f14c2703 100644
--- a/lib/agentx.c
+++ b/lib/agentx.c
@@ -27,13 +27,13 @@ DEFINE_HOOK(agentx_enabled, (), ());
static bool agentx_enabled = false;
-static struct thread_master *agentx_tm;
-static struct thread *timeout_thr = NULL;
+static struct event_loop *agentx_tm;
+static struct event *timeout_thr = NULL;
static struct list *events = NULL;
static void agentx_events_update(void);
-static void agentx_timeout(struct thread *t)
+static void agentx_timeout(struct event *t)
{
snmp_timeout();
run_alarms();
@@ -41,18 +41,18 @@ static void agentx_timeout(struct thread *t)
agentx_events_update();
}
-static void agentx_read(struct thread *t)
+static void agentx_read(struct event *t)
{
fd_set fds;
int flags, new_flags = 0;
int nonblock = false;
- struct listnode *ln = THREAD_ARG(t);
- struct thread **thr = listgetdata(ln);
+ struct listnode *ln = EVENT_ARG(t);
+ struct event **thr = listgetdata(ln);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
/* fix for non blocking socket */
- flags = fcntl(THREAD_FD(t), F_GETFL, 0);
+ flags = fcntl(EVENT_FD(t), F_GETFL, 0);
if (-1 == flags) {
flog_err(EC_LIB_SYSTEM_CALL, "Failed to get FD settings fcntl: %s(%d)",
strerror(errno), errno);
@@ -62,19 +62,19 @@ static void agentx_read(struct thread *t)
if (flags & O_NONBLOCK)
nonblock = true;
else
- new_flags = fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK);
+ new_flags = fcntl(EVENT_FD(t), F_SETFL, flags | O_NONBLOCK);
if (new_flags == -1)
flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)",
strerror(errno), errno);
FD_ZERO(&fds);
- FD_SET(THREAD_FD(t), &fds);
+ FD_SET(EVENT_FD(t), &fds);
snmp_read(&fds);
/* Reset the flag */
if (!nonblock) {
- new_flags = fcntl(THREAD_FD(t), F_SETFL, flags);
+ new_flags = fcntl(EVENT_FD(t), F_SETFL, flags);
if (new_flags == -1)
flog_err(
@@ -94,22 +94,22 @@ static void agentx_events_update(void)
struct timeval timeout = {.tv_sec = 0, .tv_usec = 0};
fd_set fds;
struct listnode *ln;
- struct thread **thr;
+ struct event **thr;
int fd, thr_fd;
- thread_cancel(&timeout_thr);
+ event_cancel(&timeout_thr);
FD_ZERO(&fds);
snmp_select_info(&maxfd, &fds, &timeout, &block);
if (!block) {
- thread_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
- &timeout_thr);
+ event_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
+ &timeout_thr);
}
ln = listhead(events);
thr = ln ? listgetdata(ln) : NULL;
- thr_fd = thr ? THREAD_FD(*thr) : -1;
+ thr_fd = thr ? EVENT_FD(*thr) : -1;
/* "two-pointer" / two-list simultaneous iteration
* ln/thr/thr_fd point to the next existing event listener to hit while
@@ -119,21 +119,21 @@ static void agentx_events_update(void)
if (thr_fd == fd) {
struct listnode *nextln = listnextnode(ln);
if (!FD_ISSET(fd, &fds)) {
- thread_cancel(thr);
+ event_cancel(thr);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
}
ln = nextln;
thr = ln ? listgetdata(ln) : NULL;
- thr_fd = thr ? THREAD_FD(*thr) : -1;
+ thr_fd = thr ? EVENT_FD(*thr) : -1;
}
/* need listener, but haven't hit one where it would be */
else if (FD_ISSET(fd, &fds)) {
struct listnode *newln;
- thr = XCALLOC(MTYPE_TMP, sizeof(struct thread *));
+ thr = XCALLOC(MTYPE_TMP, sizeof(struct event *));
newln = listnode_add_before(events, ln, thr);
- thread_add_read(agentx_tm, agentx_read, newln, fd, thr);
+ event_add_read(agentx_tm, agentx_read, newln, fd, thr);
}
}
@@ -142,7 +142,7 @@ static void agentx_events_update(void)
while (ln) {
struct listnode *nextln = listnextnode(ln);
thr = listgetdata(ln);
- thread_cancel(thr);
+ event_cancel(thr);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
ln = nextln;
@@ -244,7 +244,7 @@ bool smux_enabled(void)
return agentx_enabled;
}
-void smux_init(struct thread_master *tm)
+void smux_init(struct event_loop *tm)
{
agentx_tm = tm;
diff --git a/lib/bfd.c b/lib/bfd.c
index c1e0fff7f5..cc6d09a60f 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -10,7 +10,7 @@
#include "command.h"
#include "memory.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "vrf.h"
#include "zclient.h"
@@ -75,7 +75,7 @@ struct bfd_session_params {
* Next event.
*
* This variable controls what action to execute when the command batch
- * finishes. Normally we'd use `thread_add_event` value, however since
+ * finishes. Normally we'd use `event_add_event` value, however since
* that function is going to be called multiple times and the value
* might be different we'll use this variable to keep track of it.
*/
@@ -87,7 +87,7 @@ struct bfd_session_params {
* configuration load or northbound batch), so we'll use this to
* install/uninstall the BFD session parameters only once.
*/
- struct thread *installev;
+ struct event *installev;
/** BFD session installation state. */
bool installed;
@@ -111,7 +111,7 @@ struct bfd_sessions_global {
struct bfd_source_list source_list;
/** Pointer to FRR's event manager. */
- struct thread_master *tm;
+ struct event_loop *tm;
/** Pointer to zebra client data structure. */
struct zclient *zc;
@@ -485,9 +485,9 @@ static bool _bfd_sess_valid(const struct bfd_session_params *bsp)
return true;
}
-static void _bfd_sess_send(struct thread *t)
+static void _bfd_sess_send(struct event *t)
{
- struct bfd_session_params *bsp = THREAD_ARG(t);
+ struct bfd_session_params *bsp = EVENT_ARG(t);
int rv;
/* Validate configuration before trying to send bogus data. */
@@ -533,7 +533,7 @@ static void _bfd_sess_send(struct thread *t)
static void _bfd_sess_remove(struct bfd_session_params *bsp)
{
/* Cancel any pending installation request. */
- THREAD_OFF(bsp->installev);
+ EVENT_OFF(bsp->installev);
/* Not installed, nothing to do. */
if (!bsp->installed)
@@ -541,7 +541,7 @@ static void _bfd_sess_remove(struct bfd_session_params *bsp)
/* Send request to remove any session. */
bsp->lastev = BSE_UNINSTALL;
- thread_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
+ event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
}
void bfd_sess_free(struct bfd_session_params **bsp)
@@ -733,13 +733,13 @@ void bfd_sess_set_auto_source(struct bfd_session_params *bsp, bool enable)
void bfd_sess_install(struct bfd_session_params *bsp)
{
bsp->lastev = BSE_INSTALL;
- thread_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
+ event_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
}
void bfd_sess_uninstall(struct bfd_session_params *bsp)
{
bsp->lastev = BSE_UNINSTALL;
- thread_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
+ event_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
}
enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp)
@@ -890,11 +890,11 @@ int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS)
bsp->installed = false;
/* Cancel any pending installation request. */
- THREAD_OFF(bsp->installev);
+ EVENT_OFF(bsp->installev);
/* Ask for installation. */
bsp->lastev = BSE_INSTALL;
- thread_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
+ event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
}
return 0;
@@ -1039,7 +1039,7 @@ static int bfd_protocol_integration_finish(void)
return 0;
}
-void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
+void bfd_protocol_integration_init(struct zclient *zc, struct event_loop *tm)
{
/* Initialize data structure. */
TAILQ_INIT(&bsglobal.bsplist);
diff --git a/lib/bfd.h b/lib/bfd.h
index 66c08cde74..bfa5287340 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -348,7 +348,7 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
* Initializes the BFD integration library. This function executes the
* following actions:
*
- * - Copy the `struct thread_master` pointer to use as "thread" to execute
+ * - Copy the `struct event_loop` pointer to use as "thread" to execute
* the BFD session parameters installation.
* - Copy the `struct zclient` pointer to install its callbacks.
* - Initializes internal data structures.
@@ -356,8 +356,7 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
* \param tm normally the daemon main thread event manager.
* \param zc the zebra client of the daemon.
*/
-void bfd_protocol_integration_init(struct zclient *zc,
- struct thread_master *tm);
+void bfd_protocol_integration_init(struct zclient *zc, struct event_loop *tm);
/**
* BFD session registration arguments.
diff --git a/lib/command.c b/lib/command.c
index 196d73d46a..97ea200ff4 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -17,7 +17,7 @@
#include "memory.h"
#include "log.h"
#include "log_vty.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vector.h"
#include "linklist.h"
#include "vty.h"
@@ -2542,7 +2542,7 @@ void cmd_init(int terminal)
install_default(CONFIG_NODE);
- thread_cmd_init();
+ event_cmd_init();
workqueue_cmd_init();
hash_cmd_init();
}
diff --git a/lib/thread.c b/lib/event.c
index 87ad3d8823..a8eb89f48d 100644
--- a/lib/thread.c
+++ b/lib/event.c
@@ -8,7 +8,7 @@
#include <zebra.h>
#include <sys/resource.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "frrcu.h"
#include "log.h"
@@ -24,23 +24,23 @@
#include "libfrr.h"
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread");
-DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master");
-DEFINE_MTYPE_STATIC(LIB, THREAD_POLL, "Thread Poll Info");
-DEFINE_MTYPE_STATIC(LIB, THREAD_STATS, "Thread stats");
+DEFINE_MTYPE_STATIC(LIB, EVENT_MASTER, "Thread master");
+DEFINE_MTYPE_STATIC(LIB, EVENT_POLL, "Thread Poll Info");
+DEFINE_MTYPE_STATIC(LIB, EVENT_STATS, "Thread stats");
-DECLARE_LIST(thread_list, struct thread, threaditem);
+DECLARE_LIST(event_list, struct event, eventitem);
struct cancel_req {
int flags;
- struct thread *thread;
+ struct event *thread;
void *eventobj;
- struct thread **threadref;
+ struct event **threadref;
};
/* Flags for task cancellation */
-#define THREAD_CANCEL_FLAG_READY 0x01
+#define EVENT_CANCEL_FLAG_READY 0x01
-static int thread_timer_cmp(const struct thread *a, const struct thread *b)
+static int event_timer_cmp(const struct event *a, const struct event *b)
{
if (a->u.sands.tv_sec < b->u.sands.tv_sec)
return -1;
@@ -53,7 +53,7 @@ static int thread_timer_cmp(const struct thread *a, const struct thread *b)
return 0;
}
-DECLARE_HEAP(thread_timer_list, struct thread, timeritem, thread_timer_cmp);
+DECLARE_HEAP(event_timer_list, struct event, timeritem, event_timer_cmp);
#if defined(__APPLE__)
#include <mach/mach.h>
@@ -64,7 +64,7 @@ DECLARE_HEAP(thread_timer_list, struct thread, timeritem, thread_timer_cmp);
do { \
const unsigned char wakebyte = 0x01; \
write(m->io_pipe[1], &wakebyte, 1); \
- } while (0);
+ } while (0)
/* control variable for initializer */
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
@@ -73,7 +73,7 @@ pthread_key_t thread_current;
static pthread_mutex_t masters_mtx = PTHREAD_MUTEX_INITIALIZER;
static struct list *masters;
-static void thread_free(struct thread_master *master, struct thread *thread);
+static void thread_free(struct event_loop *master, struct event *thread);
#ifndef EXCLUDE_CPU_TIME
#define EXCLUDE_CPU_TIME 0
@@ -87,25 +87,26 @@ unsigned long cputime_threshold = CONSUMED_TIME_CHECK;
unsigned long walltime_threshold = CONSUMED_TIME_CHECK;
/* CLI start ---------------------------------------------------------------- */
-#include "lib/thread_clippy.c"
+#include "lib/event_clippy.c"
-static unsigned int cpu_record_hash_key(const struct cpu_thread_history *a)
+static unsigned int cpu_record_hash_key(const struct cpu_event_history *a)
{
int size = sizeof(a->func);
return jhash(&a->func, size, 0);
}
-static bool cpu_record_hash_cmp(const struct cpu_thread_history *a,
- const struct cpu_thread_history *b)
+static bool cpu_record_hash_cmp(const struct cpu_event_history *a,
+ const struct cpu_event_history *b)
{
return a->func == b->func;
}
-static void *cpu_record_hash_alloc(struct cpu_thread_history *a)
+static void *cpu_record_hash_alloc(struct cpu_event_history *a)
{
- struct cpu_thread_history *new;
- new = XCALLOC(MTYPE_THREAD_STATS, sizeof(struct cpu_thread_history));
+ struct cpu_event_history *new;
+
+ new = XCALLOC(MTYPE_EVENT_STATS, sizeof(struct cpu_event_history));
new->func = a->func;
new->funcname = a->funcname;
return new;
@@ -113,13 +114,13 @@ static void *cpu_record_hash_alloc(struct cpu_thread_history *a)
static void cpu_record_hash_free(void *a)
{
- struct cpu_thread_history *hist = a;
+ struct cpu_event_history *hist = a;
- XFREE(MTYPE_THREAD_STATS, hist);
+ XFREE(MTYPE_EVENT_STATS, hist);
}
-static void vty_out_cpu_thread_history(struct vty *vty,
- struct cpu_thread_history *a)
+static void vty_out_cpu_event_history(struct vty *vty,
+ struct cpu_event_history *a)
{
vty_out(vty,
"%5zu %10zu.%03zu %9zu %8zu %9zu %8zu %9zu %9zu %9zu %10zu",
@@ -128,21 +129,21 @@ static void vty_out_cpu_thread_history(struct vty *vty,
(a->real.total / a->total_calls), a->real.max,
a->total_cpu_warn, a->total_wall_warn, a->total_starv_warn);
vty_out(vty, " %c%c%c%c%c %s\n",
- a->types & (1 << THREAD_READ) ? 'R' : ' ',
- a->types & (1 << THREAD_WRITE) ? 'W' : ' ',
- a->types & (1 << THREAD_TIMER) ? 'T' : ' ',
- a->types & (1 << THREAD_EVENT) ? 'E' : ' ',
- a->types & (1 << THREAD_EXECUTE) ? 'X' : ' ', a->funcname);
+ a->types & (1 << EVENT_READ) ? 'R' : ' ',
+ a->types & (1 << EVENT_WRITE) ? 'W' : ' ',
+ a->types & (1 << EVENT_TIMER) ? 'T' : ' ',
+ a->types & (1 << EVENT_EVENT) ? 'E' : ' ',
+ a->types & (1 << EVENT_EXECUTE) ? 'X' : ' ', a->funcname);
}
static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
{
- struct cpu_thread_history *totals = args[0];
- struct cpu_thread_history copy;
+ struct cpu_event_history *totals = args[0];
+ struct cpu_event_history copy;
struct vty *vty = args[1];
uint8_t *filter = args[2];
- struct cpu_thread_history *a = bucket->data;
+ struct cpu_event_history *a = bucket->data;
copy.total_active =
atomic_load_explicit(&a->total_active, memory_order_seq_cst);
@@ -167,7 +168,7 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
if (!(copy.types & *filter))
return;
- vty_out_cpu_thread_history(vty, &copy);
+ vty_out_cpu_event_history(vty, &copy);
totals->total_active += copy.total_active;
totals->total_calls += copy.total_calls;
totals->total_cpu_warn += copy.total_cpu_warn;
@@ -183,9 +184,9 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
static void cpu_record_print(struct vty *vty, uint8_t filter)
{
- struct cpu_thread_history tmp;
+ struct cpu_event_history tmp;
void *args[3] = {&tmp, vty, &filter};
- struct thread_master *m;
+ struct event_loop *m;
struct listnode *ln;
if (!cputime_enabled)
@@ -203,8 +204,8 @@ static void cpu_record_print(struct vty *vty, uint8_t filter)
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
const char *name = m->name ? m->name : "main";
-
char underline[strlen(name) + 1];
+
memset(underline, '-', sizeof(underline));
underline[sizeof(underline) - 1] = '\0';
@@ -244,7 +245,7 @@ static void cpu_record_print(struct vty *vty, uint8_t filter)
vty_out(vty, " Type Thread\n");
if (tmp.total_calls > 0)
- vty_out_cpu_thread_history(vty, &tmp);
+ vty_out_cpu_event_history(vty, &tmp);
}
static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
@@ -252,7 +253,7 @@ static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
uint8_t *filter = args[0];
struct hash *cpu_record = args[1];
- struct cpu_thread_history *a = bucket->data;
+ struct cpu_event_history *a = bucket->data;
if (!(a->types & *filter))
return;
@@ -263,13 +264,14 @@ static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
static void cpu_record_clear(uint8_t filter)
{
uint8_t *tmp = &filter;
- struct thread_master *m;
+ struct event_loop *m;
struct listnode *ln;
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
frr_with_mutex (&m->mtx) {
void *args[2] = {tmp, m->cpu_record};
+
hash_iterate(
m->cpu_record,
(void (*)(struct hash_bucket *,
@@ -289,23 +291,23 @@ static uint8_t parse_filter(const char *filterstr)
switch (filterstr[i]) {
case 'r':
case 'R':
- filter |= (1 << THREAD_READ);
+ filter |= (1 << EVENT_READ);
break;
case 'w':
case 'W':
- filter |= (1 << THREAD_WRITE);
+ filter |= (1 << EVENT_WRITE);
break;
case 't':
case 'T':
- filter |= (1 << THREAD_TIMER);
+ filter |= (1 << EVENT_TIMER);
break;
case 'e':
case 'E':
- filter |= (1 << THREAD_EVENT);
+ filter |= (1 << EVENT_EVENT);
break;
case 'x':
case 'X':
- filter |= (1 << THREAD_EXECUTE);
+ filter |= (1 << EVENT_EXECUTE);
break;
default:
break;
@@ -395,11 +397,11 @@ ALIAS (service_walltime_warning,
"Set up miscellaneous service\n"
"Warn for tasks exceeding total wallclock threshold\n")
-static void show_thread_poll_helper(struct vty *vty, struct thread_master *m)
+static void show_thread_poll_helper(struct vty *vty, struct event_loop *m)
{
const char *name = m->name ? m->name : "main";
char underline[strlen(name) + 1];
- struct thread *thread;
+ struct event *thread;
uint32_t i;
memset(underline, '-', sizeof(underline));
@@ -444,12 +446,11 @@ DEFUN_NOSH (show_thread_poll,
"Show poll FD's and information\n")
{
struct listnode *node;
- struct thread_master *m;
+ struct event_loop *m;
frr_with_mutex (&masters_mtx) {
- for (ALL_LIST_ELEMENTS_RO(masters, node, m)) {
+ for (ALL_LIST_ELEMENTS_RO(masters, node, m))
show_thread_poll_helper(vty, m);
- }
}
return CMD_SUCCESS;
@@ -481,11 +482,11 @@ DEFUN (clear_thread_cpu,
return CMD_SUCCESS;
}
-static void show_thread_timers_helper(struct vty *vty, struct thread_master *m)
+static void show_thread_timers_helper(struct vty *vty, struct event_loop *m)
{
const char *name = m->name ? m->name : "main";
char underline[strlen(name) + 1];
- struct thread *thread;
+ struct event *thread;
memset(underline, '-', sizeof(underline));
underline[sizeof(underline) - 1] = '\0';
@@ -493,7 +494,7 @@ static void show_thread_timers_helper(struct vty *vty, struct thread_master *m)
vty_out(vty, "\nShowing timers for %s\n", name);
vty_out(vty, "-------------------%s\n", underline);
- frr_each (thread_timer_list, &m->timer, thread) {
+ frr_each (event_timer_list, &m->timer, thread) {
vty_out(vty, " %-50s%pTH\n", thread->hist->funcname, thread);
}
}
@@ -506,7 +507,7 @@ DEFPY_NOSH (show_thread_timers,
"Show all timers and how long they have in the system\n")
{
struct listnode *node;
- struct thread_master *m;
+ struct event_loop *m;
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, node, m))
@@ -516,7 +517,7 @@ DEFPY_NOSH (show_thread_timers,
return CMD_SUCCESS;
}
-void thread_cmd_init(void)
+void event_cmd_init(void)
{
install_element(VIEW_NODE, &show_thread_cpu_cmd);
install_element(VIEW_NODE, &show_thread_poll_cmd);
@@ -544,14 +545,14 @@ static void initializer(void)
pthread_key_create(&thread_current, NULL);
}
-struct thread_master *thread_master_create(const char *name)
+struct event_loop *event_master_create(const char *name)
{
- struct thread_master *rv;
+ struct event_loop *rv;
struct rlimit limit;
pthread_once(&init_once, &initializer);
- rv = XCALLOC(MTYPE_THREAD_MASTER, sizeof(struct thread_master));
+ rv = XCALLOC(MTYPE_EVENT_MASTER, sizeof(struct event_loop));
/* Initialize master mutex */
pthread_mutex_init(&rv->mtx, NULL);
@@ -559,7 +560,7 @@ struct thread_master *thread_master_create(const char *name)
/* Set name */
name = name ? name : "default";
- rv->name = XSTRDUP(MTYPE_THREAD_MASTER, name);
+ rv->name = XSTRDUP(MTYPE_EVENT_MASTER, name);
/* Initialize I/O task data structures */
@@ -570,13 +571,14 @@ struct thread_master *thread_master_create(const char *name)
rv->fd_limit = (int)limit.rlim_cur;
}
- rv->read = XCALLOC(MTYPE_THREAD_POLL,
- sizeof(struct thread *) * rv->fd_limit);
+ rv->read = XCALLOC(MTYPE_EVENT_POLL,
+ sizeof(struct event *) * rv->fd_limit);
- rv->write = XCALLOC(MTYPE_THREAD_POLL,
- sizeof(struct thread *) * rv->fd_limit);
+ rv->write = XCALLOC(MTYPE_EVENT_POLL,
+ sizeof(struct event *) * rv->fd_limit);
char tmhashname[strlen(name) + 32];
+
snprintf(tmhashname, sizeof(tmhashname), "%s - threadmaster event hash",
name);
rv->cpu_record = hash_create_size(
@@ -584,12 +586,12 @@ struct thread_master *thread_master_create(const char *name)
(bool (*)(const void *, const void *))cpu_record_hash_cmp,
tmhashname);
- thread_list_init(&rv->event);
- thread_list_init(&rv->ready);
- thread_list_init(&rv->unuse);
- thread_timer_list_init(&rv->timer);
+ event_list_init(&rv->event);
+ event_list_init(&rv->ready);
+ event_list_init(&rv->unuse);
+ event_timer_list_init(&rv->timer);
- /* Initialize thread_fetch() settings */
+ /* Initialize event_fetch() settings */
rv->spin = true;
rv->handle_signals = true;
@@ -607,9 +609,9 @@ struct thread_master *thread_master_create(const char *name)
/* Initialize data structures for poll() */
rv->handler.pfdsize = rv->fd_limit;
rv->handler.pfdcount = 0;
- rv->handler.pfds = XCALLOC(MTYPE_THREAD_MASTER,
+ rv->handler.pfds = XCALLOC(MTYPE_EVENT_MASTER,
sizeof(struct pollfd) * rv->handler.pfdsize);
- rv->handler.copy = XCALLOC(MTYPE_THREAD_MASTER,
+ rv->handler.copy = XCALLOC(MTYPE_EVENT_MASTER,
sizeof(struct pollfd) * rv->handler.pfdsize);
/* add to list of threadmasters */
@@ -623,32 +625,32 @@ struct thread_master *thread_master_create(const char *name)
return rv;
}
-void thread_master_set_name(struct thread_master *master, const char *name)
+void event_master_set_name(struct event_loop *master, const char *name)
{
frr_with_mutex (&master->mtx) {
- XFREE(MTYPE_THREAD_MASTER, master->name);
- master->name = XSTRDUP(MTYPE_THREAD_MASTER, name);
+ XFREE(MTYPE_EVENT_MASTER, master->name);
+ master->name = XSTRDUP(MTYPE_EVENT_MASTER, name);
}
}
-#define THREAD_UNUSED_DEPTH 10
+#define EVENT_UNUSED_DEPTH 10
/* Move thread to unuse list. */
-static void thread_add_unuse(struct thread_master *m, struct thread *thread)
+static void thread_add_unuse(struct event_loop *m, struct event *thread)
{
pthread_mutex_t mtxc = thread->mtx;
assert(m != NULL && thread != NULL);
thread->hist->total_active--;
- memset(thread, 0, sizeof(struct thread));
- thread->type = THREAD_UNUSED;
+ memset(thread, 0, sizeof(struct event));
+ thread->type = EVENT_UNUSED;
/* Restore the thread mutex context. */
thread->mtx = mtxc;
- if (thread_list_count(&m->unuse) < THREAD_UNUSED_DEPTH) {
- thread_list_add_tail(&m->unuse, thread);
+ if (event_list_count(&m->unuse) < EVENT_UNUSED_DEPTH) {
+ event_list_add_tail(&m->unuse, thread);
return;
}
@@ -656,19 +658,17 @@ static void thread_add_unuse(struct thread_master *m, struct thread *thread)
}
/* Free all unused thread. */
-static void thread_list_free(struct thread_master *m,
- struct thread_list_head *list)
+static void thread_list_free(struct event_loop *m, struct event_list_head *list)
{
- struct thread *t;
+ struct event *t;
- while ((t = thread_list_pop(list)))
+ while ((t = event_list_pop(list)))
thread_free(m, t);
}
-static void thread_array_free(struct thread_master *m,
- struct thread **thread_array)
+static void thread_array_free(struct event_loop *m, struct event **thread_array)
{
- struct thread *t;
+ struct event *t;
int index;
for (index = 0; index < m->fd_limit; ++index) {
@@ -678,41 +678,41 @@ static void thread_array_free(struct thread_master *m,
thread_free(m, t);
}
}
- XFREE(MTYPE_THREAD_POLL, thread_array);
+ XFREE(MTYPE_EVENT_POLL, thread_array);
}
/*
- * thread_master_free_unused
+ * event_master_free_unused
*
* As threads are finished with they are put on the
* unuse list for later reuse.
* If we are shutting down, Free up unused threads
* So we can see if we forget to shut anything off
*/
-void thread_master_free_unused(struct thread_master *m)
+void event_master_free_unused(struct event_loop *m)
{
frr_with_mutex (&m->mtx) {
- struct thread *t;
- while ((t = thread_list_pop(&m->unuse)))
+ struct event *t;
+
+ while ((t = event_list_pop(&m->unuse)))
thread_free(m, t);
}
}
/* Stop thread scheduler. */
-void thread_master_free(struct thread_master *m)
+void event_master_free(struct event_loop *m)
{
- struct thread *t;
+ struct event *t;
frr_with_mutex (&masters_mtx) {
listnode_delete(masters, m);
- if (masters->count == 0) {
+ if (masters->count == 0)
list_delete(&masters);
- }
}
thread_array_free(m, m->read);
thread_array_free(m, m->write);
- while ((t = thread_timer_list_pop(&m->timer)))
+ while ((t = event_timer_list_pop(&m->timer)))
thread_free(m, t);
thread_list_free(m, &m->event);
thread_list_free(m, &m->ready);
@@ -726,18 +726,18 @@ void thread_master_free(struct thread_master *m)
hash_clean_and_free(&m->cpu_record, cpu_record_hash_free);
- XFREE(MTYPE_THREAD_MASTER, m->name);
- XFREE(MTYPE_THREAD_MASTER, m->handler.pfds);
- XFREE(MTYPE_THREAD_MASTER, m->handler.copy);
- XFREE(MTYPE_THREAD_MASTER, m);
+ XFREE(MTYPE_EVENT_MASTER, m->name);
+ XFREE(MTYPE_EVENT_MASTER, m->handler.pfds);
+ XFREE(MTYPE_EVENT_MASTER, m->handler.copy);
+ XFREE(MTYPE_EVENT_MASTER, m);
}
/* Return remain time in milliseconds. */
-unsigned long thread_timer_remain_msec(struct thread *thread)
+unsigned long event_timer_remain_msec(struct event *thread)
{
int64_t remain;
- if (!thread_is_scheduled(thread))
+ if (!event_is_scheduled(thread))
return 0;
frr_with_mutex (&thread->mtx) {
@@ -748,14 +748,15 @@ unsigned long thread_timer_remain_msec(struct thread *thread)
}
/* Return remain time in seconds. */
-unsigned long thread_timer_remain_second(struct thread *thread)
+unsigned long event_timer_remain_second(struct event *thread)
{
- return thread_timer_remain_msec(thread) / 1000LL;
+ return event_timer_remain_msec(thread) / 1000LL;
}
-struct timeval thread_timer_remain(struct thread *thread)
+struct timeval event_timer_remain(struct event *thread)
{
struct timeval remain;
+
frr_with_mutex (&thread->mtx) {
monotime_until(&thread->u.sands, &remain);
}
@@ -780,28 +781,26 @@ static int time_hhmmss(char *buf, int buf_size, long sec)
return wr != 8;
}
-char *thread_timer_to_hhmmss(char *buf, int buf_size,
- struct thread *t_timer)
+char *event_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer)
{
- if (t_timer) {
- time_hhmmss(buf, buf_size,
- thread_timer_remain_second(t_timer));
- } else {
+ if (t_timer)
+ time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer));
+ else
snprintf(buf, buf_size, "--:--:--");
- }
+
return buf;
}
/* Get new thread. */
-static struct thread *thread_get(struct thread_master *m, uint8_t type,
- void (*func)(struct thread *), void *arg,
- const struct xref_threadsched *xref)
+static struct event *thread_get(struct event_loop *m, uint8_t type,
+ void (*func)(struct event *), void *arg,
+ const struct xref_eventsched *xref)
{
- struct thread *thread = thread_list_pop(&m->unuse);
- struct cpu_thread_history tmp;
+ struct event *thread = event_list_pop(&m->unuse);
+ struct cpu_event_history tmp;
if (!thread) {
- thread = XCALLOC(MTYPE_THREAD, sizeof(struct thread));
+ thread = XCALLOC(MTYPE_THREAD, sizeof(struct event));
/* mutex only needs to be initialized at struct creation. */
pthread_mutex_init(&thread->mtx, NULL);
m->alloc++;
@@ -811,7 +810,7 @@ static struct thread *thread_get(struct thread_master *m, uint8_t type,
thread->add_type = type;
thread->master = m;
thread->arg = arg;
- thread->yield = THREAD_YIELD_TIME_SLOT; /* default */
+ thread->yield = EVENT_YIELD_TIME_SLOT; /* default */
thread->ref = NULL;
thread->ignore_timer_late = false;
@@ -840,7 +839,7 @@ static struct thread *thread_get(struct thread_master *m, uint8_t type,
return thread;
}
-static void thread_free(struct thread_master *master, struct thread *thread)
+static void thread_free(struct event_loop *master, struct event *thread)
{
/* Update statistics. */
assert(master->alloc > 0);
@@ -851,7 +850,7 @@ static void thread_free(struct thread_master *master, struct thread *thread)
XFREE(MTYPE_THREAD, thread);
}
-static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
+static int fd_poll(struct event_loop *m, const struct timeval *timer_wait,
bool *eintr_p)
{
sigset_t origsigs;
@@ -860,7 +859,7 @@ static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
/*
* If timer_wait is null here, that means poll() should block
- * indefinitely, unless the thread_master has overridden it by setting
+ * indefinitely, unless the event_master has overridden it by setting
* ->selectpoll_timeout.
*
* If the value is positive, it specifies the maximum number of
@@ -873,15 +872,17 @@ static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
/* number of file descriptors with events */
int num;
- if (timer_wait != NULL
- && m->selectpoll_timeout == 0) // use the default value
+ if (timer_wait != NULL && m->selectpoll_timeout == 0) {
+ /* use the default value */
timeout = (timer_wait->tv_sec * 1000)
+ (timer_wait->tv_usec / 1000);
- else if (m->selectpoll_timeout > 0) // use the user's timeout
+ } else if (m->selectpoll_timeout > 0) {
+ /* use the user's timeout */
timeout = m->selectpoll_timeout;
- else if (m->selectpoll_timeout
- < 0) // effect a poll (return immediately)
+ } else if (m->selectpoll_timeout < 0) {
+ /* effect a poll (return immediately) */
timeout = 0;
+ }
zlog_tls_buffer_flush();
rcu_read_unlock();
@@ -949,16 +950,15 @@ done:
}
/* Add new read thread. */
-void _thread_add_read_write(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg, int fd,
- struct thread **t_ptr)
+void _event_add_read_write(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, int fd, struct event **t_ptr)
{
- int dir = xref->thread_type;
- struct thread *thread = NULL;
- struct thread **thread_array;
+ int dir = xref->event_type;
+ struct event *thread = NULL;
+ struct event **thread_array;
- if (dir == THREAD_READ)
+ if (dir == EVENT_READ)
frrtrace(9, frr_libfrr, schedule_read, m,
xref->funcname, xref->xref.file, xref->xref.line,
t_ptr, fd, 0, arg, 0);
@@ -972,20 +972,22 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
assert(!"Number of FD's open is greater than FRR currently configured to handle, aborting");
frr_with_mutex (&m->mtx) {
+ /* Thread is already scheduled; don't reschedule */
if (t_ptr && *t_ptr)
- // thread is already scheduled; don't reschedule
break;
/* default to a new pollfd */
nfds_t queuepos = m->handler.pfdcount;
- if (dir == THREAD_READ)
+ if (dir == EVENT_READ)
thread_array = m->read;
else
thread_array = m->write;
- /* if we already have a pollfd for our file descriptor, find and
- * use it */
+ /*
+ * if we already have a pollfd for our file descriptor, find and
+ * use it
+ */
for (nfds_t i = 0; i < m->handler.pfdcount; i++)
if (m->handler.pfds[i].fd == fd) {
queuepos = i;
@@ -1008,7 +1010,7 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
m->handler.pfds[queuepos].fd = fd;
m->handler.pfds[queuepos].events |=
- (dir == THREAD_READ ? POLLIN : POLLOUT);
+ (dir == EVENT_READ ? POLLIN : POLLOUT);
if (queuepos == m->handler.pfdcount)
m->handler.pfdcount++;
@@ -1029,13 +1031,13 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
}
}
-static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- struct timeval *time_relative,
- struct thread **t_ptr)
+static void _event_add_timer_timeval(const struct xref_eventsched *xref,
+ struct event_loop *m,
+ void (*func)(struct event *), void *arg,
+ struct timeval *time_relative,
+ struct event **t_ptr)
{
- struct thread *thread;
+ struct event *thread;
struct timeval t;
assert(m != NULL);
@@ -1055,11 +1057,11 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
/* thread is already scheduled; don't reschedule */
return;
- thread = thread_get(m, THREAD_TIMER, func, arg, xref);
+ thread = thread_get(m, EVENT_TIMER, func, arg, xref);
frr_with_mutex (&thread->mtx) {
thread->u.sands = t;
- thread_timer_list_add(&m->timer, thread);
+ event_timer_list_add(&m->timer, thread);
if (t_ptr) {
*t_ptr = thread;
thread->ref = t_ptr;
@@ -1070,7 +1072,7 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
* might change the time we'll wait for, give the pthread
* a chance to re-compute.
*/
- if (thread_timer_list_first(&m->timer) == thread)
+ if (event_timer_list_first(&m->timer) == thread)
AWAKEN(m);
}
#define ONEYEAR2SEC (60 * 60 * 24 * 365)
@@ -1083,9 +1085,9 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
/* Add timer event thread. */
-void _thread_add_timer(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, long timer, struct thread **t_ptr)
+void _event_add_timer(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, long timer,
+ struct event **t_ptr)
{
struct timeval trel;
@@ -1094,14 +1096,13 @@ void _thread_add_timer(const struct xref_threadsched *xref,
trel.tv_sec = timer;
trel.tv_usec = 0;
- _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "millisecond" resolution */
-void _thread_add_timer_msec(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- long timer, struct thread **t_ptr)
+void _event_add_timer_msec(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, long timer, struct event **t_ptr)
{
struct timeval trel;
@@ -1110,24 +1111,23 @@ void _thread_add_timer_msec(const struct xref_threadsched *xref,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000 * (timer % 1000);
- _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "timeval" resolution */
-void _thread_add_timer_tv(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- struct timeval *tv, struct thread **t_ptr)
+void _event_add_timer_tv(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, struct timeval *tv, struct event **t_ptr)
{
- _thread_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
}
/* Add simple event thread. */
-void _thread_add_event(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, int val, struct thread **t_ptr)
+void _event_add_event(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, int val,
+ struct event **t_ptr)
{
- struct thread *thread = NULL;
+ struct event *thread = NULL;
frrtrace(9, frr_libfrr, schedule_event, m,
xref->funcname, xref->xref.file, xref->xref.line,
@@ -1140,10 +1140,10 @@ void _thread_add_event(const struct xref_threadsched *xref,
/* thread is already scheduled; don't reschedule */
break;
- thread = thread_get(m, THREAD_EVENT, func, arg, xref);
+ thread = thread_get(m, EVENT_EVENT, func, arg, xref);
frr_with_mutex (&thread->mtx) {
thread->u.val = val;
- thread_list_add_tail(&m->event, thread);
+ event_list_add_tail(&m->event, thread);
}
if (t_ptr) {
@@ -1161,7 +1161,7 @@ void _thread_add_event(const struct xref_threadsched *xref,
* NOT's out the .events field of pollfd corresponding to the given file
* descriptor. The event to be NOT'd is passed in the 'state' parameter.
*
- * This needs to happen for both copies of pollfd's. See 'thread_fetch'
+ * This needs to happen for both copies of pollfd's. See 'event_fetch'
* implementation for details.
*
* @param master
@@ -1171,8 +1171,8 @@ void _thread_add_event(const struct xref_threadsched *xref,
* - POLLIN
* - POLLOUT
*/
-static void thread_cancel_rw(struct thread_master *master, int fd, short state,
- int idx_hint)
+static void event_cancel_rw(struct event_loop *master, int fd, short state,
+ int idx_hint)
{
bool found = false;
@@ -1216,8 +1216,10 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
master->handler.pfds[master->handler.pfdcount].events = 0;
}
- /* If we have the same pollfd in the copy, perform the same operations,
- * otherwise return. */
+ /*
+ * If we have the same pollfd in the copy, perform the same operations,
+ * otherwise return.
+ */
if (i >= master->handler.copycount)
return;
@@ -1229,7 +1231,7 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
* sizeof(struct pollfd));
master->handler.copycount--;
master->handler.copy[master->handler.copycount].fd = 0;
- master->handler.copy[master->handler.copycount].events = 0;
+ master->handler.copy[master->handler.copycount].events = 0;
}
}
@@ -1237,10 +1239,10 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
* Process task cancellation given a task argument: iterate through the
* various lists of tasks, looking for any that match the argument.
*/
-static void cancel_arg_helper(struct thread_master *master,
+static void cancel_arg_helper(struct event_loop *master,
const struct cancel_req *cr)
{
- struct thread *t;
+ struct event *t;
nfds_t i;
int fd;
struct pollfd *pfd;
@@ -1250,26 +1252,26 @@ static void cancel_arg_helper(struct thread_master *master,
return;
/* First process the ready lists. */
- frr_each_safe(thread_list, &master->event, t) {
+ frr_each_safe (event_list, &master->event, t) {
if (t->arg != cr->eventobj)
continue;
- thread_list_del(&master->event, t);
+ event_list_del(&master->event, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
}
- frr_each_safe(thread_list, &master->ready, t) {
+ frr_each_safe (event_list, &master->ready, t) {
if (t->arg != cr->eventobj)
continue;
- thread_list_del(&master->ready, t);
+ event_list_del(&master->ready, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
}
/* If requested, stop here and ignore io and timers */
- if (CHECK_FLAG(cr->flags, THREAD_CANCEL_FLAG_READY))
+ if (CHECK_FLAG(cr->flags, EVENT_CANCEL_FLAG_READY))
return;
/* Check the io tasks */
@@ -1285,7 +1287,7 @@ static void cancel_arg_helper(struct thread_master *master,
fd = pfd->fd;
/* Found a match to cancel: clean up fd arrays */
- thread_cancel_rw(master, pfd->fd, pfd->events, i);
+ event_cancel_rw(master, pfd->fd, pfd->events, i);
/* Clean up thread arrays */
master->read[fd] = NULL;
@@ -1305,14 +1307,14 @@ static void cancel_arg_helper(struct thread_master *master,
}
/* Check the timer tasks */
- t = thread_timer_list_first(&master->timer);
+ t = event_timer_list_first(&master->timer);
while (t) {
- struct thread *t_next;
+ struct event *t_next;
- t_next = thread_timer_list_next(&master->timer, t);
+ t_next = event_timer_list_next(&master->timer, t);
if (t->arg == cr->eventobj) {
- thread_timer_list_del(&master->timer, t);
+ event_timer_list_del(&master->timer, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
@@ -1325,16 +1327,16 @@ static void cancel_arg_helper(struct thread_master *master,
/**
* Process cancellation requests.
*
- * This may only be run from the pthread which owns the thread_master.
+ * This may only be run from the pthread which owns the event_master.
*
* @param master the thread master to process
* @REQUIRE master->mtx
*/
-static void do_thread_cancel(struct thread_master *master)
+static void do_event_cancel(struct event_loop *master)
{
- struct thread_list_head *list = NULL;
- struct thread **thread_array = NULL;
- struct thread *thread;
+ struct event_list_head *list = NULL;
+ struct event **thread_array = NULL;
+ struct event *thread;
struct cancel_req *cr;
struct listnode *ln;
@@ -1365,33 +1367,33 @@ static void do_thread_cancel(struct thread_master *master)
/* Determine the appropriate queue to cancel the thread from */
switch (thread->type) {
- case THREAD_READ:
- thread_cancel_rw(master, thread->u.fd, POLLIN, -1);
+ case EVENT_READ:
+ event_cancel_rw(master, thread->u.fd, POLLIN, -1);
thread_array = master->read;
break;
- case THREAD_WRITE:
- thread_cancel_rw(master, thread->u.fd, POLLOUT, -1);
+ case EVENT_WRITE:
+ event_cancel_rw(master, thread->u.fd, POLLOUT, -1);
thread_array = master->write;
break;
- case THREAD_TIMER:
- thread_timer_list_del(&master->timer, thread);
+ case EVENT_TIMER:
+ event_timer_list_del(&master->timer, thread);
break;
- case THREAD_EVENT:
+ case EVENT_EVENT:
list = &master->event;
break;
- case THREAD_READY:
+ case EVENT_READY:
list = &master->ready;
break;
- default:
+ case EVENT_UNUSED:
+ case EVENT_EXECUTE:
continue;
break;
}
- if (list) {
- thread_list_del(list, thread);
- } else if (thread_array) {
+ if (list)
+ event_list_del(list, thread);
+ else if (thread_array)
thread_array[thread->u.fd] = NULL;
- }
if (thread->ref)
*thread->ref = NULL;
@@ -1403,7 +1405,7 @@ static void do_thread_cancel(struct thread_master *master)
if (master->cancel_req)
list_delete_all_node(master->cancel_req);
- /* Wake up any threads which may be blocked in thread_cancel_async() */
+ /* Wake up any threads which may be blocked in event_cancel_async() */
master->canceled = true;
pthread_cond_broadcast(&master->cancel_cond);
}
@@ -1411,7 +1413,7 @@ static void do_thread_cancel(struct thread_master *master)
/*
* Helper function used for multiple flavors of arg-based cancellation.
*/
-static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
+static void cancel_event_helper(struct event_loop *m, void *arg, int flags)
{
struct cancel_req *cr;
@@ -1428,7 +1430,7 @@ static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
frr_with_mutex (&m->mtx) {
cr->eventobj = arg;
listnode_add(m->cancel_req, cr);
- do_thread_cancel(m);
+ do_event_cancel(m);
}
}
@@ -1437,10 +1439,10 @@ static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
*
* MT-Unsafe
*
- * @param m the thread_master to cancel from
+ * @param m the event_master to cancel from
* @param arg the argument passed when creating the event
*/
-void thread_cancel_event(struct thread_master *master, void *arg)
+void event_cancel_event(struct event_loop *master, void *arg)
{
cancel_event_helper(master, arg, 0);
}
@@ -1450,14 +1452,14 @@ void thread_cancel_event(struct thread_master *master, void *arg)
*
* MT-Unsafe
*
- * @param m the thread_master to cancel from
+ * @param m the event_master to cancel from
* @param arg the argument passed when creating the event
*/
-void thread_cancel_event_ready(struct thread_master *m, void *arg)
+void event_cancel_event_ready(struct event_loop *m, void *arg)
{
/* Only cancel ready/event tasks */
- cancel_event_helper(m, arg, THREAD_CANCEL_FLAG_READY);
+ cancel_event_helper(m, arg, EVENT_CANCEL_FLAG_READY);
}
/**
@@ -1467,19 +1469,19 @@ void thread_cancel_event_ready(struct thread_master *m, void *arg)
*
* @param thread task to cancel
*/
-void thread_cancel(struct thread **thread)
+void event_cancel(struct event **thread)
{
- struct thread_master *master;
+ struct event_loop *master;
if (thread == NULL || *thread == NULL)
return;
master = (*thread)->master;
- frrtrace(9, frr_libfrr, thread_cancel, master,
- (*thread)->xref->funcname, (*thread)->xref->xref.file,
- (*thread)->xref->xref.line, NULL, (*thread)->u.fd,
- (*thread)->u.val, (*thread)->arg, (*thread)->u.sands.tv_sec);
+ frrtrace(9, frr_libfrr, event_cancel, master, (*thread)->xref->funcname,
+ (*thread)->xref->xref.file, (*thread)->xref->xref.line, NULL,
+ (*thread)->u.fd, (*thread)->u.val, (*thread)->arg,
+ (*thread)->u.sands.tv_sec);
assert(master->owner == pthread_self());
@@ -1488,7 +1490,7 @@ void thread_cancel(struct thread **thread)
XCALLOC(MTYPE_TMP, sizeof(struct cancel_req));
cr->thread = *thread;
listnode_add(master->cancel_req, cr);
- do_thread_cancel(master);
+ do_event_cancel(master);
}
*thread = NULL;
@@ -1497,7 +1499,7 @@ void thread_cancel(struct thread **thread)
/**
* Asynchronous cancellation.
*
- * Called with either a struct thread ** or void * to an event argument,
+ * Called with either a struct event ** or void * to an event argument,
* this function posts the correct cancellation request and blocks until it is
* serviced.
*
@@ -1506,7 +1508,7 @@ void thread_cancel(struct thread **thread)
* The last two parameters are mutually exclusive, i.e. if you pass one the
* other must be NULL.
*
- * When the cancellation procedure executes on the target thread_master, the
+ * When the cancellation procedure executes on the target event_master, the
* thread * provided is checked for nullity. If it is null, the thread is
* assumed to no longer exist and the cancellation request is a no-op. Thus
* users of this API must pass a back-reference when scheduling the original
@@ -1518,19 +1520,19 @@ void thread_cancel(struct thread **thread)
* @param thread pointer to thread to cancel
* @param eventobj the event
*/
-void thread_cancel_async(struct thread_master *master, struct thread **thread,
- void *eventobj)
+void event_cancel_async(struct event_loop *master, struct event **thread,
+ void *eventobj)
{
assert(!(thread && eventobj) && (thread || eventobj));
if (thread && *thread)
- frrtrace(9, frr_libfrr, thread_cancel_async, master,
+ frrtrace(9, frr_libfrr, event_cancel_async, master,
(*thread)->xref->funcname, (*thread)->xref->xref.file,
(*thread)->xref->xref.line, NULL, (*thread)->u.fd,
(*thread)->u.val, (*thread)->arg,
(*thread)->u.sands.tv_sec);
else
- frrtrace(9, frr_libfrr, thread_cancel_async, master, NULL, NULL,
+ frrtrace(9, frr_libfrr, event_cancel_async, master, NULL, NULL,
0, NULL, 0, 0, eventobj, 0);
assert(master->owner != pthread_self());
@@ -1560,30 +1562,30 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
}
/* ------------------------------------------------------------------------- */
-static struct timeval *thread_timer_wait(struct thread_timer_list_head *timers,
+static struct timeval *thread_timer_wait(struct event_timer_list_head *timers,
struct timeval *timer_val)
{
- if (!thread_timer_list_count(timers))
+ if (!event_timer_list_count(timers))
return NULL;
- struct thread *next_timer = thread_timer_list_first(timers);
+ struct event *next_timer = event_timer_list_first(timers);
+
monotime_until(&next_timer->u.sands, timer_val);
return timer_val;
}
-static struct thread *thread_run(struct thread_master *m, struct thread *thread,
- struct thread *fetch)
+static struct event *thread_run(struct event_loop *m, struct event *thread,
+ struct event *fetch)
{
*fetch = *thread;
thread_add_unuse(m, thread);
return fetch;
}
-static int thread_process_io_helper(struct thread_master *m,
- struct thread *thread, short state,
- short actual_state, int pos)
+static int thread_process_io_helper(struct event_loop *m, struct event *thread,
+ short state, short actual_state, int pos)
{
- struct thread **thread_array;
+ struct event **thread_array;
/*
* poll() clears the .events field, but the pollfd array we
@@ -1606,14 +1608,14 @@ static int thread_process_io_helper(struct thread_master *m,
return 0;
}
- if (thread->type == THREAD_READ)
+ if (thread->type == EVENT_READ)
thread_array = m->read;
else
thread_array = m->write;
thread_array[thread->u.fd] = NULL;
- thread_list_add_tail(&m->ready, thread);
- thread->type = THREAD_READY;
+ event_list_add_tail(&m->ready, thread);
+ thread->type = EVENT_READY;
return 1;
}
@@ -1627,7 +1629,7 @@ static int thread_process_io_helper(struct thread_master *m,
* @param m the thread master
* @param num the number of active file descriptors (return value of poll())
*/
-static void thread_process_io(struct thread_master *m, unsigned int num)
+static void thread_process_io(struct event_loop *m, unsigned int num)
{
unsigned int ready = 0;
struct pollfd *pfds = m->handler.copy;
@@ -1640,10 +1642,10 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
ready++;
/*
- * Unless someone has called thread_cancel from another
+ * Unless someone has called event_cancel from another
* pthread, the only thing that could have changed in
* m->handler.pfds while we were asleep is the .events
- * field in a given pollfd. Barring thread_cancel() that
+ * field in a given pollfd. Barring event_cancel() that
* value should be a superset of the values we have in our
* copy, so there's no need to update it. Similarily,
* barring deletion, the fd should still be a valid index
@@ -1661,9 +1663,10 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
thread_process_io_helper(m, m->write[pfds[i].fd],
POLLOUT, pfds[i].revents, i);
- /* if one of our file descriptors is garbage, remove the same
- * from
- * both pfds + update sizes and index */
+ /*
+ * if one of our file descriptors is garbage, remove the same
+ * from both pfds + update sizes and index
+ */
if (pfds[i].revents & POLLNVAL) {
memmove(m->handler.pfds + i, m->handler.pfds + i + 1,
(m->handler.pfdcount - i - 1)
@@ -1685,15 +1688,15 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
}
/* Add all timers that have popped to the ready list. */
-static unsigned int thread_process_timers(struct thread_master *m,
+static unsigned int thread_process_timers(struct event_loop *m,
struct timeval *timenow)
{
struct timeval prev = *timenow;
bool displayed = false;
- struct thread *thread;
+ struct event *thread;
unsigned int ready = 0;
- while ((thread = thread_timer_list_first(&m->timer))) {
+ while ((thread = event_timer_list_first(&m->timer))) {
if (timercmp(timenow, &thread->u.sands, <))
break;
prev = thread->u.sands;
@@ -1717,9 +1720,9 @@ static unsigned int thread_process_timers(struct thread_master *m,
}
}
- thread_timer_list_pop(&m->timer);
- thread->type = THREAD_READY;
- thread_list_add_tail(&m->ready, thread);
+ event_timer_list_pop(&m->timer);
+ thread->type = EVENT_READY;
+ event_list_add_tail(&m->ready, thread);
ready++;
}
@@ -1727,14 +1730,14 @@ static unsigned int thread_process_timers(struct thread_master *m,
}
/* process a list en masse, e.g. for event thread lists */
-static unsigned int thread_process(struct thread_list_head *list)
+static unsigned int thread_process(struct event_list_head *list)
{
- struct thread *thread;
+ struct event *thread;
unsigned int ready = 0;
- while ((thread = thread_list_pop(list))) {
- thread->type = THREAD_READY;
- thread_list_add_tail(&thread->master->ready, thread);
+ while ((thread = event_list_pop(list))) {
+ thread->type = EVENT_READY;
+ event_list_add_tail(&thread->master->ready, thread);
ready++;
}
return ready;
@@ -1742,9 +1745,9 @@ static unsigned int thread_process(struct thread_list_head *list)
/* Fetch next ready thread. */
-struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
+struct event *event_fetch(struct event_loop *m, struct event *fetch)
{
- struct thread *thread = NULL;
+ struct event *thread = NULL;
struct timeval now;
struct timeval zerotime = {0, 0};
struct timeval tv;
@@ -1760,13 +1763,13 @@ struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
pthread_mutex_lock(&m->mtx);
/* Process any pending cancellation requests */
- do_thread_cancel(m);
+ do_event_cancel(m);
/*
* Attempt to flush ready queue before going into poll().
* This is performance-critical. Think twice before modifying.
*/
- if ((thread = thread_list_pop(&m->ready))) {
+ if ((thread = event_list_pop(&m->ready))) {
fetch = thread_run(m, thread, fetch);
if (fetch->ref)
*fetch->ref = NULL;
@@ -1802,11 +1805,11 @@ struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
* In every case except the last, we need to hit poll() at least
* once per loop to avoid starvation by events
*/
- if (!thread_list_count(&m->ready))
+ if (!event_list_count(&m->ready))
tw = thread_timer_wait(&m->timer, &tv);
- if (thread_list_count(&m->ready) ||
- (tw && !timercmp(tw, &zerotime, >)))
+ if (event_list_count(&m->ready) ||
+ (tw && !timercmp(tw, &zerotime, >)))
tw = &zerotime;
if (!tw && m->handler.pfdcount == 0) { /* die */
@@ -1867,8 +1870,8 @@ static unsigned long timeval_elapsed(struct timeval a, struct timeval b)
+ (a.tv_usec - b.tv_usec));
}
-unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
- unsigned long *cputime)
+unsigned long event_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
+ unsigned long *cputime)
{
#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
@@ -1902,19 +1905,22 @@ unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
return timeval_elapsed(now->real, start->real);
}
-/* We should aim to yield after yield milliseconds, which defaults
- to THREAD_YIELD_TIME_SLOT .
- Note: we are using real (wall clock) time for this calculation.
- It could be argued that CPU time may make more sense in certain
- contexts. The things to consider are whether the thread may have
- blocked (in which case wall time increases, but CPU time does not),
- or whether the system is heavily loaded with other processes competing
- for CPU time. On balance, wall clock time seems to make sense.
- Plus it has the added benefit that gettimeofday should be faster
- than calling getrusage. */
-int thread_should_yield(struct thread *thread)
+/*
+ * We should aim to yield after yield milliseconds, which defaults
+ * to EVENT_YIELD_TIME_SLOT .
+ * Note: we are using real (wall clock) time for this calculation.
+ * It could be argued that CPU time may make more sense in certain
+ * contexts. The things to consider are whether the thread may have
+ * blocked (in which case wall time increases, but CPU time does not),
+ * or whether the system is heavily loaded with other processes competing
+ * for CPU time. On balance, wall clock time seems to make sense.
+ * Plus it has the added benefit that gettimeofday should be faster
+ * than calling getrusage.
+ */
+int event_should_yield(struct event *thread)
{
int result;
+
frr_with_mutex (&thread->mtx) {
result = monotime_since(&thread->real, NULL)
> (int64_t)thread->yield;
@@ -1922,14 +1928,14 @@ int thread_should_yield(struct thread *thread)
return result;
}
-void thread_set_yield_time(struct thread *thread, unsigned long yield_time)
+void event_set_yield_time(struct event *thread, unsigned long yield_time)
{
frr_with_mutex (&thread->mtx) {
thread->yield = yield_time;
}
}
-void thread_getrusage(RUSAGE_T *r)
+void event_getrusage(RUSAGE_T *r)
{
monotime(&r->real);
if (!cputime_enabled) {
@@ -1963,7 +1969,7 @@ void thread_getrusage(RUSAGE_T *r)
* particular, the maximum real and cpu times must be monotonically increasing
* or this code is not correct.
*/
-void thread_call(struct thread *thread)
+void event_call(struct event *thread)
{
RUSAGE_T before, after;
@@ -1980,10 +1986,10 @@ void thread_call(struct thread *thread)
thread->real = before.real;
- frrtrace(9, frr_libfrr, thread_call, thread->master,
+ frrtrace(9, frr_libfrr, event_call, thread->master,
thread->xref->funcname, thread->xref->xref.file,
- thread->xref->xref.line, NULL, thread->u.fd,
- thread->u.val, thread->arg, thread->u.sands.tv_sec);
+ thread->xref->xref.line, NULL, thread->u.fd, thread->u.val,
+ thread->arg, thread->u.sands.tv_sec);
pthread_setspecific(thread_current, thread);
(*thread->func)(thread);
@@ -1995,7 +2001,7 @@ void thread_call(struct thread *thread)
unsigned long walltime, cputime;
unsigned long exp;
- walltime = thread_consumed_time(&after, &before, &cputime);
+ walltime = event_consumed_time(&after, &before, &cputime);
/* update walltime */
atomic_fetch_add_explicit(&thread->hist->real.total, walltime,
@@ -2059,26 +2065,25 @@ void thread_call(struct thread *thread)
}
/* Execute thread */
-void _thread_execute(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, int val)
+void _event_execute(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, int val)
{
- struct thread *thread;
+ struct event *thread;
/* Get or allocate new thread to execute. */
frr_with_mutex (&m->mtx) {
- thread = thread_get(m, THREAD_EVENT, func, arg, xref);
+ thread = thread_get(m, EVENT_EVENT, func, arg, xref);
/* Set its event value. */
frr_with_mutex (&thread->mtx) {
- thread->add_type = THREAD_EXECUTE;
+ thread->add_type = EVENT_EXECUTE;
thread->u.val = val;
thread->ref = &thread;
}
}
/* Execute thread doing all accounting. */
- thread_call(thread);
+ event_call(thread);
/* Give back or free thread. */
thread_add_unuse(m, thread);
@@ -2131,16 +2136,13 @@ void debug_signals(const sigset_t *sigs)
}
static ssize_t printfrr_thread_dbg(struct fbuf *buf, struct printfrr_eargs *ea,
- const struct thread *thread)
-{
- static const char * const types[] = {
- [THREAD_READ] = "read",
- [THREAD_WRITE] = "write",
- [THREAD_TIMER] = "timer",
- [THREAD_EVENT] = "event",
- [THREAD_READY] = "ready",
- [THREAD_UNUSED] = "unused",
- [THREAD_EXECUTE] = "exec",
+ const struct event *thread)
+{
+ static const char *const types[] = {
+ [EVENT_READ] = "read", [EVENT_WRITE] = "write",
+ [EVENT_TIMER] = "timer", [EVENT_EVENT] = "event",
+ [EVENT_READY] = "ready", [EVENT_UNUSED] = "unused",
+ [EVENT_EXECUTE] = "exec",
};
ssize_t rv = 0;
char info[16] = "";
@@ -2156,14 +2158,19 @@ static ssize_t printfrr_thread_dbg(struct fbuf *buf, struct printfrr_eargs *ea,
rv += bprintfrr(buf, " INVALID(%u)", thread->type);
switch (thread->type) {
- case THREAD_READ:
- case THREAD_WRITE:
+ case EVENT_READ:
+ case EVENT_WRITE:
snprintfrr(info, sizeof(info), "fd=%d", thread->u.fd);
break;
- case THREAD_TIMER:
+ case EVENT_TIMER:
snprintfrr(info, sizeof(info), "r=%pTVMud", &thread->u.sands);
break;
+ case EVENT_READY:
+ case EVENT_EVENT:
+ case EVENT_UNUSED:
+ case EVENT_EXECUTE:
+ break;
}
rv += bprintfrr(buf, " %-12s %s() %s from %s:%d}", info,
@@ -2176,7 +2183,7 @@ printfrr_ext_autoreg_p("TH", printfrr_thread);
static ssize_t printfrr_thread(struct fbuf *buf, struct printfrr_eargs *ea,
const void *ptr)
{
- const struct thread *thread = ptr;
+ const struct event *thread = ptr;
struct timespec remain = {};
if (ea->fmt[0] == 'D') {
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index 0c617238fa..c4ead01bf6 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -75,7 +75,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
/* initialize mutex */
pthread_mutex_init(&fpt->mtx, NULL);
/* create new thread master */
- fpt->master = thread_master_create(name);
+ fpt->master = event_master_create(name);
/* set attributes */
fpt->attr = *attr;
name = (name ? name : "Anonymous thread");
@@ -101,7 +101,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
static void frr_pthread_destroy_nolock(struct frr_pthread *fpt)
{
- thread_master_free(fpt->master);
+ event_master_free(fpt->master);
pthread_mutex_destroy(&fpt->mtx);
pthread_mutex_destroy(fpt->running_cond_mtx);
pthread_cond_destroy(fpt->running_cond);
@@ -224,14 +224,14 @@ void frr_pthread_stop_all(void)
*/
/* dummy task for sleeper pipe */
-static void fpt_dummy(struct thread *thread)
+static void fpt_dummy(struct event *thread)
{
}
/* poison pill task to end event loop */
-static void fpt_finish(struct thread *thread)
+static void fpt_finish(struct event *thread)
{
- struct frr_pthread *fpt = THREAD_ARG(thread);
+ struct frr_pthread *fpt = EVENT_ARG(thread);
atomic_store_explicit(&fpt->running, false, memory_order_relaxed);
}
@@ -239,7 +239,7 @@ static void fpt_finish(struct thread *thread)
/* stop function, called from other threads to halt this one */
static int fpt_halt(struct frr_pthread *fpt, void **res)
{
- thread_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
+ event_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
pthread_join(fpt->thread, res);
return 0;
@@ -281,7 +281,7 @@ static void *fpt_run(void *arg)
int sleeper[2];
pipe(sleeper);
- thread_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
+ event_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
fpt->master->handle_signals = false;
@@ -289,11 +289,11 @@ static void *fpt_run(void *arg)
frr_pthread_notify_running(fpt);
- struct thread task;
+ struct event task;
while (atomic_load_explicit(&fpt->running, memory_order_relaxed)) {
pthread_testcancel();
- if (thread_fetch(fpt->master, &task)) {
- thread_call(&task);
+ if (event_fetch(fpt->master, &task)) {
+ event_call(&task);
}
}
diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h
index b1d08717fb..f91044dfae 100644
--- a/lib/frr_pthread.h
+++ b/lib/frr_pthread.h
@@ -11,7 +11,7 @@
#include "frratomic.h"
#include "memory.h"
#include "frrcu.h"
-#include "thread.h"
+#include "frrevent.h"
#ifdef __cplusplus
extern "C" {
@@ -41,7 +41,7 @@ struct frr_pthread {
struct rcu_thread *rcu_thread;
/* thread master for this pthread's thread.c event loop */
- struct thread_master *master;
+ struct event_loop *master;
/* caller-specified data; start & stop funcs, name, id */
struct frr_pthread_attr attr;
diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c
index 2673d57605..b28dd7f1bb 100644
--- a/lib/frr_zmq.c
+++ b/lib/frr_zmq.c
@@ -15,7 +15,7 @@
#include <zebra.h>
#include <zmq.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "frr_zmq.h"
#include "log.h"
@@ -43,9 +43,9 @@ void frrzmq_finish(void)
}
}
-static void frrzmq_read_msg(struct thread *t)
+static void frrzmq_read_msg(struct event *t)
{
- struct frrzmq_cb **cbp = THREAD_ARG(t);
+ struct frrzmq_cb **cbp = EVENT_ARG(t);
struct frrzmq_cb *cb;
zmq_msg_t msg;
unsigned partno;
@@ -138,8 +138,8 @@ static void frrzmq_read_msg(struct thread *t)
if (read)
frrzmq_check_events(cbp, &cb->write, ZMQ_POLLOUT);
- thread_add_read(t->master, frrzmq_read_msg, cbp,
- cb->fd, &cb->read.thread);
+ event_add_read(t->master, frrzmq_read_msg, cbp, cb->fd,
+ &cb->read.thread);
return;
out_err:
@@ -149,14 +149,13 @@ out_err:
cb->read.cb_error(cb->read.arg, cb->zmqsock);
}
-int _frrzmq_thread_add_read(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*partfunc)(void *arg, void *zmqsock,
- zmq_msg_t *msg, unsigned partnum),
- void (*errfunc)(void *arg, void *zmqsock),
- void *arg, void *zmqsock,
- struct frrzmq_cb **cbp)
+int _frrzmq_event_add_read(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*partfunc)(void *arg, void *zmqsock,
+ zmq_msg_t *msg, unsigned partnum),
+ void (*errfunc)(void *arg, void *zmqsock), void *arg,
+ void *zmqsock, struct frrzmq_cb **cbp)
{
int fd, events;
size_t len;
@@ -191,19 +190,19 @@ int _frrzmq_thread_add_read(const struct xref_threadsched *xref,
cb->in_cb = false;
if (events & ZMQ_POLLIN) {
- thread_cancel(&cb->read.thread);
+ event_cancel(&cb->read.thread);
- thread_add_event(master, frrzmq_read_msg, cbp, fd,
- &cb->read.thread);
- } else
- thread_add_read(master, frrzmq_read_msg, cbp, fd,
+ event_add_event(master, frrzmq_read_msg, cbp, fd,
&cb->read.thread);
+ } else
+ event_add_read(master, frrzmq_read_msg, cbp, fd,
+ &cb->read.thread);
return 0;
}
-static void frrzmq_write_msg(struct thread *t)
+static void frrzmq_write_msg(struct event *t)
{
- struct frrzmq_cb **cbp = THREAD_ARG(t);
+ struct frrzmq_cb **cbp = EVENT_ARG(t);
struct frrzmq_cb *cb;
unsigned char written = 0;
int ret;
@@ -247,8 +246,8 @@ static void frrzmq_write_msg(struct thread *t)
if (written)
frrzmq_check_events(cbp, &cb->read, ZMQ_POLLIN);
- thread_add_write(t->master, frrzmq_write_msg, cbp,
- cb->fd, &cb->write.thread);
+ event_add_write(t->master, frrzmq_write_msg, cbp, cb->fd,
+ &cb->write.thread);
return;
out_err:
@@ -258,11 +257,11 @@ out_err:
cb->write.cb_error(cb->write.arg, cb->zmqsock);
}
-int _frrzmq_thread_add_write(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*errfunc)(void *arg, void *zmqsock),
- void *arg, void *zmqsock, struct frrzmq_cb **cbp)
+int _frrzmq_event_add_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*errfunc)(void *arg, void *zmqsock),
+ void *arg, void *zmqsock, struct frrzmq_cb **cbp)
{
int fd, events;
size_t len;
@@ -297,13 +296,13 @@ int _frrzmq_thread_add_write(const struct xref_threadsched *xref,
cb->in_cb = false;
if (events & ZMQ_POLLOUT) {
- thread_cancel(&cb->write.thread);
+ event_cancel(&cb->write.thread);
- _thread_add_event(xref, master, frrzmq_write_msg, cbp, fd,
- &cb->write.thread);
- } else
- thread_add_write(master, frrzmq_write_msg, cbp, fd,
+ _event_add_event(xref, master, frrzmq_write_msg, cbp, fd,
&cb->write.thread);
+ } else
+ event_add_write(master, frrzmq_write_msg, cbp, fd,
+ &cb->write.thread);
return 0;
}
@@ -312,7 +311,7 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core)
if (!cb || !*cb)
return;
core->cancelled = true;
- thread_cancel(&core->thread);
+ event_cancel(&core->thread);
/* If cancelled from within a callback, don't try to free memory
* in this path.
@@ -343,15 +342,15 @@ void frrzmq_check_events(struct frrzmq_cb **cbp, struct cb_core *core,
if (zmq_getsockopt(cb->zmqsock, ZMQ_EVENTS, &events, &len))
return;
if ((events & event) && core->thread && !core->cancelled) {
- struct thread_master *tm = core->thread->master;
+ struct event_loop *tm = core->thread->master;
- thread_cancel(&core->thread);
+ event_cancel(&core->thread);
if (event == ZMQ_POLLIN)
- thread_add_event(tm, frrzmq_read_msg,
- cbp, cb->fd, &core->thread);
+ event_add_event(tm, frrzmq_read_msg, cbp, cb->fd,
+ &core->thread);
else
- thread_add_event(tm, frrzmq_write_msg,
- cbp, cb->fd, &core->thread);
+ event_add_event(tm, frrzmq_write_msg, cbp, cb->fd,
+ &core->thread);
}
}
diff --git a/lib/frr_zmq.h b/lib/frr_zmq.h
index f12291d602..73da3770f4 100644
--- a/lib/frr_zmq.h
+++ b/lib/frr_zmq.h
@@ -7,7 +7,7 @@
#ifndef _FRRZMQ_H
#define _FRRZMQ_H
-#include "thread.h"
+#include "frrevent.h"
#include <zmq.h>
#ifdef __cplusplus
@@ -26,7 +26,7 @@ extern "C" {
/* callback integration */
struct cb_core {
- struct thread *thread;
+ struct event *thread;
void *arg;
bool cancelled;
@@ -59,30 +59,29 @@ extern void frrzmq_finish(void);
#define _xref_zmq_a(type, f, d, call) \
({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
.funcname = #f, \
.dest = #d, \
- .thread_type = THREAD_ ## type, \
+ .event_type = EVENT_##type, \
}; \
XREF_LINK(_xref.xref); \
call; \
- }) \
- /* end */
+ }) /* end */
/* core event registration, one of these 2 macros should be used */
-#define frrzmq_thread_add_read_msg(m, f, e, a, z, d) \
+#define frrzmq_event_add_read_msg(m, f, e, a, z, d) \
_xref_zmq_a(READ, f, d, \
- _frrzmq_thread_add_read(&_xref, m, f, NULL, e, a, z, d))
+ _frrzmq_event_add_read(&_xref, m, f, NULL, e, a, z, d))
-#define frrzmq_thread_add_read_part(m, f, e, a, z, d) \
+#define frrzmq_event_add_read_part(m, f, e, a, z, d) \
_xref_zmq_a(READ, f, d, \
- _frrzmq_thread_add_read(&_xref, m, NULL, f, e, a, z, d))
+ _frrzmq_event_add_read(&_xref, m, NULL, f, e, a, z, d))
-#define frrzmq_thread_add_write_msg(m, f, e, a, z, d) \
+#define frrzmq_event_add_write_msg(m, f, e, a, z, d) \
_xref_zmq_a(WRITE, f, d, \
- _frrzmq_thread_add_write(&_xref, m, f, e, a, z, d))
+ _frrzmq_event_add_write(&_xref, m, f, e, a, z, d))
struct cb_core;
struct frrzmq_cb;
@@ -108,18 +107,20 @@ struct frrzmq_cb;
* may schedule the event to run as soon as libfrr is back in its main
* loop.
*/
-extern int _frrzmq_thread_add_read(
- const struct xref_threadsched *xref, struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*partfunc)(void *arg, void *zmqsock, zmq_msg_t *msg,
- unsigned partnum),
- void (*errfunc)(void *arg, void *zmqsock), void *arg, void *zmqsock,
- struct frrzmq_cb **cb);
-extern int _frrzmq_thread_add_write(
- const struct xref_threadsched *xref, struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*errfunc)(void *arg, void *zmqsock), void *arg, void *zmqsock,
- struct frrzmq_cb **cb);
+extern int
+_frrzmq_event_add_read(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*partfunc)(void *arg, void *zmqsock,
+ zmq_msg_t *msg, unsigned partnum),
+ void (*errfunc)(void *arg, void *zmqsock), void *arg,
+ void *zmqsock, struct frrzmq_cb **cb);
+extern int _frrzmq_event_add_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*errfunc)(void *arg, void *zmqsock),
+ void *arg, void *zmqsock,
+ struct frrzmq_cb **cb);
extern void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core);
diff --git a/lib/frrevent.h b/lib/frrevent.h
new file mode 100644
index 0000000000..2b0c52bb51
--- /dev/null
+++ b/lib/frrevent.h
@@ -0,0 +1,295 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Event management routine header.
+ * Copyright (C) 1998 Kunihiro Ishiguro
+ */
+
+#ifndef _ZEBRA_THREAD_H
+#define _ZEBRA_THREAD_H
+
+#include <zebra.h>
+#include <pthread.h>
+#include <poll.h>
+#include "monotime.h"
+#include "frratomic.h"
+#include "typesafe.h"
+#include "xref.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bool cputime_enabled;
+extern unsigned long cputime_threshold;
+/* capturing wallclock time is always enabled since it is fast (reading
+ * hardware TSC w/o syscalls)
+ */
+extern unsigned long walltime_threshold;
+
+struct rusage_t {
+#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
+ struct timespec cpu;
+#else
+ struct rusage cpu;
+#endif
+ struct timeval real;
+};
+#define RUSAGE_T struct rusage_t
+
+#define GETRUSAGE(X) event_getrusage(X)
+
+PREDECL_LIST(event_list);
+PREDECL_HEAP(event_timer_list);
+
+struct fd_handler {
+ /* number of pfd that fit in the allocated space of pfds. This is a
+ * constant and is the same for both pfds and copy.
+ */
+ nfds_t pfdsize;
+
+ /* file descriptors to monitor for i/o */
+ struct pollfd *pfds;
+ /* number of pollfds stored in pfds */
+ nfds_t pfdcount;
+
+ /* chunk used for temp copy of pollfds */
+ struct pollfd *copy;
+ /* number of pollfds stored in copy */
+ nfds_t copycount;
+};
+
+struct xref_eventsched {
+ struct xref xref;
+
+ const char *funcname;
+ const char *dest;
+ uint32_t event_type;
+};
+
+/* Master of the theads. */
+struct event_loop {
+ char *name;
+
+ struct event **read;
+ struct event **write;
+ struct event_timer_list_head timer;
+ struct event_list_head event, ready, unuse;
+ struct list *cancel_req;
+ bool canceled;
+ pthread_cond_t cancel_cond;
+ struct hash *cpu_record;
+ int io_pipe[2];
+ int fd_limit;
+ struct fd_handler handler;
+ unsigned long alloc;
+ long selectpoll_timeout;
+ bool spin;
+ bool handle_signals;
+ pthread_mutex_t mtx;
+ pthread_t owner;
+
+ bool ready_run_loop;
+ RUSAGE_T last_getrusage;
+};
+
+/* Event types. */
+enum event_types {
+ EVENT_READ,
+ EVENT_WRITE,
+ EVENT_TIMER,
+ EVENT_EVENT,
+ EVENT_READY,
+ EVENT_UNUSED,
+ EVENT_EXECUTE,
+};
+
+/* Event itself. */
+struct event {
+ enum event_types type; /* event type */
+ enum event_types add_type; /* event type */
+ struct event_list_item eventitem;
+ struct event_timer_list_item timeritem;
+ struct event **ref; /* external reference (if given) */
+ struct event_loop *master; /* pointer to the struct event_loop */
+ void (*func)(struct event *e); /* event function */
+ void *arg; /* event argument */
+ union {
+ int val; /* second argument of the event. */
+ int fd; /* file descriptor in case of r/w */
+ struct timeval sands; /* rest of time sands value. */
+ } u;
+ struct timeval real;
+ struct cpu_event_history *hist; /* cache pointer to cpu_history */
+ unsigned long yield; /* yield time in microseconds */
+ const struct xref_eventsched *xref; /* origin location */
+ pthread_mutex_t mtx; /* mutex for thread.c functions */
+ bool ignore_timer_late;
+};
+
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pTH"(struct event *)
+#endif
+
+struct cpu_event_history {
+ void (*func)(struct event *e);
+ atomic_size_t total_cpu_warn;
+ atomic_size_t total_wall_warn;
+ atomic_size_t total_starv_warn;
+ atomic_size_t total_calls;
+ atomic_size_t total_active;
+ struct time_stats {
+ atomic_size_t total, max;
+ } real;
+ struct time_stats cpu;
+ atomic_uint_fast32_t types;
+ const char *funcname;
+};
+
+/* Struct timeval's tv_usec one second value. */
+#define TIMER_SECOND_MICRO 1000000L
+
+/* Event yield time. */
+#define EVENT_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
+
+#define EVENT_TIMER_STRLEN 12
+
+/* Macros. */
+#define EVENT_ARG(X) ((X)->arg)
+#define EVENT_FD(X) ((X)->u.fd)
+#define EVENT_VAL(X) ((X)->u.val)
+
+/*
+ * Please consider this macro deprecated, and do not use it in new code.
+ */
+#define EVENT_OFF(thread) \
+ do { \
+ if ((thread)) \
+ event_cancel(&(thread)); \
+ } while (0)
+
+/*
+ * Macro wrappers to generate xrefs for all thread add calls. Includes
+ * file/line/function info for debugging/tracing.
+ */
+#include "lib/xref.h"
+
+#define _xref_t_a(addfn, type, m, f, a, v, t) \
+ ({ \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
+ .funcname = #f, \
+ .dest = #t, \
+ .event_type = EVENT_##type, \
+ }; \
+ XREF_LINK(_xref.xref); \
+ _event_add_##addfn(&_xref, m, f, a, v, t); \
+ }) /* end */
+
+#define event_add_read(m, f, a, v, t) _xref_t_a(read_write, READ, m, f, a, v, t)
+#define event_add_write(m, f, a, v, t) \
+ _xref_t_a(read_write, WRITE, m, f, a, v, t)
+#define event_add_timer(m, f, a, v, t) _xref_t_a(timer, TIMER, m, f, a, v, t)
+#define event_add_timer_msec(m, f, a, v, t) \
+ _xref_t_a(timer_msec, TIMER, m, f, a, v, t)
+#define event_add_timer_tv(m, f, a, v, t) \
+ _xref_t_a(timer_tv, TIMER, m, f, a, v, t)
+#define event_add_event(m, f, a, v, t) _xref_t_a(event, EVENT, m, f, a, v, t)
+
+#define event_execute(m, f, a, v) \
+ ({ \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
+ .funcname = #f, \
+ .dest = NULL, \
+ .event_type = EVENT_EXECUTE, \
+ }; \
+ XREF_LINK(_xref.xref); \
+ _event_execute(&_xref, m, f, a, v); \
+ }) /* end */
+
+/* Prototypes. */
+extern struct event_loop *event_master_create(const char *name);
+void event_master_set_name(struct event_loop *master, const char *name);
+extern void event_master_free(struct event_loop *m);
+extern void event_master_free_unused(struct event_loop *m);
+
+extern void _event_add_read_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int fd,
+ struct event **tref);
+
+extern void _event_add_timer(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, long t,
+ struct event **tref);
+
+extern void _event_add_timer_msec(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, long t,
+ struct event **tref);
+
+extern void _event_add_timer_tv(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg,
+ struct timeval *tv, struct event **tref);
+
+extern void _event_add_event(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int val,
+ struct event **tref);
+
+extern void _event_execute(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int val);
+
+extern void event_cancel(struct event **event);
+extern void event_cancel_async(struct event_loop *m, struct event **eptr,
+ void *data);
+/* Cancel ready tasks with an arg matching 'arg' */
+extern void event_cancel_event_ready(struct event_loop *m, void *arg);
+/* Cancel all tasks with an arg matching 'arg', including timers and io */
+extern void event_cancel_event(struct event_loop *m, void *arg);
+extern struct event *event_fetch(struct event_loop *m, struct event *event);
+extern void event_call(struct event *event);
+extern unsigned long event_timer_remain_second(struct event *event);
+extern struct timeval event_timer_remain(struct event *event);
+extern unsigned long event_timer_remain_msec(struct event *event);
+extern int event_should_yield(struct event *event);
+/* set yield time for thread */
+extern void event_set_yield_time(struct event *event, unsigned long ytime);
+
+/* Internal libfrr exports */
+extern void event_getrusage(RUSAGE_T *r);
+extern void event_cmd_init(void);
+
+/* Returns elapsed real (wall clock) time. */
+extern unsigned long event_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
+ unsigned long *cpu_time_elapsed);
+
+/* only for use in logging functions! */
+extern pthread_key_t thread_current;
+extern char *event_timer_to_hhmmss(char *buf, int buf_size,
+ struct event *t_timer);
+
+static inline bool event_is_scheduled(struct event *thread)
+{
+ if (thread)
+ return true;
+
+ return false;
+}
+
+/* Debug signal mask */
+void debug_signals(const sigset_t *sigs);
+
+static inline void event_ignore_late_timer(struct event *event)
+{
+ event->ignore_timer_late = true;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ZEBRA_THREAD_H */
diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c
index cdb1c3adb4..abd42f359f 100644
--- a/lib/grammar_sandbox_main.c
+++ b/lib/grammar_sandbox_main.c
@@ -23,13 +23,13 @@ static void vty_do_exit(int isexit)
exit(0);
}
-struct thread_master *master;
+struct event_loop *master;
int main(int argc, char **argv)
{
- struct thread thread;
+ struct event event;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
zlog_aux_init("NONE: ", LOG_DEBUG);
@@ -45,8 +45,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &event))
+ event_call(&event);
/* Not reached. */
exit(0);
diff --git a/lib/ldp_sync.c b/lib/ldp_sync.c
index b01cf87287..d55819dfaf 100644
--- a/lib/ldp_sync.c
+++ b/lib/ldp_sync.c
@@ -10,7 +10,7 @@
#include "memory.h"
#include "prefix.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "zclient.h"
#include "table.h"
@@ -66,7 +66,7 @@ bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info)
* update state
*/
if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP)
ldp_sync_info->state =
diff --git a/lib/ldp_sync.h b/lib/ldp_sync.h
index 5b6ebbf887..f7601ebf9d 100644
--- a/lib/ldp_sync.h
+++ b/lib/ldp_sync.h
@@ -37,7 +37,7 @@ struct ldp_sync_info {
uint8_t enabled; /* enabled */
uint8_t state; /* running state */
uint16_t holddown; /* timer value */
- struct thread *t_holddown; /* holddown timer*/
+ struct event *t_holddown; /* holddown timer*/
uint32_t metric[2]; /* isis interface metric */
};
diff --git a/lib/libfrr.c b/lib/libfrr.c
index d1b7dd133e..07e2eafec5 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -33,10 +33,10 @@
#include "frrscript.h"
#include "systemd.h"
-DEFINE_HOOK(frr_early_init, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_config_post, (struct thread_master * tm), (tm));
+DEFINE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_config_post, (struct event_loop * tm), (tm));
DEFINE_KOOH(frr_early_fini, (), ());
DEFINE_KOOH(frr_fini, (), ());
@@ -696,8 +696,8 @@ static void _err_print(const void *cookie, const char *errstr)
fprintf(stderr, "%s: %s\n", prefix, errstr);
}
-static struct thread_master *master;
-struct thread_master *frr_init(void)
+static struct event_loop *master;
+struct event_loop *frr_init(void)
{
struct option_chain *oc;
struct log_arg *log_arg;
@@ -769,7 +769,7 @@ struct thread_master *frr_init(void)
zprivs_init(di->privs);
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
signal_init(master, di->n_signals, di->signals);
hook_call(frr_early_init, master);
@@ -964,7 +964,7 @@ static void frr_daemonize(void)
* to read the config in after thread execution starts, so that
* we can match this behavior.
*/
-static void frr_config_read_in(struct thread *t)
+static void frr_config_read_in(struct event *t)
{
hook_call(frr_config_pre, master);
@@ -1015,8 +1015,8 @@ void frr_config_fork(void)
exit(0);
}
- thread_add_event(master, frr_config_read_in, NULL, 0,
- &di->read_in);
+ event_add_event(master, frr_config_read_in, NULL, 0,
+ &di->read_in);
}
if (di->daemon_mode || di->terminal)
@@ -1095,9 +1095,9 @@ static void frr_terminal_close(int isexit)
}
}
-static struct thread *daemon_ctl_thread = NULL;
+static struct event *daemon_ctl_thread = NULL;
-static void frr_daemon_ctl(struct thread *t)
+static void frr_daemon_ctl(struct event *t)
{
char buf[1];
ssize_t nr;
@@ -1129,8 +1129,8 @@ static void frr_daemon_ctl(struct thread *t)
}
out:
- thread_add_read(master, frr_daemon_ctl, NULL, daemon_ctl_sock,
- &daemon_ctl_thread);
+ event_add_read(master, frr_daemon_ctl, NULL, daemon_ctl_sock,
+ &daemon_ctl_thread);
}
void frr_detach(void)
@@ -1139,7 +1139,7 @@ void frr_detach(void)
frr_check_detach();
}
-void frr_run(struct thread_master *master)
+void frr_run(struct event_loop *master)
{
char instanceinfo[64] = "";
@@ -1158,8 +1158,8 @@ void frr_run(struct thread_master *master)
vty_stdio(frr_terminal_close);
if (daemon_ctl_sock != -1) {
set_nonblocking(daemon_ctl_sock);
- thread_add_read(master, frr_daemon_ctl, NULL,
- daemon_ctl_sock, &daemon_ctl_thread);
+ event_add_read(master, frr_daemon_ctl, NULL,
+ daemon_ctl_sock, &daemon_ctl_thread);
}
} else if (di->daemon_mode) {
int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
@@ -1180,9 +1180,9 @@ void frr_run(struct thread_master *master)
/* end fixed stderr startup logging */
zlog_startup_end();
- struct thread thread;
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ struct event thread;
+ while (event_fetch(master, &thread))
+ event_call(&thread);
}
void frr_early_fini(void)
@@ -1213,7 +1213,7 @@ void frr_fini(void)
frr_pthread_finish();
zprivs_terminate(di->privs);
/* signal_init -> nothing needed */
- thread_master_free(master);
+ event_master_free(master);
master = NULL;
zlog_tls_buffer_fini();
zlog_fini();
diff --git a/lib/libfrr.h b/lib/libfrr.h
index 97e9b93c10..c05bc01e4f 100644
--- a/lib/libfrr.h
+++ b/lib/libfrr.h
@@ -11,7 +11,7 @@
#include "typesafe.h"
#include "sigevent.h"
#include "privs.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "getopt.h"
#include "module.h"
@@ -70,7 +70,7 @@ struct frr_daemon_info {
bool terminal;
enum frr_cli_mode cli_mode;
- struct thread *read_in;
+ struct event *read_in;
const char *config_file;
const char *backup_config_file;
const char *pid_file;
@@ -133,22 +133,22 @@ extern int frr_getopt(int argc, char *const argv[], int *longindex);
extern __attribute__((__noreturn__)) void frr_help_exit(int status);
-extern struct thread_master *frr_init(void);
+extern struct event_loop *frr_init(void);
extern const char *frr_get_progname(void);
extern enum frr_cli_mode frr_get_cli_mode(void);
extern uint32_t frr_get_fd_limit(void);
extern bool frr_is_startup_fd(int fd);
/* call order of these hooks is as ordered here */
-DECLARE_HOOK(frr_early_init, (struct thread_master * tm), (tm));
-DECLARE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
+DECLARE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
+DECLARE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
/* fork() happens between late_init and config_pre */
-DECLARE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
-DECLARE_HOOK(frr_config_post, (struct thread_master * tm), (tm));
+DECLARE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));
+DECLARE_HOOK(frr_config_post, (struct event_loop * tm), (tm));
extern void frr_config_fork(void);
-extern void frr_run(struct thread_master *master);
+extern void frr_run(struct event_loop *master);
extern void frr_detach(void);
extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
diff --git a/lib/libfrr_trace.h b/lib/libfrr_trace.h
index 92c469706a..05c958fa42 100644
--- a/lib/libfrr_trace.h
+++ b/lib/libfrr_trace.h
@@ -21,7 +21,7 @@
#include <lttng/tracepoint.h>
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "table.h"
@@ -73,8 +73,8 @@ TRACEPOINT_EVENT(
TRACEPOINT_LOGLEVEL(frr_libfrr, hash_release, TRACE_INFO)
#define THREAD_SCHEDULE_ARGS \
- TP_ARGS(struct thread_master *, master, const char *, funcname, \
- const char *, schedfrom, int, fromln, struct thread **, \
+ TP_ARGS(struct event_loop *, master, const char *, funcname, \
+ const char *, schedfrom, int, fromln, struct event **, \
thread_ptr, int, fd, int, val, void *, arg, long, time)
TRACEPOINT_EVENT_CLASS(
@@ -103,9 +103,9 @@ THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_timer)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_event)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_read)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_write)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel_async)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel_async)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_call)
TRACEPOINT_EVENT(
frr_libfrr,
diff --git a/lib/log.c b/lib/log.c
index f7ab86fd9d..00b897dca1 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -140,7 +140,7 @@ void zlog_signal(int signo, const char *action, void *siginfo_v,
fb.pos = buf;
- struct thread *tc;
+ struct event *tc;
tc = pthread_getspecific(thread_current);
if (!tc)
@@ -284,7 +284,7 @@ void zlog_backtrace(int priority)
void zlog_thread_info(int log_level)
{
- struct thread *tc;
+ struct event *tc;
tc = pthread_getspecific(thread_current);
if (tc)
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c
index bb45024d0e..c35399cb5a 100644
--- a/lib/mgmt_be_client.c
+++ b/lib/mgmt_be_client.c
@@ -105,12 +105,12 @@ DECLARE_LIST(mgmt_be_txns, struct mgmt_be_txn_ctx, list_linkage);
struct mgmt_be_client_ctx {
int conn_fd;
- struct thread_master *tm;
- struct thread *conn_retry_tmr;
- struct thread *conn_read_ev;
- struct thread *conn_write_ev;
- struct thread *conn_writes_on;
- struct thread *msg_proc_ev;
+ struct event_loop *tm;
+ struct event *conn_retry_tmr;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *msg_proc_ev;
uint32_t flags;
struct mgmt_msg_state mstate;
@@ -897,18 +897,18 @@ static void mgmt_be_client_process_msg(void *user_ctx, uint8_t *data,
mgmtd__be_message__free_unpacked(be_msg, NULL);
}
-static void mgmt_be_client_proc_msgbufs(struct thread *thread)
+static void mgmt_be_client_proc_msgbufs(struct event *thread)
{
- struct mgmt_be_client_ctx *client_ctx = THREAD_ARG(thread);
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_be_client_process_msg,
client_ctx, mgmt_debug_be_client))
mgmt_be_client_register_event(client_ctx, MGMTD_BE_PROC_MSG);
}
-static void mgmt_be_client_read(struct thread *thread)
+static void mgmt_be_client_read(struct event *thread)
{
- struct mgmt_be_client_ctx *client_ctx = THREAD_ARG(thread);
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
enum mgmt_msg_rsched rv;
rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
@@ -962,9 +962,9 @@ static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx,
return rv;
}
-static void mgmt_be_client_write(struct thread *thread)
+static void mgmt_be_client_write(struct event *thread)
{
- struct mgmt_be_client_ctx *client_ctx = THREAD_ARG(thread);
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
enum mgmt_msg_wsched rv;
rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
@@ -981,11 +981,11 @@ static void mgmt_be_client_write(struct thread *thread)
assert(rv == MSW_SCHED_NONE);
}
-static void mgmt_be_client_resume_writes(struct thread *thread)
+static void mgmt_be_client_resume_writes(struct event *thread)
{
struct mgmt_be_client_ctx *client_ctx;
- client_ctx = (struct mgmt_be_client_ctx *)THREAD_ARG(thread);
+ client_ctx = (struct mgmt_be_client_ctx *)EVENT_ARG(thread);
assert(client_ctx && client_ctx->conn_fd != -1);
mgmt_be_client_writes_on(client_ctx);
@@ -1040,9 +1040,9 @@ static void mgmt_be_server_connect(struct mgmt_be_client_ctx *client_ctx)
client_ctx->client_params.user_data, true);
}
-static void mgmt_be_client_conn_timeout(struct thread *thread)
+static void mgmt_be_client_conn_timeout(struct event *thread)
{
- mgmt_be_server_connect(THREAD_ARG(thread));
+ mgmt_be_server_connect(EVENT_ARG(thread));
}
static void
@@ -1053,25 +1053,25 @@ mgmt_be_client_register_event(struct mgmt_be_client_ctx *client_ctx,
switch (event) {
case MGMTD_BE_CONN_READ:
- thread_add_read(client_ctx->tm, mgmt_be_client_read,
+ event_add_read(client_ctx->tm, mgmt_be_client_read,
client_ctx, client_ctx->conn_fd,
&client_ctx->conn_read_ev);
assert(client_ctx->conn_read_ev);
break;
case MGMTD_BE_CONN_WRITE:
- thread_add_write(client_ctx->tm, mgmt_be_client_write,
+ event_add_write(client_ctx->tm, mgmt_be_client_write,
client_ctx, client_ctx->conn_fd,
&client_ctx->conn_write_ev);
assert(client_ctx->conn_write_ev);
break;
case MGMTD_BE_PROC_MSG:
tv.tv_usec = MGMTD_BE_MSG_PROC_DELAY_USEC;
- thread_add_timer_tv(client_ctx->tm, mgmt_be_client_proc_msgbufs,
+ event_add_timer_tv(client_ctx->tm, mgmt_be_client_proc_msgbufs,
client_ctx, &tv, &client_ctx->msg_proc_ev);
assert(client_ctx->msg_proc_ev);
break;
case MGMTD_BE_CONN_WRITES_ON:
- thread_add_timer_msec(client_ctx->tm,
+ event_add_timer_msec(client_ctx->tm,
mgmt_be_client_resume_writes, client_ctx,
MGMTD_BE_MSG_WRITE_DELAY_MSEC,
&client_ctx->conn_writes_on);
@@ -1095,7 +1095,7 @@ mgmt_be_client_schedule_conn_retry(struct mgmt_be_client_ctx *client_ctx,
MGMTD_BE_CLIENT_DBG(
"Scheduling MGMTD Backend server connection retry after %lu seconds",
intvl_secs);
- thread_add_timer(client_ctx->tm, mgmt_be_client_conn_timeout,
+ event_add_timer(client_ctx->tm, mgmt_be_client_conn_timeout,
(void *)client_ctx, intvl_secs,
&client_ctx->conn_retry_tmr);
}
@@ -1106,7 +1106,7 @@ extern struct nb_config *running_config;
* Initialize library and try connecting with MGMTD.
*/
uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
- struct thread_master *master_thread)
+ struct event_loop *master_thread)
{
assert(master_thread && params && strlen(params->name)
&& !mgmt_be_client_ctx.tm);
@@ -1213,11 +1213,11 @@ void mgmt_be_client_lib_destroy(uintptr_t lib_hndl)
mgmt_msg_destroy(&client_ctx->mstate);
- THREAD_OFF(client_ctx->conn_retry_tmr);
- THREAD_OFF(client_ctx->conn_read_ev);
- THREAD_OFF(client_ctx->conn_write_ev);
- THREAD_OFF(client_ctx->conn_writes_on);
- THREAD_OFF(client_ctx->msg_proc_ev);
+ EVENT_OFF(client_ctx->conn_retry_tmr);
+ EVENT_OFF(client_ctx->conn_read_ev);
+ EVENT_OFF(client_ctx->conn_write_ev);
+ EVENT_OFF(client_ctx->conn_writes_on);
+ EVENT_OFF(client_ctx->msg_proc_ev);
mgmt_be_cleanup_all_txns(client_ctx);
mgmt_be_txns_fini(&client_ctx->txn_head);
}
diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h
index 66bc62fb08..db427457a4 100644
--- a/lib/mgmt_be_client.h
+++ b/lib/mgmt_be_client.h
@@ -188,9 +188,8 @@ mgmt_be_client_name2id(const char *name)
* Returns:
* Backend client lib handler (nothing but address of mgmt_be_client_ctx)
*/
-extern uintptr_t
-mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
- struct thread_master *master_thread);
+extern uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
+ struct event_loop *master_thread);
/*
* Subscribe with MGMTD for one or more YANG subtree(s).
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c
index 3624922124..57c1961ff0 100644
--- a/lib/mgmt_fe_client.c
+++ b/lib/mgmt_fe_client.c
@@ -49,12 +49,12 @@ DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_SESSION, "MGMTD Frontend session");
struct mgmt_fe_client_ctx {
int conn_fd;
- struct thread_master *tm;
- struct thread *conn_retry_tmr;
- struct thread *conn_read_ev;
- struct thread *conn_write_ev;
- struct thread *conn_writes_on;
- struct thread *msg_proc_ev;
+ struct event_loop *tm;
+ struct event *conn_retry_tmr;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *msg_proc_ev;
uint32_t flags;
struct mgmt_msg_state mstate;
@@ -174,12 +174,12 @@ static int mgmt_fe_client_send_msg(struct mgmt_fe_client_ctx *client_ctx,
return rv;
}
-static void mgmt_fe_client_write(struct thread *thread)
+static void mgmt_fe_client_write(struct event *thread)
{
struct mgmt_fe_client_ctx *client_ctx;
enum mgmt_msg_wsched rv;
- client_ctx = (struct mgmt_fe_client_ctx *)THREAD_ARG(thread);
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
mgmt_debug_fe_client);
if (rv == MSW_SCHED_STREAM)
@@ -194,11 +194,11 @@ static void mgmt_fe_client_write(struct thread *thread)
assert(rv == MSW_SCHED_NONE);
}
-static void mgmt_fe_client_resume_writes(struct thread *thread)
+static void mgmt_fe_client_resume_writes(struct event *thread)
{
struct mgmt_fe_client_ctx *client_ctx;
- client_ctx = (struct mgmt_fe_client_ctx *)THREAD_ARG(thread);
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
assert(client_ctx && client_ctx->conn_fd != -1);
mgmt_fe_client_writes_on(client_ctx);
@@ -670,22 +670,22 @@ static void mgmt_fe_client_process_msg(void *user_ctx, uint8_t *data,
mgmtd__fe_message__free_unpacked(fe_msg, NULL);
}
-static void mgmt_fe_client_proc_msgbufs(struct thread *thread)
+static void mgmt_fe_client_proc_msgbufs(struct event *thread)
{
struct mgmt_fe_client_ctx *client_ctx;
- client_ctx = (struct mgmt_fe_client_ctx *)THREAD_ARG(thread);
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_fe_client_process_msg,
client_ctx, mgmt_debug_fe_client))
mgmt_fe_client_register_event(client_ctx, MGMTD_FE_PROC_MSG);
}
-static void mgmt_fe_client_read(struct thread *thread)
+static void mgmt_fe_client_read(struct event *thread)
{
struct mgmt_fe_client_ctx *client_ctx;
enum mgmt_msg_rsched rv;
- client_ctx = (struct mgmt_fe_client_ctx *)THREAD_ARG(thread);
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
mgmt_debug_fe_client);
@@ -725,9 +725,9 @@ static void mgmt_fe_server_connect(struct mgmt_fe_client_ctx *client_ctx)
}
-static void mgmt_fe_client_conn_timeout(struct thread *thread)
+static void mgmt_fe_client_conn_timeout(struct event *thread)
{
- mgmt_fe_server_connect(THREAD_ARG(thread));
+ mgmt_fe_server_connect(EVENT_ARG(thread));
}
static void
@@ -738,26 +738,26 @@ mgmt_fe_client_register_event(struct mgmt_fe_client_ctx *client_ctx,
switch (event) {
case MGMTD_FE_CONN_READ:
- thread_add_read(client_ctx->tm, mgmt_fe_client_read,
+ event_add_read(client_ctx->tm, mgmt_fe_client_read,
client_ctx, client_ctx->conn_fd,
&client_ctx->conn_read_ev);
assert(client_ctx->conn_read_ev);
break;
case MGMTD_FE_CONN_WRITE:
- thread_add_write(client_ctx->tm, mgmt_fe_client_write,
+ event_add_write(client_ctx->tm, mgmt_fe_client_write,
client_ctx, client_ctx->conn_fd,
&client_ctx->conn_write_ev);
assert(client_ctx->conn_write_ev);
break;
case MGMTD_FE_PROC_MSG:
tv.tv_usec = MGMTD_FE_MSG_PROC_DELAY_USEC;
- thread_add_timer_tv(client_ctx->tm,
+ event_add_timer_tv(client_ctx->tm,
mgmt_fe_client_proc_msgbufs, client_ctx,
&tv, &client_ctx->msg_proc_ev);
assert(client_ctx->msg_proc_ev);
break;
case MGMTD_FE_CONN_WRITES_ON:
- thread_add_timer_msec(
+ event_add_timer_msec(
client_ctx->tm, mgmt_fe_client_resume_writes,
client_ctx, MGMTD_FE_MSG_WRITE_DELAY_MSEC,
&client_ctx->conn_writes_on);
@@ -775,7 +775,7 @@ static void mgmt_fe_client_schedule_conn_retry(
MGMTD_FE_CLIENT_DBG(
"Scheduling MGMTD Frontend server connection retry after %lu seconds",
intvl_secs);
- thread_add_timer(client_ctx->tm, mgmt_fe_client_conn_timeout,
+ event_add_timer(client_ctx->tm, mgmt_fe_client_conn_timeout,
(void *)client_ctx, intvl_secs,
&client_ctx->conn_retry_tmr);
}
@@ -784,7 +784,7 @@ static void mgmt_fe_client_schedule_conn_retry(
* Initialize library and try connecting with MGMTD.
*/
uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
- struct thread_master *master_thread)
+ struct event_loop *master_thread)
{
assert(master_thread && params && strlen(params->name)
&& !mgmt_fe_client_ctx.tm);
@@ -1067,10 +1067,10 @@ void mgmt_fe_client_lib_destroy(uintptr_t lib_hndl)
mgmt_fe_destroy_client_sessions(lib_hndl);
- THREAD_OFF(client_ctx->conn_retry_tmr);
- THREAD_OFF(client_ctx->conn_read_ev);
- THREAD_OFF(client_ctx->conn_write_ev);
- THREAD_OFF(client_ctx->conn_writes_on);
- THREAD_OFF(client_ctx->msg_proc_ev);
+ EVENT_OFF(client_ctx->conn_retry_tmr);
+ EVENT_OFF(client_ctx->conn_read_ev);
+ EVENT_OFF(client_ctx->conn_write_ev);
+ EVENT_OFF(client_ctx->conn_writes_on);
+ EVENT_OFF(client_ctx->msg_proc_ev);
mgmt_msg_destroy(&client_ctx->mstate);
}
diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h
index ac29b8f27c..aa3371f03c 100644
--- a/lib/mgmt_fe_client.h
+++ b/lib/mgmt_fe_client.h
@@ -13,7 +13,7 @@ extern "C" {
#endif
#include "mgmt_pb.h"
-#include "thread.h"
+#include "frrevent.h"
#include "mgmtd/mgmt_defines.h"
/***************************************************************
@@ -130,9 +130,8 @@ struct mgmt_fe_client_params {
* Returns:
* Frontend client lib handler (nothing but address of mgmt_fe_client_ctx)
*/
-extern uintptr_t
-mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
- struct thread_master *master_thread);
+extern uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
+ struct event_loop *master_thread);
/*
* Create a new Session for a Frontend Client connection.
diff --git a/lib/mgmt_msg.c b/lib/mgmt_msg.c
index 2fab03bc54..3f55f82024 100644
--- a/lib/mgmt_msg.c
+++ b/lib/mgmt_msg.c
@@ -10,7 +10,7 @@
#include "network.h"
#include "sockopt.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "mgmt_msg.h"
diff --git a/lib/mgmt_msg.h b/lib/mgmt_msg.h
index 854875170b..e2dd2d476a 100644
--- a/lib/mgmt_msg.h
+++ b/lib/mgmt_msg.h
@@ -8,7 +8,7 @@
#define _MGMT_MSG_H
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#define MGMT_MSG_MARKER (0x4D724B21u) /* ASCII - "MrK!"*/
diff --git a/lib/northbound.c b/lib/northbound.c
index 1259294a22..307cf0fb49 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -2685,7 +2685,7 @@ void nb_validate_callbacks(void)
}
-void nb_init(struct thread_master *tm,
+void nb_init(struct event_loop *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules, bool db_enabled)
{
diff --git a/lib/northbound.h b/lib/northbound.h
index 4b5028c87e..1723a87e4e 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -7,7 +7,7 @@
#ifndef _FRR_NORTHBOUND_H_
#define _FRR_NORTHBOUND_H_
-#include "thread.h"
+#include "frrevent.h"
#include "hook.h"
#include "linklist.h"
#include "openbsd-tree.h"
@@ -1478,7 +1478,7 @@ void nb_validate_callbacks(void);
* db_enabled
* Set this to record the transactions in the transaction log.
*/
-extern void nb_init(struct thread_master *tm,
+extern void nb_init(struct event_loop *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules, bool db_enabled);
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 281d9a4704..5cf5f93b43 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -29,7 +29,7 @@ struct debug nb_dbg_events = {0, "Northbound events"};
struct debug nb_dbg_libyang = {0, "libyang debugging"};
struct nb_config *vty_shared_candidate_config;
-static struct thread_master *master;
+static struct event_loop *master;
static void vty_show_nb_errors(struct vty *vty, int error, const char *errmsg)
{
@@ -265,7 +265,7 @@ int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
void nb_cli_confirmed_commit_clean(struct vty *vty)
{
- thread_cancel(&vty->t_confirmed_commit_timeout);
+ event_cancel(&vty->t_confirmed_commit_timeout);
nb_config_free(vty->confirmed_commit_rollback);
vty->confirmed_commit_rollback = NULL;
}
@@ -300,9 +300,9 @@ int nb_cli_confirmed_commit_rollback(struct vty *vty)
return ret;
}
-static void nb_cli_confirmed_commit_timeout(struct thread *thread)
+static void nb_cli_confirmed_commit_timeout(struct event *thread)
{
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* XXX: broadcast this message to all logged-in users? */
vty_out(vty,
@@ -328,11 +328,10 @@ static int nb_cli_commit(struct vty *vty, bool force,
"%% Resetting confirmed-commit timeout to %u minute(s)\n\n",
confirmed_timeout);
- thread_cancel(&vty->t_confirmed_commit_timeout);
- thread_add_timer(master,
- nb_cli_confirmed_commit_timeout, vty,
- confirmed_timeout * 60,
- &vty->t_confirmed_commit_timeout);
+ event_cancel(&vty->t_confirmed_commit_timeout);
+ event_add_timer(master, nb_cli_confirmed_commit_timeout,
+ vty, confirmed_timeout * 60,
+ &vty->t_confirmed_commit_timeout);
} else {
/* Accept commit confirmation. */
vty_out(vty, "%% Commit complete.\n\n");
@@ -355,9 +354,9 @@ static int nb_cli_commit(struct vty *vty, bool force,
vty->confirmed_commit_rollback = nb_config_dup(running_config);
vty->t_confirmed_commit_timeout = NULL;
- thread_add_timer(master, nb_cli_confirmed_commit_timeout, vty,
- confirmed_timeout * 60,
- &vty->t_confirmed_commit_timeout);
+ event_add_timer(master, nb_cli_confirmed_commit_timeout, vty,
+ confirmed_timeout * 60,
+ &vty->t_confirmed_commit_timeout);
}
context.client = NB_CLIENT_CLI;
@@ -1877,7 +1876,7 @@ static const struct cmd_variable_handler yang_var_handlers[] = {
.completions = yang_translator_autocomplete},
{.completions = NULL}};
-void nb_cli_init(struct thread_master *tm)
+void nb_cli_init(struct event_loop *tm)
{
master = tm;
diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h
index ef2ef44eb0..c8f8a8481a 100644
--- a/lib/northbound_cli.h
+++ b/lib/northbound_cli.h
@@ -137,7 +137,7 @@ extern void nb_cli_show_config_prepare(struct nb_config *config,
extern void nb_cli_confirmed_commit_clean(struct vty *vty);
extern int nb_cli_confirmed_commit_rollback(struct vty *vty);
extern void nb_cli_install_default(int node);
-extern void nb_cli_init(struct thread_master *tm);
+extern void nb_cli_init(struct event_loop *tm);
extern void nb_cli_terminate(void);
#ifdef __cplusplus
diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c
index ee19568516..34406a110b 100644
--- a/lib/northbound_confd.c
+++ b/lib/northbound_confd.c
@@ -23,10 +23,10 @@ DEFINE_MTYPE_STATIC(LIB, CONFD, "ConfD module");
static struct debug nb_dbg_client_confd = {0, "Northbound client: ConfD"};
-static struct thread_master *master;
+static struct event_loop *master;
static struct sockaddr confd_addr;
static int cdb_sub_sock, dp_ctl_sock, dp_worker_sock;
-static struct thread *t_cdb_sub, *t_dp_ctl, *t_dp_worker;
+static struct event *t_cdb_sub, *t_dp_ctl, *t_dp_worker;
static struct confd_daemon_ctx *dctx;
static struct confd_notification_ctx *live_ctx;
static bool confd_connected;
@@ -401,15 +401,15 @@ static int frr_confd_cdb_read_cb_abort(int fd, int *subp, int reslen)
return 0;
}
-static void frr_confd_cdb_read_cb(struct thread *thread)
+static void frr_confd_cdb_read_cb(struct event *thread)
{
- int fd = THREAD_FD(thread);
+ int fd = EVENT_FD(thread);
enum cdb_sub_notification cdb_ev;
int flags;
int *subp = NULL;
int reslen = 0;
- thread_add_read(master, frr_confd_cdb_read_cb, NULL, fd, &t_cdb_sub);
+ event_add_read(master, frr_confd_cdb_read_cb, NULL, fd, &t_cdb_sub);
if (cdb_read_subscription_socket2(fd, &cdb_ev, &flags, &subp, &reslen)
!= CONFD_OK) {
@@ -574,8 +574,8 @@ static int frr_confd_init_cdb(void)
}
pthread_detach(cdb_trigger_thread);
- thread_add_read(master, frr_confd_cdb_read_cb, NULL, cdb_sub_sock,
- &t_cdb_sub);
+ event_add_read(master, frr_confd_cdb_read_cb, NULL, cdb_sub_sock,
+ &t_cdb_sub);
return 0;
@@ -588,7 +588,7 @@ error:
static void frr_confd_finish_cdb(void)
{
if (cdb_sub_sock > 0) {
- THREAD_OFF(t_cdb_sub);
+ EVENT_OFF(t_cdb_sub);
cdb_close(cdb_sub_sock);
}
}
@@ -1173,22 +1173,23 @@ static int frr_confd_dp_read(struct confd_daemon_ctx *dctx, int fd)
return 0;
}
-static void frr_confd_dp_ctl_read(struct thread *thread)
+static void frr_confd_dp_ctl_read(struct event *thread)
{
- struct confd_daemon_ctx *dctx = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct confd_daemon_ctx *dctx = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
- thread_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl);
+ event_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl);
frr_confd_dp_read(dctx, fd);
}
-static void frr_confd_dp_worker_read(struct thread *thread)
+static void frr_confd_dp_worker_read(struct event *thread)
{
- struct confd_daemon_ctx *dctx = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct confd_daemon_ctx *dctx = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
- thread_add_read(master, frr_confd_dp_worker_read, dctx, fd, &t_dp_worker);
+ event_add_read(master, frr_confd_dp_worker_read, dctx, fd,
+ &t_dp_worker);
frr_confd_dp_read(dctx, fd);
}
@@ -1320,10 +1321,10 @@ static int frr_confd_init_dp(const char *program_name)
goto error;
}
- thread_add_read(master, frr_confd_dp_ctl_read, dctx, dp_ctl_sock,
- &t_dp_ctl);
- thread_add_read(master, frr_confd_dp_worker_read, dctx, dp_worker_sock,
- &t_dp_worker);
+ event_add_read(master, frr_confd_dp_ctl_read, dctx, dp_ctl_sock,
+ &t_dp_ctl);
+ event_add_read(master, frr_confd_dp_worker_read, dctx, dp_worker_sock,
+ &t_dp_worker);
return 0;
@@ -1336,11 +1337,11 @@ error:
static void frr_confd_finish_dp(void)
{
if (dp_worker_sock > 0) {
- THREAD_OFF(t_dp_worker);
+ EVENT_OFF(t_dp_worker);
close(dp_worker_sock);
}
if (dp_ctl_sock > 0) {
- THREAD_OFF(t_dp_ctl);
+ EVENT_OFF(t_dp_ctl);
close(dp_ctl_sock);
}
if (dctx != NULL)
@@ -1464,7 +1465,7 @@ static int frr_confd_finish(void)
return 0;
}
-static int frr_confd_module_late_init(struct thread_master *tm)
+static int frr_confd_module_late_init(struct event_loop *tm)
{
master = tm;
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp
index 274a0ca45a..6c33351cef 100644
--- a/lib/northbound_grpc.cpp
+++ b/lib/northbound_grpc.cpp
@@ -12,7 +12,7 @@
#include "log.h"
#include "libfrr.h"
#include "lib/version.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "command.h"
#include "lib_errors.h"
#include "northbound.h"
@@ -38,7 +38,7 @@
*/
static bool nb_dbg_client_grpc = 0;
-static struct thread_master *main_master;
+static struct event_loop *main_master;
static struct frr_pthread *fpt;
@@ -157,8 +157,7 @@ class RpcStateBase
* state will either be MORE or FINISH. It will always be FINISH
* for Unary RPCs.
*/
- thread_add_event(main_master, c_callback, (void *)this, 0,
- NULL);
+ event_add_event(main_master, c_callback, (void *)this, 0, NULL);
pthread_mutex_lock(&this->cmux);
while (this->state == PROCESS)
@@ -181,11 +180,11 @@ class RpcStateBase
}
protected:
- virtual CallState run_mainthread(struct thread *thread) = 0;
+ virtual CallState run_mainthread(struct event *thread) = 0;
- static void c_callback(struct thread *thread)
+ static void c_callback(struct event *thread)
{
- auto _tag = static_cast<RpcStateBase *>(THREAD_ARG(thread));
+ auto _tag = static_cast<RpcStateBase *>(EVENT_ARG(thread));
/*
* We hold the lock until the callback finishes and has updated
* _tag->state, then we signal done and release.
@@ -250,7 +249,7 @@ template <typename Q, typename S> class UnaryRpcState : public RpcStateBase
&copy->responder, cq, cq, copy);
}
- CallState run_mainthread(struct thread *thread) override
+ CallState run_mainthread(struct event *thread) override
{
// Unary RPC are always finished, see "Unary" :)
grpc::Status status = this->callback(this);
@@ -302,7 +301,7 @@ class StreamRpcState : public RpcStateBase
&copy->async_responder, cq, cq, copy);
}
- CallState run_mainthread(struct thread *thread) override
+ CallState run_mainthread(struct event *thread) override
{
if (this->callback(this))
return MORE;
@@ -1275,7 +1274,7 @@ static int frr_grpc_finish(void)
* fork. This is done by scheduling this init function as an event task, since
* the event loop doesn't run until after fork.
*/
-static void frr_grpc_module_very_late_init(struct thread *thread)
+static void frr_grpc_module_very_late_init(struct event *thread)
{
const char *args = THIS_MODULE->load_args;
uint port = GRPC_DEFAULT_PORT;
@@ -1299,11 +1298,11 @@ error:
flog_err(EC_LIB_GRPC_INIT, "failed to initialize the gRPC module");
}
-static int frr_grpc_module_late_init(struct thread_master *tm)
+static int frr_grpc_module_late_init(struct event_loop *tm)
{
main_master = tm;
hook_register(frr_fini, frr_grpc_finish);
- thread_add_event(tm, frr_grpc_module_very_late_init, NULL, 0, NULL);
+ event_add_event(tm, frr_grpc_module_very_late_init, NULL, 0, NULL);
return 0;
}
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c
index 337fb690d1..86105d2e77 100644
--- a/lib/northbound_sysrepo.c
+++ b/lib/northbound_sysrepo.c
@@ -23,12 +23,12 @@ DEFINE_MTYPE_STATIC(LIB, SYSREPO, "Sysrepo module");
static struct debug nb_dbg_client_sysrepo = {0, "Northbound client: Sysrepo"};
-static struct thread_master *master;
+static struct event_loop *master;
static sr_session_ctx_t *session;
static sr_conn_ctx_t *connection;
static struct nb_transaction *transaction;
-static void frr_sr_read_cb(struct thread *thread);
+static void frr_sr_read_cb(struct event *thread);
static int frr_sr_finish(void);
/* Convert FRR YANG data value to sysrepo YANG data value. */
@@ -514,10 +514,10 @@ static int frr_sr_notification_send(const char *xpath, struct list *arguments)
return NB_OK;
}
-static void frr_sr_read_cb(struct thread *thread)
+static void frr_sr_read_cb(struct event *thread)
{
- struct yang_module *module = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct yang_module *module = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
int ret;
ret = sr_subscription_process_events(module->sr_subscription, session,
@@ -528,7 +528,7 @@ static void frr_sr_read_cb(struct thread *thread)
return;
}
- thread_add_read(master, frr_sr_read_cb, module, fd, &module->sr_thread);
+ event_add_read(master, frr_sr_read_cb, module, fd, &module->sr_thread);
}
static void frr_sr_subscribe_config(struct yang_module *module)
@@ -688,8 +688,8 @@ static int frr_sr_init(void)
sr_strerror(ret));
goto cleanup;
}
- thread_add_read(master, frr_sr_read_cb, module,
- event_pipe, &module->sr_thread);
+ event_add_read(master, frr_sr_read_cb, module, event_pipe,
+ &module->sr_thread);
}
hook_register(nb_notification_send, frr_sr_notification_send);
@@ -710,7 +710,7 @@ static int frr_sr_finish(void)
if (!module->sr_subscription)
continue;
sr_unsubscribe(module->sr_subscription);
- THREAD_OFF(module->sr_thread);
+ EVENT_OFF(module->sr_thread);
}
if (session)
@@ -721,7 +721,7 @@ static int frr_sr_finish(void)
return 0;
}
-static int frr_sr_module_config_loaded(struct thread_master *tm)
+static int frr_sr_module_config_loaded(struct event_loop *tm)
{
master = tm;
@@ -736,7 +736,7 @@ static int frr_sr_module_config_loaded(struct thread_master *tm)
return 0;
}
-static int frr_sr_module_late_init(struct thread_master *tm)
+static int frr_sr_module_late_init(struct event_loop *tm)
{
frr_sr_cli_init();
diff --git a/lib/pullwr.c b/lib/pullwr.c
index 5bc566c285..3967eb5875 100644
--- a/lib/pullwr.c
+++ b/lib/pullwr.c
@@ -16,9 +16,9 @@
struct pullwr {
int fd;
- struct thread_master *tm;
+ struct event_loop *tm;
/* writer == NULL <=> we're idle */
- struct thread *writer;
+ struct event *writer;
void *arg;
void (*fill)(void *, struct pullwr *);
@@ -38,12 +38,11 @@ struct pullwr {
DEFINE_MTYPE_STATIC(LIB, PULLWR_HEAD, "pull-driven write controller");
DEFINE_MTYPE_STATIC(LIB, PULLWR_BUF, "pull-driven write buffer");
-static void pullwr_run(struct thread *t);
+static void pullwr_run(struct event *t);
-struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
- void *arg,
- void (*fill)(void *, struct pullwr *),
- void (*err)(void *, struct pullwr *, bool))
+struct pullwr *_pullwr_new(struct event_loop *tm, int fd, void *arg,
+ void (*fill)(void *, struct pullwr *),
+ void (*err)(void *, struct pullwr *, bool))
{
struct pullwr *pullwr;
@@ -62,7 +61,7 @@ struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
void pullwr_del(struct pullwr *pullwr)
{
- THREAD_OFF(pullwr->writer);
+ EVENT_OFF(pullwr->writer);
XFREE(MTYPE_PULLWR_BUF, pullwr->buffer);
XFREE(MTYPE_PULLWR_HEAD, pullwr);
@@ -80,7 +79,7 @@ void pullwr_bump(struct pullwr *pullwr)
if (pullwr->writer)
return;
- thread_add_timer(pullwr->tm, pullwr_run, pullwr, 0, &pullwr->writer);
+ event_add_timer(pullwr->tm, pullwr_run, pullwr, 0, &pullwr->writer);
}
static size_t pullwr_iov(struct pullwr *pullwr, struct iovec *iov)
@@ -176,9 +175,9 @@ void pullwr_write(struct pullwr *pullwr, const void *data, size_t len)
pullwr_bump(pullwr);
}
-static void pullwr_run(struct thread *t)
+static void pullwr_run(struct event *t)
{
- struct pullwr *pullwr = THREAD_ARG(t);
+ struct pullwr *pullwr = EVENT_ARG(t);
struct iovec iov[2];
size_t niov, lastvalid;
ssize_t nwr;
@@ -206,7 +205,7 @@ static void pullwr_run(struct thread *t)
if (pullwr->valid == 0) {
/* we made a fill() call above that didn't feed any
* data in, and we have nothing more queued, so we go
- * into idle, i.e. no calling thread_add_write()
+ * into idle, i.e. no calling event_add_write()
*/
pullwr_resize(pullwr, 0);
return;
@@ -237,7 +236,7 @@ static void pullwr_run(struct thread *t)
* is full and we go wait until it's available for writing again.
*/
- thread_add_write(pullwr->tm, pullwr_run, pullwr, pullwr->fd,
+ event_add_write(pullwr->tm, pullwr_run, pullwr, pullwr->fd,
&pullwr->writer);
/* if we hit the time limit, just keep the buffer, we'll probably need
diff --git a/lib/pullwr.h b/lib/pullwr.h
index 77ecf855b4..ef2e01c04e 100644
--- a/lib/pullwr.h
+++ b/lib/pullwr.h
@@ -10,7 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#ifdef __cplusplus
@@ -45,10 +45,10 @@ struct pullwr;
* and released with pullwr_del(). This can be done from inside the callback,
* the pullwr code holds no more references on it when calling err().
*/
-extern struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
- void *arg,
- void (*fill)(void *, struct pullwr *),
- void (*err)(void *, struct pullwr *, bool eof));
+extern struct pullwr *_pullwr_new(struct event_loop *tm, int fd, void *arg,
+ void (*fill)(void *, struct pullwr *),
+ void (*err)(void *, struct pullwr *,
+ bool eof));
extern void pullwr_del(struct pullwr *pullwr);
/* type-checking wrapper. makes sure fill() and err() take a first argument
diff --git a/lib/qobj.c b/lib/qobj.c
index 09b156ba39..b9630e7547 100644
--- a/lib/qobj.c
+++ b/lib/qobj.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "log.h"
diff --git a/lib/resolver.c b/lib/resolver.c
index 2918576c03..99bf356eb3 100644
--- a/lib/resolver.c
+++ b/lib/resolver.c
@@ -12,7 +12,7 @@
#include "typesafe.h"
#include "jhash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib_errors.h"
#include "resolver.h"
#include "command.h"
@@ -23,8 +23,8 @@ XREF_SETUP();
struct resolver_state {
ares_channel channel;
- struct thread_master *master;
- struct thread *timeout;
+ struct event_loop *master;
+ struct event *timeout;
};
static struct resolver_state state;
@@ -47,7 +47,7 @@ struct resolver_fd {
int fd;
struct resolver_state *state;
- struct thread *t_read, *t_write;
+ struct event *t_read, *t_write;
};
static int resolver_fd_cmp(const struct resolver_fd *a,
@@ -100,38 +100,38 @@ static void resolver_fd_drop_maybe(struct resolver_fd *resfd)
static void resolver_update_timeouts(struct resolver_state *r);
-static void resolver_cb_timeout(struct thread *t)
+static void resolver_cb_timeout(struct event *t)
{
- struct resolver_state *r = THREAD_ARG(t);
+ struct resolver_state *r = EVENT_ARG(t);
ares_process(r->channel, NULL, NULL);
resolver_update_timeouts(r);
}
-static void resolver_cb_socket_readable(struct thread *t)
+static void resolver_cb_socket_readable(struct event *t)
{
- struct resolver_fd *resfd = THREAD_ARG(t);
+ struct resolver_fd *resfd = EVENT_ARG(t);
struct resolver_state *r = resfd->state;
- thread_add_read(r->master, resolver_cb_socket_readable, resfd,
- resfd->fd, &resfd->t_read);
+ event_add_read(r->master, resolver_cb_socket_readable, resfd, resfd->fd,
+ &resfd->t_read);
/* ^ ordering important:
- * ares_process_fd may transitively call THREAD_OFF(resfd->t_read)
+ * ares_process_fd may transitively call EVENT_OFF(resfd->t_read)
* combined with resolver_fd_drop_maybe, so resfd may be free'd after!
*/
ares_process_fd(r->channel, resfd->fd, ARES_SOCKET_BAD);
resolver_update_timeouts(r);
}
-static void resolver_cb_socket_writable(struct thread *t)
+static void resolver_cb_socket_writable(struct event *t)
{
- struct resolver_fd *resfd = THREAD_ARG(t);
+ struct resolver_fd *resfd = EVENT_ARG(t);
struct resolver_state *r = resfd->state;
- thread_add_write(r->master, resolver_cb_socket_writable, resfd,
- resfd->fd, &resfd->t_write);
+ event_add_write(r->master, resolver_cb_socket_writable, resfd,
+ resfd->fd, &resfd->t_write);
/* ^ ordering important:
- * ares_process_fd may transitively call THREAD_OFF(resfd->t_write)
+ * ares_process_fd may transitively call EVENT_OFF(resfd->t_write)
* combined with resolver_fd_drop_maybe, so resfd may be free'd after!
*/
ares_process_fd(r->channel, ARES_SOCKET_BAD, resfd->fd);
@@ -142,13 +142,13 @@ static void resolver_update_timeouts(struct resolver_state *r)
{
struct timeval *tv, tvbuf;
- THREAD_OFF(r->timeout);
+ EVENT_OFF(r->timeout);
tv = ares_timeout(r->channel, NULL, &tvbuf);
if (tv) {
unsigned int timeoutms = tv->tv_sec * 1000 + tv->tv_usec / 1000;
- thread_add_timer_msec(r->master, resolver_cb_timeout, r,
- timeoutms, &r->timeout);
+ event_add_timer_msec(r->master, resolver_cb_timeout, r,
+ timeoutms, &r->timeout);
}
}
@@ -165,16 +165,16 @@ static void ares_socket_cb(void *data, ares_socket_t fd, int readable,
assert(resfd->state == r);
if (!readable)
- THREAD_OFF(resfd->t_read);
+ EVENT_OFF(resfd->t_read);
else if (!resfd->t_read)
- thread_add_read(r->master, resolver_cb_socket_readable, resfd,
- fd, &resfd->t_read);
+ event_add_read(r->master, resolver_cb_socket_readable, resfd,
+ fd, &resfd->t_read);
if (!writable)
- THREAD_OFF(resfd->t_write);
+ EVENT_OFF(resfd->t_write);
else if (!resfd->t_write)
- thread_add_write(r->master, resolver_cb_socket_writable, resfd,
- fd, &resfd->t_write);
+ event_add_write(r->master, resolver_cb_socket_writable, resfd,
+ fd, &resfd->t_write);
resolver_fd_drop_maybe(resfd);
}
@@ -222,9 +222,9 @@ static void ares_address_cb(void *arg, int status, int timeouts,
callback(query, NULL, i, &addr[0]);
}
-static void resolver_cb_literal(struct thread *t)
+static void resolver_cb_literal(struct event *t)
{
- struct resolver_query *query = THREAD_ARG(t);
+ struct resolver_query *query = EVENT_ARG(t);
void (*callback)(struct resolver_query *, const char *, int,
union sockunion *);
@@ -264,8 +264,8 @@ void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
/* for consistency with proper name lookup, don't call the
* callback immediately; defer to thread loop
*/
- thread_add_timer_msec(state.master, resolver_cb_literal,
- query, 0, &query->literal_cb);
+ event_add_timer_msec(state.master, resolver_cb_literal, query,
+ 0, &query->literal_cb);
return;
}
@@ -314,7 +314,7 @@ static int resolver_config_write_debug(struct vty *vty)
}
-void resolver_init(struct thread_master *tm)
+void resolver_init(struct event_loop *tm)
{
struct ares_options ares_opts;
diff --git a/lib/resolver.h b/lib/resolver.h
index d3f38f742d..87e8ecdc4a 100644
--- a/lib/resolver.h
+++ b/lib/resolver.h
@@ -6,7 +6,7 @@
#ifndef _FRR_RESOLVER_H
#define _FRR_RESOLVER_H
-#include "thread.h"
+#include "frrevent.h"
#include "sockunion.h"
#ifdef __cplusplus
@@ -19,10 +19,10 @@ struct resolver_query {
/* used to immediate provide the result if IP literal is passed in */
union sockunion literal_addr;
- struct thread *literal_cb;
+ struct event *literal_cb;
};
-void resolver_init(struct thread_master *tm);
+void resolver_init(struct event_loop *tm);
void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
const char *hostname,
void (*cb)(struct resolver_query *, const char *, int,
diff --git a/lib/sigevent.c b/lib/sigevent.c
index 3ed34894e5..3cd65eb800 100644
--- a/lib/sigevent.c
+++ b/lib/sigevent.c
@@ -22,7 +22,7 @@
/* master signals descriptor struct */
static struct frr_sigevent_master_t {
- struct thread *t;
+ struct event *t;
struct frr_signal_t *signals;
int sigc;
@@ -127,14 +127,14 @@ int frr_sigevent_process(void)
#ifdef SIGEVENT_SCHEDULE_THREAD
/* timer thread to check signals. shouldn't be needed */
-void frr_signal_timer(struct thread *t)
+void frr_signal_timer(struct event *t)
{
struct frr_sigevent_master_t *sigm;
- sigm = THREAD_ARG(t);
+ sigm = EVENT_ARG(t);
sigm->t = NULL;
- thread_add_timer(sigm->t->master, frr_signal_timer, &sigmaster,
- FRR_SIGNAL_TIMER_INTERVAL, &sigm->t);
+ event_add_timer(sigm->t->master, frr_signal_timer, &sigmaster,
+ FRR_SIGNAL_TIMER_INTERVAL, &sigm->t);
frr_sigevent_process();
}
#endif /* SIGEVENT_SCHEDULE_THREAD */
@@ -331,8 +331,7 @@ static void trap_default_signals(void)
}
}
-void signal_init(struct thread_master *m, int sigc,
- struct frr_signal_t signals[])
+void signal_init(struct event_loop *m, int sigc, struct frr_signal_t signals[])
{
int i = 0;
@@ -354,7 +353,7 @@ void signal_init(struct thread_master *m, int sigc,
#ifdef SIGEVENT_SCHEDULE_THREAD
sigmaster.t = NULL;
- thread_add_timer(m, frr_signal_timer, &sigmaster,
- FRR_SIGNAL_TIMER_INTERVAL, &sigmaster.t);
+ event_add_timer(m, frr_signal_timer, &sigmaster,
+ FRR_SIGNAL_TIMER_INTERVAL, &sigmaster.t);
#endif /* SIGEVENT_SCHEDULE_THREAD */
}
diff --git a/lib/sigevent.h b/lib/sigevent.h
index e58b9a70c0..0b07f594c1 100644
--- a/lib/sigevent.h
+++ b/lib/sigevent.h
@@ -8,7 +8,7 @@
#ifndef _FRR_SIGNAL_H
#define _FRR_SIGNAL_H
-#include <thread.h>
+#include <frrevent.h>
#ifdef __cplusplus
extern "C" {
@@ -25,12 +25,12 @@ struct frr_signal_t {
/* initialise sigevent system
* takes:
- * - pointer to valid struct thread_master
+ * - pointer to valid struct event_loop
* - number of elements in passed in signals array
* - array of frr_signal_t's describing signals to handle
* and handlers to use for each signal
*/
-extern void signal_init(struct thread_master *m, int sigc,
+extern void signal_init(struct event_loop *m, int sigc,
struct frr_signal_t *signals);
diff --git a/lib/smux.h b/lib/smux.h
index 28a303cf72..cec4d2a1bf 100644
--- a/lib/smux.h
+++ b/lib/smux.h
@@ -9,7 +9,7 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/snmp_vars.h>
-#include "thread.h"
+#include "frrevent.h"
#include "hook.h"
#ifdef __cplusplus
@@ -99,7 +99,7 @@ struct index_oid {
*/
extern bool smux_enabled(void);
-extern void smux_init(struct thread_master *tm);
+extern void smux_init(struct event_loop *tm);
extern void smux_agentx_enable(void);
extern void smux_register_mib(const char *, struct variable *, size_t, int,
oid[], size_t);
diff --git a/lib/spf_backoff.c b/lib/spf_backoff.c
index 1e80b5ec2d..b05c44ddf7 100644
--- a/lib/spf_backoff.c
+++ b/lib/spf_backoff.c
@@ -17,7 +17,7 @@
#include "command.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
DEFINE_MTYPE_STATIC(LIB, SPF_BACKOFF, "SPF backoff");
@@ -37,7 +37,7 @@ enum spf_backoff_state {
};
struct spf_backoff {
- struct thread_master *m;
+ struct event_loop *m;
/* Timers as per draft */
long init_delay;
@@ -48,8 +48,8 @@ struct spf_backoff {
/* State machine */
enum spf_backoff_state state;
- struct thread *t_holddown;
- struct thread *t_timetolearn;
+ struct event *t_holddown;
+ struct event *t_timetolearn;
/* For debugging */
char *name;
@@ -70,7 +70,7 @@ static const char *spf_backoff_state2str(enum spf_backoff_state state)
return "???";
}
-struct spf_backoff *spf_backoff_new(struct thread_master *m, const char *name,
+struct spf_backoff *spf_backoff_new(struct event_loop *m, const char *name,
long init_delay, long short_delay,
long long_delay, long holddown,
long timetolearn)
@@ -97,27 +97,27 @@ void spf_backoff_free(struct spf_backoff *backoff)
if (!backoff)
return;
- thread_cancel(&backoff->t_holddown);
- thread_cancel(&backoff->t_timetolearn);
+ event_cancel(&backoff->t_holddown);
+ event_cancel(&backoff->t_timetolearn);
XFREE(MTYPE_SPF_BACKOFF_NAME, backoff->name);
XFREE(MTYPE_SPF_BACKOFF, backoff);
}
-static void spf_backoff_timetolearn_elapsed(struct thread *thread)
+static void spf_backoff_timetolearn_elapsed(struct event *thread)
{
- struct spf_backoff *backoff = THREAD_ARG(thread);
+ struct spf_backoff *backoff = EVENT_ARG(thread);
backoff->state = SPF_BACKOFF_LONG_WAIT;
backoff_debug("SPF Back-off(%s) TIMETOLEARN elapsed, move to state %s",
backoff->name, spf_backoff_state2str(backoff->state));
}
-static void spf_backoff_holddown_elapsed(struct thread *thread)
+static void spf_backoff_holddown_elapsed(struct event *thread)
{
- struct spf_backoff *backoff = THREAD_ARG(thread);
+ struct spf_backoff *backoff = EVENT_ARG(thread);
- THREAD_OFF(backoff->t_timetolearn);
+ EVENT_OFF(backoff->t_timetolearn);
timerclear(&backoff->first_event_time);
backoff->state = SPF_BACKOFF_QUIET;
backoff_debug("SPF Back-off(%s) HOLDDOWN elapsed, move to state %s",
@@ -139,21 +139,21 @@ long spf_backoff_schedule(struct spf_backoff *backoff)
switch (backoff->state) {
case SPF_BACKOFF_QUIET:
backoff->state = SPF_BACKOFF_SHORT_WAIT;
- thread_add_timer_msec(
+ event_add_timer_msec(
backoff->m, spf_backoff_timetolearn_elapsed, backoff,
backoff->timetolearn, &backoff->t_timetolearn);
- thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
- backoff, backoff->holddown,
- &backoff->t_holddown);
+ event_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
+ backoff, backoff->holddown,
+ &backoff->t_holddown);
backoff->first_event_time = now;
rv = backoff->init_delay;
break;
case SPF_BACKOFF_SHORT_WAIT:
case SPF_BACKOFF_LONG_WAIT:
- thread_cancel(&backoff->t_holddown);
- thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
- backoff, backoff->holddown,
- &backoff->t_holddown);
+ event_cancel(&backoff->t_holddown);
+ event_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
+ backoff, backoff->holddown,
+ &backoff->t_holddown);
if (backoff->state == SPF_BACKOFF_SHORT_WAIT)
rv = backoff->short_delay;
else
@@ -204,8 +204,8 @@ void spf_backoff_show(struct spf_backoff *backoff, struct vty *vty,
vty_out(vty, "%sHolddown timer: %ld msec\n", prefix,
backoff->holddown);
if (backoff->t_holddown) {
- struct timeval remain =
- thread_timer_remain(backoff->t_holddown);
+ struct timeval remain = event_timer_remain(backoff->t_holddown);
+
vty_out(vty, "%s Still runs for %lld msec\n",
prefix,
(long long)remain.tv_sec * 1000
@@ -218,7 +218,7 @@ void spf_backoff_show(struct spf_backoff *backoff, struct vty *vty,
backoff->timetolearn);
if (backoff->t_timetolearn) {
struct timeval remain =
- thread_timer_remain(backoff->t_timetolearn);
+ event_timer_remain(backoff->t_timetolearn);
vty_out(vty, "%s Still runs for %lld msec\n",
prefix,
(long long)remain.tv_sec * 1000
diff --git a/lib/spf_backoff.h b/lib/spf_backoff.h
index 87aa4a0825..83f1b76adc 100644
--- a/lib/spf_backoff.h
+++ b/lib/spf_backoff.h
@@ -18,10 +18,10 @@ extern "C" {
#endif
struct spf_backoff;
-struct thread_master;
+struct event_loop;
struct vty;
-struct spf_backoff *spf_backoff_new(struct thread_master *m, const char *name,
+struct spf_backoff *spf_backoff_new(struct event_loop *m, const char *name,
long init_delay, long short_delay,
long long_delay, long holddown,
long timetolearn);
diff --git a/lib/subdir.am b/lib/subdir.am
index d456629bbd..469fac2446 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -108,7 +108,7 @@ lib_libfrr_la_SOURCES = \
lib/systemd.c \
lib/table.c \
lib/termtable.c \
- lib/thread.c \
+ lib/event.c \
lib/typerb.c \
lib/typesafe.c \
lib/vector.c \
@@ -181,7 +181,7 @@ clippy_scan += \
lib/plist.c \
lib/routemap.c \
lib/routemap_cli.c \
- lib/thread.c \
+ lib/event.c \
lib/vty.c \
lib/zlog_5424_cli.c \
# end
@@ -288,7 +288,7 @@ pkginclude_HEADERS += \
lib/systemd.h \
lib/table.h \
lib/termtable.h \
- lib/thread.h \
+ lib/frrevent.h \
lib/trace.h \
lib/typerb.h \
lib/typesafe.h \
diff --git a/lib/systemd.c b/lib/systemd.c
index 0106e88b93..56a53a6e78 100644
--- a/lib/systemd.c
+++ b/lib/systemd.c
@@ -7,7 +7,7 @@
#include <zebra.h>
#include <sys/un.h>
-#include "thread.h"
+#include "frrevent.h"
#include "systemd.h"
#include "lib_errors.h"
@@ -63,18 +63,18 @@ void systemd_send_stopping(void)
systemd_send_information("STOPPING=1");
}
-static struct thread_master *systemd_master = NULL;
+static struct event_loop *systemd_master = NULL;
-static void systemd_send_watchdog(struct thread *t)
+static void systemd_send_watchdog(struct event *t)
{
systemd_send_information("WATCHDOG=1");
assert(watchdog_msec > 0);
- thread_add_timer_msec(systemd_master, systemd_send_watchdog, NULL,
- watchdog_msec, NULL);
+ event_add_timer_msec(systemd_master, systemd_send_watchdog, NULL,
+ watchdog_msec, NULL);
}
-void systemd_send_started(struct thread_master *m)
+void systemd_send_started(struct event_loop *m)
{
assert(m != NULL);
diff --git a/lib/systemd.h b/lib/systemd.h
index 09f27a70ba..ba2461b8a1 100644
--- a/lib/systemd.h
+++ b/lib/systemd.h
@@ -21,11 +21,11 @@ extern bool sd_stderr_is_journal;
void systemd_send_stopping(void);
/*
- * master - The struct thread_master * to use to schedule ourself
+ * master - The struct event_loop * to use to schedule ourself
* the_process - Should we send watchdog if we are not the requested
* process?
*/
-void systemd_send_started(struct thread_master *master);
+void systemd_send_started(struct event_loop *master);
/*
* status - A status string to send to systemd
diff --git a/lib/thread.h b/lib/thread.h
deleted file mode 100644
index 128d11b6eb..0000000000
--- a/lib/thread.h
+++ /dev/null
@@ -1,291 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Thread management routine header.
- * Copyright (C) 1998 Kunihiro Ishiguro
- */
-
-#ifndef _ZEBRA_THREAD_H
-#define _ZEBRA_THREAD_H
-
-#include <zebra.h>
-#include <pthread.h>
-#include <poll.h>
-#include "monotime.h"
-#include "frratomic.h"
-#include "typesafe.h"
-#include "xref.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern bool cputime_enabled;
-extern unsigned long cputime_threshold;
-/* capturing wallclock time is always enabled since it is fast (reading
- * hardware TSC w/o syscalls)
- */
-extern unsigned long walltime_threshold;
-
-struct rusage_t {
-#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
- struct timespec cpu;
-#else
- struct rusage cpu;
-#endif
- struct timeval real;
-};
-#define RUSAGE_T struct rusage_t
-
-#define GETRUSAGE(X) thread_getrusage(X)
-
-PREDECL_LIST(thread_list);
-PREDECL_HEAP(thread_timer_list);
-
-struct fd_handler {
- /* number of pfd that fit in the allocated space of pfds. This is a
- * constant and is the same for both pfds and copy.
- */
- nfds_t pfdsize;
-
- /* file descriptors to monitor for i/o */
- struct pollfd *pfds;
- /* number of pollfds stored in pfds */
- nfds_t pfdcount;
-
- /* chunk used for temp copy of pollfds */
- struct pollfd *copy;
- /* number of pollfds stored in copy */
- nfds_t copycount;
-};
-
-struct xref_threadsched {
- struct xref xref;
-
- const char *funcname;
- const char *dest;
- uint32_t thread_type;
-};
-
-/* Master of the theads. */
-struct thread_master {
- char *name;
-
- struct thread **read;
- struct thread **write;
- struct thread_timer_list_head timer;
- struct thread_list_head event, ready, unuse;
- struct list *cancel_req;
- bool canceled;
- pthread_cond_t cancel_cond;
- struct hash *cpu_record;
- int io_pipe[2];
- int fd_limit;
- struct fd_handler handler;
- unsigned long alloc;
- long selectpoll_timeout;
- bool spin;
- bool handle_signals;
- pthread_mutex_t mtx;
- pthread_t owner;
-
- bool ready_run_loop;
- RUSAGE_T last_getrusage;
-};
-
-/* Thread itself. */
-struct thread {
- uint8_t type; /* thread type */
- uint8_t add_type; /* thread type */
- struct thread_list_item threaditem;
- struct thread_timer_list_item timeritem;
- struct thread **ref; /* external reference (if given) */
- struct thread_master *master; /* pointer to the struct thread_master */
- void (*func)(struct thread *); /* event function */
- void *arg; /* event argument */
- union {
- int val; /* second argument of the event. */
- int fd; /* file descriptor in case of r/w */
- struct timeval sands; /* rest of time sands value. */
- } u;
- struct timeval real;
- struct cpu_thread_history *hist; /* cache pointer to cpu_history */
- unsigned long yield; /* yield time in microseconds */
- const struct xref_threadsched *xref; /* origin location */
- pthread_mutex_t mtx; /* mutex for thread.c functions */
- bool ignore_timer_late;
-};
-
-#ifdef _FRR_ATTRIBUTE_PRINTFRR
-#pragma FRR printfrr_ext "%pTH" (struct thread *)
-#endif
-
-struct cpu_thread_history {
- void (*func)(struct thread *);
- atomic_size_t total_cpu_warn;
- atomic_size_t total_wall_warn;
- atomic_size_t total_starv_warn;
- atomic_size_t total_calls;
- atomic_size_t total_active;
- struct time_stats {
- atomic_size_t total, max;
- } real;
- struct time_stats cpu;
- atomic_uint_fast32_t types;
- const char *funcname;
-};
-
-/* Struct timeval's tv_usec one second value. */
-#define TIMER_SECOND_MICRO 1000000L
-
-/* Thread types. */
-#define THREAD_READ 0
-#define THREAD_WRITE 1
-#define THREAD_TIMER 2
-#define THREAD_EVENT 3
-#define THREAD_READY 4
-#define THREAD_UNUSED 5
-#define THREAD_EXECUTE 6
-
-/* Thread yield time. */
-#define THREAD_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
-
-#define THREAD_TIMER_STRLEN 12
-
-/* Macros. */
-#define THREAD_ARG(X) ((X)->arg)
-#define THREAD_FD(X) ((X)->u.fd)
-#define THREAD_VAL(X) ((X)->u.val)
-
-/*
- * Please consider this macro deprecated, and do not use it in new code.
- */
-#define THREAD_OFF(thread) \
- do { \
- if ((thread)) \
- thread_cancel(&(thread)); \
- } while (0)
-
-/*
- * Macro wrappers to generate xrefs for all thread add calls. Includes
- * file/line/function info for debugging/tracing.
- */
-#include "lib/xref.h"
-
-#define _xref_t_a(addfn, type, m, f, a, v, t) \
- ({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
- .funcname = #f, \
- .dest = #t, \
- .thread_type = THREAD_ ## type, \
- }; \
- XREF_LINK(_xref.xref); \
- _thread_add_ ## addfn(&_xref, m, f, a, v, t); \
- }) \
- /* end */
-
-#define thread_add_read(m,f,a,v,t) _xref_t_a(read_write, READ, m,f,a,v,t)
-#define thread_add_write(m,f,a,v,t) _xref_t_a(read_write, WRITE, m,f,a,v,t)
-#define thread_add_timer(m,f,a,v,t) _xref_t_a(timer, TIMER, m,f,a,v,t)
-#define thread_add_timer_msec(m,f,a,v,t) _xref_t_a(timer_msec, TIMER, m,f,a,v,t)
-#define thread_add_timer_tv(m,f,a,v,t) _xref_t_a(timer_tv, TIMER, m,f,a,v,t)
-#define thread_add_event(m,f,a,v,t) _xref_t_a(event, EVENT, m,f,a,v,t)
-
-#define thread_execute(m,f,a,v) \
- ({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
- .funcname = #f, \
- .dest = NULL, \
- .thread_type = THREAD_EXECUTE, \
- }; \
- XREF_LINK(_xref.xref); \
- _thread_execute(&_xref, m, f, a, v); \
- }) /* end */
-
-/* Prototypes. */
-extern struct thread_master *thread_master_create(const char *);
-void thread_master_set_name(struct thread_master *master, const char *name);
-extern void thread_master_free(struct thread_master *);
-extern void thread_master_free_unused(struct thread_master *);
-
-extern void _thread_add_read_write(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- int fd, struct thread **tref);
-
-extern void _thread_add_timer(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, long t,
- struct thread **tref);
-
-extern void _thread_add_timer_msec(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- long t, struct thread **tref);
-
-extern void _thread_add_timer_tv(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- struct timeval *tv, struct thread **tref);
-
-extern void _thread_add_event(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, int val,
- struct thread **tref);
-
-extern void _thread_execute(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, int val);
-
-extern void thread_cancel(struct thread **event);
-extern void thread_cancel_async(struct thread_master *, struct thread **,
- void *);
-/* Cancel ready tasks with an arg matching 'arg' */
-extern void thread_cancel_event_ready(struct thread_master *m, void *arg);
-/* Cancel all tasks with an arg matching 'arg', including timers and io */
-extern void thread_cancel_event(struct thread_master *m, void *arg);
-extern struct thread *thread_fetch(struct thread_master *, struct thread *);
-extern void thread_call(struct thread *);
-extern unsigned long thread_timer_remain_second(struct thread *);
-extern struct timeval thread_timer_remain(struct thread *);
-extern unsigned long thread_timer_remain_msec(struct thread *);
-extern int thread_should_yield(struct thread *);
-/* set yield time for thread */
-extern void thread_set_yield_time(struct thread *, unsigned long);
-
-/* Internal libfrr exports */
-extern void thread_getrusage(RUSAGE_T *);
-extern void thread_cmd_init(void);
-
-/* Returns elapsed real (wall clock) time. */
-extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
- unsigned long *cpu_time_elapsed);
-
-/* only for use in logging functions! */
-extern pthread_key_t thread_current;
-extern char *thread_timer_to_hhmmss(char *buf, int buf_size,
- struct thread *t_timer);
-
-static inline bool thread_is_scheduled(struct thread *thread)
-{
- if (thread)
- return true;
-
- return false;
-}
-
-/* Debug signal mask */
-void debug_signals(const sigset_t *sigs);
-
-static inline void thread_ignore_late_timer(struct thread *thread)
-{
- thread->ignore_timer_late = true;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZEBRA_THREAD_H */
diff --git a/lib/vty.c b/lib/vty.c
index 3dcae0282f..d0a6677788 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -22,7 +22,7 @@
#include <stdio.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "command.h"
#include "sockunion.h"
@@ -81,7 +81,7 @@ struct vty_serv {
int sock;
bool vtysh;
- struct thread *t_accept;
+ struct event *t_accept;
};
DECLARE_DLIST(vtyservs, struct vty_serv, itm);
@@ -545,7 +545,7 @@ static int vty_command(struct vty *vty, char *buf)
GETRUSAGE(&after);
- walltime = thread_consumed_time(&after, &before, &cputime);
+ walltime = event_consumed_time(&after, &before, &cputime);
if (cputime_enabled_here && cputime_enabled && cputime_threshold
&& cputime > cputime_threshold)
@@ -1360,13 +1360,13 @@ static void vty_buffer_reset(struct vty *vty)
}
/* Read data via vty socket. */
-static void vty_read(struct thread *thread)
+static void vty_read(struct event *thread)
{
int i;
int nbytes;
unsigned char buf[VTY_READ_BUFSIZ];
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* Read raw data from socket */
if ((nbytes = read(vty->fd, buf, VTY_READ_BUFSIZ)) <= 0) {
@@ -1563,15 +1563,15 @@ static void vty_read(struct thread *thread)
}
/* Flush buffer to the vty. */
-static void vty_flush(struct thread *thread)
+static void vty_flush(struct event *thread)
{
int erase;
buffer_status_t flushrc;
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* Tempolary disable read thread. */
if (vty->lines == 0)
- THREAD_OFF(vty->t_read);
+ EVENT_OFF(vty->t_read);
/* Function execution continue. */
erase = ((vty->status == VTY_MORE || vty->status == VTY_MORELINE));
@@ -1757,9 +1757,9 @@ void vty_stdio_suspend(void)
if (!stdio_vty)
return;
- THREAD_OFF(stdio_vty->t_write);
- THREAD_OFF(stdio_vty->t_read);
- THREAD_OFF(stdio_vty->t_timeout);
+ EVENT_OFF(stdio_vty->t_write);
+ EVENT_OFF(stdio_vty->t_read);
+ EVENT_OFF(stdio_vty->t_timeout);
if (stdio_termios)
tcsetattr(0, TCSANOW, &stdio_orig_termios);
@@ -1823,9 +1823,9 @@ struct vty *vty_stdio(void (*atclose)(int isexit))
}
/* Accept connection from the network. */
-static void vty_accept(struct thread *thread)
+static void vty_accept(struct event *thread)
{
- struct vty_serv *vtyserv = THREAD_ARG(thread);
+ struct vty_serv *vtyserv = EVENT_ARG(thread);
int vty_sock;
union sockunion su;
int ret;
@@ -2036,9 +2036,9 @@ static void vty_serv_un(const char *path)
/* #define VTYSH_DEBUG 1 */
-static void vtysh_accept(struct thread *thread)
+static void vtysh_accept(struct event *thread)
{
- struct vty_serv *vtyserv = THREAD_ARG(thread);
+ struct vty_serv *vtyserv = EVENT_ARG(thread);
int accept_sock = vtyserv->sock;
int sock;
int client_len;
@@ -2166,7 +2166,7 @@ void vty_pass_fd(struct vty *vty, int fd)
vty->pass_fd = fd;
}
-static void vtysh_read(struct thread *thread)
+static void vtysh_read(struct event *thread)
{
int ret;
int sock;
@@ -2176,8 +2176,8 @@ static void vtysh_read(struct thread *thread)
unsigned char *p;
uint8_t header[4] = {0, 0, 0, 0};
- sock = THREAD_FD(thread);
- vty = THREAD_ARG(thread);
+ sock = EVENT_FD(thread);
+ vty = EVENT_ARG(thread);
if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) {
if (nbytes < 0) {
@@ -2275,9 +2275,9 @@ static void vtysh_read(struct thread *thread)
vty_event(VTYSH_READ, vty);
}
-static void vtysh_write(struct thread *thread)
+static void vtysh_write(struct event *thread)
{
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
vtysh_flush(vty);
}
@@ -2322,9 +2322,9 @@ void vty_close(struct vty *vty)
vty_config_exit(vty);
/* Cancel threads.*/
- THREAD_OFF(vty->t_read);
- THREAD_OFF(vty->t_write);
- THREAD_OFF(vty->t_timeout);
+ EVENT_OFF(vty->t_read);
+ EVENT_OFF(vty->t_write);
+ EVENT_OFF(vty->t_timeout);
if (vty->pass_fd != -1) {
close(vty->pass_fd);
@@ -2382,11 +2382,11 @@ void vty_close(struct vty *vty)
}
/* When time out occur output message then close connection. */
-static void vty_timeout(struct thread *thread)
+static void vty_timeout(struct event *thread)
{
struct vty *vty;
- vty = THREAD_ARG(thread);
+ vty = EVENT_ARG(thread);
vty->v_timeout = 0;
/* Clear buffer*/
@@ -2801,19 +2801,19 @@ int vty_config_node_exit(struct vty *vty)
}
/* Master of the threads. */
-static struct thread_master *vty_master;
+static struct event_loop *vty_master;
static void vty_event_serv(enum vty_event event, struct vty_serv *vty_serv)
{
switch (event) {
case VTY_SERV:
- thread_add_read(vty_master, vty_accept, vty_serv,
- vty_serv->sock, &vty_serv->t_accept);
+ event_add_read(vty_master, vty_accept, vty_serv, vty_serv->sock,
+ &vty_serv->t_accept);
break;
#ifdef VTYSH
case VTYSH_SERV:
- thread_add_read(vty_master, vtysh_accept, vty_serv,
- vty_serv->sock, &vty_serv->t_accept);
+ event_add_read(vty_master, vtysh_accept, vty_serv,
+ vty_serv->sock, &vty_serv->t_accept);
break;
#endif /* VTYSH */
case VTY_READ:
@@ -2830,34 +2830,34 @@ static void vty_event(enum vty_event event, struct vty *vty)
switch (event) {
#ifdef VTYSH
case VTYSH_READ:
- thread_add_read(vty_master, vtysh_read, vty, vty->fd,
- &vty->t_read);
+ event_add_read(vty_master, vtysh_read, vty, vty->fd,
+ &vty->t_read);
break;
case VTYSH_WRITE:
- thread_add_write(vty_master, vtysh_write, vty, vty->wfd,
- &vty->t_write);
+ event_add_write(vty_master, vtysh_write, vty, vty->wfd,
+ &vty->t_write);
break;
#endif /* VTYSH */
case VTY_READ:
- thread_add_read(vty_master, vty_read, vty, vty->fd,
- &vty->t_read);
+ event_add_read(vty_master, vty_read, vty, vty->fd,
+ &vty->t_read);
/* Time out treatment. */
if (vty->v_timeout) {
- THREAD_OFF(vty->t_timeout);
- thread_add_timer(vty_master, vty_timeout, vty,
- vty->v_timeout, &vty->t_timeout);
+ EVENT_OFF(vty->t_timeout);
+ event_add_timer(vty_master, vty_timeout, vty,
+ vty->v_timeout, &vty->t_timeout);
}
break;
case VTY_WRITE:
- thread_add_write(vty_master, vty_flush, vty, vty->wfd,
- &vty->t_write);
+ event_add_write(vty_master, vty_flush, vty, vty->wfd,
+ &vty->t_write);
break;
case VTY_TIMEOUT_RESET:
- THREAD_OFF(vty->t_timeout);
+ EVENT_OFF(vty->t_timeout);
if (vty->v_timeout)
- thread_add_timer(vty_master, vty_timeout, vty,
- vty->v_timeout, &vty->t_timeout);
+ event_add_timer(vty_master, vty_timeout, vty,
+ vty->v_timeout, &vty->t_timeout);
break;
case VTY_SERV:
case VTYSH_SERV:
@@ -3655,7 +3655,7 @@ int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
}
/* Install vty's own commands like `who' command. */
-void vty_init(struct thread_master *master_thread, bool do_command_logging)
+void vty_init(struct event_loop *master_thread, bool do_command_logging)
{
/* For further configuration read, preserve current directory. */
vty_save_cwd();
@@ -3726,7 +3726,7 @@ void vty_terminate(void)
vtys_init(vtysh_sessions);
while ((vtyserv = vtyservs_pop(vty_servs))) {
- THREAD_OFF(vtyserv->t_accept);
+ EVENT_OFF(vtyserv->t_accept);
close(vtyserv->sock);
XFREE(MTYPE_VTY_SERV, vtyserv);
}
diff --git a/lib/vty.h b/lib/vty.h
index b302c14913..66d3355329 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -18,7 +18,7 @@
#include <regex.h>
#endif /* HAVE_LIBPCRE2_POSIX */
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "sockunion.h"
#include "qobj.h"
@@ -148,7 +148,7 @@ struct vty {
size_t pending_cmds_bufpos;
/* Confirmed-commit timeout and rollback configuration. */
- struct thread *t_confirmed_commit_timeout;
+ struct event *t_confirmed_commit_timeout;
struct nb_config *confirmed_commit_rollback;
/* qobj object ID (replacement for "index") */
@@ -202,12 +202,12 @@ struct vty {
int lines;
/* Read and write thread. */
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_read;
+ struct event *t_write;
/* Timeout seconds and thread. */
unsigned long v_timeout;
- struct thread *t_timeout;
+ struct event *t_timeout;
/* What address is this vty comming from. */
char address[SU_ADDRSTRLEN];
@@ -337,7 +337,7 @@ struct vty_arg {
extern struct nb_config *vty_mgmt_candidate_config;
/* Prototypes. */
-extern void vty_init(struct thread_master *, bool do_command_logging);
+extern void vty_init(struct event_loop *m, bool do_command_logging);
extern void vty_init_vtysh(void);
extern void vty_terminate(void);
extern void vty_reset(void);
diff --git a/lib/wheel.c b/lib/wheel.c
index 4aca23481b..e17995c64a 100644
--- a/lib/wheel.c
+++ b/lib/wheel.c
@@ -6,7 +6,7 @@
*/
#include "zebra.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "wheel.h"
#include "log.h"
@@ -16,9 +16,9 @@ DEFINE_MTYPE_STATIC(LIB, TIMER_WHEEL_LIST, "Timer Wheel Slot List");
static int debug_timer_wheel = 0;
-static void wheel_timer_thread(struct thread *t);
+static void wheel_timer_thread(struct event *t);
-static void wheel_timer_thread_helper(struct thread *t)
+static void wheel_timer_thread_helper(struct event *t)
{
struct listnode *node, *nextnode;
unsigned long long curr_slot;
@@ -26,7 +26,7 @@ static void wheel_timer_thread_helper(struct thread *t)
struct timer_wheel *wheel;
void *data;
- wheel = THREAD_ARG(t);
+ wheel = EVENT_ARG(t);
wheel->curr_slot += wheel->slots_to_skip;
@@ -47,23 +47,23 @@ static void wheel_timer_thread_helper(struct thread *t)
slots_to_skip++;
wheel->slots_to_skip = slots_to_skip;
- thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
- wheel->nexttime * slots_to_skip, &wheel->timer);
+ event_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
+ wheel->nexttime * slots_to_skip, &wheel->timer);
}
-static void wheel_timer_thread(struct thread *t)
+static void wheel_timer_thread(struct event *t)
{
struct timer_wheel *wheel;
- wheel = THREAD_ARG(t);
+ wheel = EVENT_ARG(t);
- thread_execute(wheel->master, wheel_timer_thread_helper, wheel, 0);
+ event_execute(wheel->master, wheel_timer_thread_helper, wheel, 0);
}
-struct timer_wheel *wheel_init(struct thread_master *master, int period,
- size_t slots, unsigned int (*slot_key)(const void *),
- void (*slot_run)(void *),
- const char *run_name)
+struct timer_wheel *wheel_init(struct event_loop *master, int period,
+ size_t slots,
+ unsigned int (*slot_key)(const void *),
+ void (*slot_run)(void *), const char *run_name)
{
struct timer_wheel *wheel;
size_t i;
@@ -85,8 +85,8 @@ struct timer_wheel *wheel_init(struct thread_master *master, int period,
for (i = 0; i < slots; i++)
wheel->wheel_slot_lists[i] = list_new();
- thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
- wheel->nexttime, &wheel->timer);
+ event_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
+ wheel->nexttime, &wheel->timer);
return wheel;
}
@@ -99,7 +99,7 @@ void wheel_delete(struct timer_wheel *wheel)
list_delete(&wheel->wheel_slot_lists[i]);
}
- THREAD_OFF(wheel->timer);
+ EVENT_OFF(wheel->timer);
XFREE(MTYPE_TIMER_WHEEL_LIST, wheel->wheel_slot_lists);
XFREE(MTYPE_TIMER_WHEEL, wheel->name);
XFREE(MTYPE_TIMER_WHEEL, wheel);
diff --git a/lib/wheel.h b/lib/wheel.h
index 9aa808cdfd..0d9ac10020 100644
--- a/lib/wheel.h
+++ b/lib/wheel.h
@@ -13,7 +13,7 @@ extern "C" {
struct timer_wheel {
char *name;
- struct thread_master *master;
+ struct event_loop *master;
int slots;
long long curr_slot;
unsigned int period;
@@ -21,7 +21,7 @@ struct timer_wheel {
unsigned int slots_to_skip;
struct list **wheel_slot_lists;
- struct thread *timer;
+ struct event *timer;
/*
* Key to determine what slot the item belongs in
*/
@@ -66,7 +66,7 @@ struct timer_wheel {
* and cause significant amount of time handling thread events instead
* of running your code.
*/
-struct timer_wheel *wheel_init(struct thread_master *master, int period,
+struct timer_wheel *wheel_init(struct event_loop *master, int period,
size_t slots,
unsigned int (*slot_key)(const void *),
void (*slot_run)(void *), const char *run_name);
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 5477aadd65..fa5d585360 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "workqueue.h"
#include "linklist.h"
@@ -59,8 +59,7 @@ static void work_queue_item_remove(struct work_queue *wq,
}
/* create new work queue */
-struct work_queue *work_queue_new(struct thread_master *m,
- const char *queue_name)
+struct work_queue *work_queue_new(struct event_loop *m, const char *queue_name)
{
struct work_queue *new;
@@ -78,7 +77,7 @@ struct work_queue *work_queue_new(struct thread_master *m,
/* Default values, can be overridden by caller */
new->spec.hold = WORK_QUEUE_DEFAULT_HOLD;
- new->spec.yield = THREAD_YIELD_TIME_SLOT;
+ new->spec.yield = EVENT_YIELD_TIME_SLOT;
new->spec.retry = WORK_QUEUE_DEFAULT_RETRY;
return new;
@@ -88,7 +87,7 @@ void work_queue_free_and_null(struct work_queue **wqp)
{
struct work_queue *wq = *wqp;
- THREAD_OFF(wq->thread);
+ EVENT_OFF(wq->thread);
while (!work_queue_empty(wq)) {
struct work_queue_item *item = work_queue_last_item(wq);
@@ -106,29 +105,29 @@ void work_queue_free_and_null(struct work_queue **wqp)
bool work_queue_is_scheduled(struct work_queue *wq)
{
- return thread_is_scheduled(wq->thread);
+ return event_is_scheduled(wq->thread);
}
static int work_queue_schedule(struct work_queue *wq, unsigned int delay)
{
/* if appropriate, schedule work queue thread */
if (CHECK_FLAG(wq->flags, WQ_UNPLUGGED) &&
- !thread_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
+ !event_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
/* Schedule timer if there's a delay, otherwise just schedule
* as an 'event'
*/
if (delay > 0) {
- thread_add_timer_msec(wq->master, work_queue_run, wq,
- delay, &wq->thread);
- thread_ignore_late_timer(wq->thread);
+ event_add_timer_msec(wq->master, work_queue_run, wq,
+ delay, &wq->thread);
+ event_ignore_late_timer(wq->thread);
} else
- thread_add_event(wq->master, work_queue_run, wq, 0,
- &wq->thread);
+ event_add_event(wq->master, work_queue_run, wq, 0,
+ &wq->thread);
/* set thread yield time, if needed */
- if (thread_is_scheduled(wq->thread) &&
- wq->spec.yield != THREAD_YIELD_TIME_SLOT)
- thread_set_yield_time(wq->thread, wq->spec.yield);
+ if (event_is_scheduled(wq->thread) &&
+ wq->spec.yield != EVENT_YIELD_TIME_SLOT)
+ event_set_yield_time(wq->thread, wq->spec.yield);
return 1;
} else
return 0;
@@ -198,7 +197,7 @@ void workqueue_cmd_init(void)
*/
void work_queue_plug(struct work_queue *wq)
{
- THREAD_OFF(wq->thread);
+ EVENT_OFF(wq->thread);
UNSET_FLAG(wq->flags, WQ_UNPLUGGED);
}
@@ -218,7 +217,7 @@ void work_queue_unplug(struct work_queue *wq)
* will reschedule itself if required,
* otherwise work_queue_item_add
*/
-void work_queue_run(struct thread *thread)
+void work_queue_run(struct event *thread)
{
struct work_queue *wq;
struct work_queue_item *item, *titem;
@@ -226,7 +225,7 @@ void work_queue_run(struct thread *thread)
unsigned int cycles = 0;
char yielded = 0;
- wq = THREAD_ARG(thread);
+ wq = EVENT_ARG(thread);
assert(wq);
@@ -311,8 +310,8 @@ void work_queue_run(struct thread *thread)
cycles++;
/* test if we should yield */
- if (!(cycles % wq->cycles.granularity)
- && thread_should_yield(thread)) {
+ if (!(cycles % wq->cycles.granularity) &&
+ event_should_yield(thread)) {
yielded = 1;
goto stats;
}
diff --git a/lib/workqueue.h b/lib/workqueue.h
index c7ed14b056..5d84739d5c 100644
--- a/lib/workqueue.h
+++ b/lib/workqueue.h
@@ -47,8 +47,8 @@ struct work_queue {
/* Everything but the specification struct is private
* the following may be read
*/
- struct thread_master *master; /* thread master */
- struct thread *thread; /* thread, if one is active */
+ struct event_loop *master; /* thread master */
+ struct event *thread; /* thread, if one is active */
char *name; /* work queue name */
/* Specification for this work queue.
@@ -137,7 +137,7 @@ static inline void work_queue_item_dequeue(struct work_queue *wq,
* user must fill in the spec of the returned work queue before adding
* anything to it
*/
-extern struct work_queue *work_queue_new(struct thread_master *m,
+extern struct work_queue *work_queue_new(struct event_loop *m,
const char *queue_name);
/* destroy work queue */
@@ -158,7 +158,7 @@ extern void work_queue_unplug(struct work_queue *wq);
bool work_queue_is_scheduled(struct work_queue *wq);
/* Helpers, exported for thread.c and command.c */
-extern void work_queue_run(struct thread *thread);
+extern void work_queue_run(struct event *thread);
extern void workqueue_cmd_init(void);
diff --git a/lib/xref.h b/lib/xref.h
index b49c9eb2f2..f06d65b422 100644
--- a/lib/xref.h
+++ b/lib/xref.h
@@ -20,7 +20,7 @@ extern "C" {
enum xref_type {
XREFT_NONE = 0,
- XREFT_THREADSCHED = 0x100,
+ XREFT_EVENTSCHED = 0x100,
XREFT_LOGMSG = 0x200,
XREFT_ASSERT = 0x280,
diff --git a/lib/yang.h b/lib/yang.h
index 91cd641ce8..654c246f0d 100644
--- a/lib/yang.h
+++ b/lib/yang.h
@@ -50,7 +50,7 @@ struct yang_module {
#endif
#ifdef HAVE_SYSREPO
sr_subscription_ctx_t *sr_subscription;
- struct thread *sr_thread;
+ struct event *sr_thread;
#endif
};
RB_HEAD(yang_modules, yang_module);
diff --git a/lib/zclient.c b/lib/zclient.c
index 0e49d65528..95093a56f5 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -14,7 +14,7 @@
#include "vrf_int.h"
#include "if.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "zclient.h"
#include "memory.h"
#include "table.h"
@@ -51,7 +51,7 @@ socklen_t zclient_addr_len;
static int zclient_debug;
/* Allocate zclient structure. */
-struct zclient *zclient_new(struct thread_master *master,
+struct zclient *zclient_new(struct event_loop *master,
struct zclient_options *opt,
zclient_handler *const *handlers, size_t n_handlers)
{
@@ -160,9 +160,9 @@ void zclient_stop(struct zclient *zclient)
zlog_debug("zclient %p stopped", zclient);
/* Stop threads. */
- THREAD_OFF(zclient->t_read);
- THREAD_OFF(zclient->t_connect);
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_read);
+ EVENT_OFF(zclient->t_connect);
+ EVENT_OFF(zclient->t_write);
/* Reset streams. */
stream_reset(zclient->ibuf);
@@ -249,9 +249,9 @@ static enum zclient_send_status zclient_failed(struct zclient *zclient)
return ZCLIENT_SEND_FAILURE;
}
-static void zclient_flush_data(struct thread *thread)
+static void zclient_flush_data(struct event *thread)
{
- struct zclient *zclient = THREAD_ARG(thread);
+ struct zclient *zclient = EVENT_ARG(thread);
zclient->t_write = NULL;
if (zclient->sock < 0)
@@ -266,8 +266,8 @@ static void zclient_flush_data(struct thread *thread)
return;
case BUFFER_PENDING:
zclient->t_write = NULL;
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
break;
case BUFFER_EMPTY:
if (zclient->zebra_buffer_write_ready)
@@ -295,11 +295,11 @@ enum zclient_send_status zclient_send_message(struct zclient *zclient)
__func__, zclient->sock);
return zclient_failed(zclient);
case BUFFER_EMPTY:
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_write);
return ZCLIENT_SEND_SUCCESS;
case BUFFER_PENDING:
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
return ZCLIENT_SEND_BUFFERED;
}
@@ -744,11 +744,11 @@ void zclient_init(struct zclient *zclient, int redist_default,
/* This function is a wrapper function for calling zclient_start from
timer or event thread. */
-static void zclient_connect(struct thread *t)
+static void zclient_connect(struct event *t)
{
struct zclient *zclient;
- zclient = THREAD_ARG(t);
+ zclient = EVENT_ARG(t);
zclient->t_connect = NULL;
if (zclient_debug)
@@ -4026,7 +4026,7 @@ static zclient_handler *const lib_handlers[] = {
};
/* Zebra client message read function. */
-static void zclient_read(struct thread *thread)
+static void zclient_read(struct event *thread)
{
size_t already;
uint16_t length, command;
@@ -4035,7 +4035,7 @@ static void zclient_read(struct thread *thread)
struct zclient *zclient;
/* Get socket to zebra. */
- zclient = THREAD_ARG(thread);
+ zclient = EVENT_ARG(thread);
zclient->t_read = NULL;
/* Read zebra header (if we don't have it already). */
@@ -4204,22 +4204,22 @@ static void zclient_event(enum zclient_event event, struct zclient *zclient)
{
switch (event) {
case ZCLIENT_SCHEDULE:
- thread_add_event(zclient->master, zclient_connect, zclient, 0,
- &zclient->t_connect);
+ event_add_event(zclient->master, zclient_connect, zclient, 0,
+ &zclient->t_connect);
break;
case ZCLIENT_CONNECT:
if (zclient_debug)
zlog_debug(
"zclient connect failures: %d schedule interval is now %d",
zclient->fail, zclient->fail < 3 ? 10 : 60);
- thread_add_timer(zclient->master, zclient_connect, zclient,
- zclient->fail < 3 ? 10 : 60,
- &zclient->t_connect);
+ event_add_timer(zclient->master, zclient_connect, zclient,
+ zclient->fail < 3 ? 10 : 60,
+ &zclient->t_connect);
break;
case ZCLIENT_READ:
zclient->t_read = NULL;
- thread_add_read(zclient->master, zclient_read, zclient,
- zclient->sock, &zclient->t_read);
+ event_add_read(zclient->master, zclient_read, zclient,
+ zclient->sock, &zclient->t_read);
break;
}
}
diff --git a/lib/zclient.h b/lib/zclient.h
index 53c7038c88..367e5b1474 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -290,7 +290,7 @@ typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS);
/* Structure for the zebra client. */
struct zclient {
/* The thread master we schedule ourselves on */
- struct thread_master *master;
+ struct event_loop *master;
/* Privileges to change socket values */
struct zebra_privs_t *privs;
@@ -323,11 +323,11 @@ struct zclient {
struct buffer *wb;
/* Read and connect thread. */
- struct thread *t_read;
- struct thread *t_connect;
+ struct event *t_read;
+ struct event *t_connect;
/* Thread to write buffered data to zebra. */
- struct thread *t_write;
+ struct event *t_write;
/* Redistribute information. */
uint8_t redist_default; /* clients protocol */
@@ -862,7 +862,7 @@ int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in,
extern uint32_t zclient_get_nhg_start(uint32_t proto);
-extern struct zclient *zclient_new(struct thread_master *m,
+extern struct zclient *zclient_new(struct event_loop *m,
struct zclient_options *opt,
zclient_handler *const *handlers,
size_t n_handlers);
diff --git a/lib/zlog.c b/lib/zlog.c
index e05720fd9e..309a955fa9 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -48,7 +48,7 @@
#include "frrcu.h"
#include "zlog.h"
#include "libfrr_trace.h"
-#include "thread.h"
+#include "frrevent.h"
DEFINE_MTYPE_STATIC(LIB, LOG_MESSAGE, "log message");
DEFINE_MTYPE_STATIC(LIB, LOG_TLSBUF, "log thread-local buffer");
@@ -506,7 +506,7 @@ static void vzlog_tls(struct zlog_tls *zlog_tls, const struct xref_logmsg *xref,
static void zlog_backtrace_msg(const struct xref_logmsg *xref, int prio)
{
- struct thread *tc = pthread_getspecific(thread_current);
+ struct event *tc = pthread_getspecific(thread_current);
const char *uid = xref->xref.xrefdata->uid;
bool found_thread = false;
diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c
index 5264dda0f8..c15bdece29 100644
--- a/lib/zlog_5424.c
+++ b/lib/zlog_5424.c
@@ -26,7 +26,7 @@
#include "frr_pthread.h"
#include "command.h"
#include "monotime.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib/version.h"
#include "lib/lib_errors.h"
@@ -789,10 +789,10 @@ static void zlog_5424_cycle(struct zlog_cfg_5424 *zcf, int fd)
rcu_free(MTYPE_LOG_5424, oldt, zt.rcu_head);
}
-static void zlog_5424_reconnect(struct thread *t)
+static void zlog_5424_reconnect(struct event *t)
{
- struct zlog_cfg_5424 *zcf = THREAD_ARG(t);
- int fd = THREAD_FD(t);
+ struct zlog_cfg_5424 *zcf = EVENT_ARG(t);
+ int fd = EVENT_FD(t);
char dummy[256];
ssize_t ret;
@@ -800,8 +800,8 @@ static void zlog_5424_reconnect(struct thread *t)
ret = read(fd, dummy, sizeof(dummy));
if (ret > 0) {
/* logger is sending us something?!?! */
- thread_add_read(t->master, zlog_5424_reconnect, zcf, fd,
- &zcf->t_reconnect);
+ event_add_read(t->master, zlog_5424_reconnect, zcf, fd,
+ &zcf->t_reconnect);
return;
}
@@ -1030,14 +1030,14 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
assert(zcf->master);
if (fd != -1) {
- thread_add_read(zcf->master, zlog_5424_reconnect, zcf,
- fd, &zcf->t_reconnect);
+ event_add_read(zcf->master, zlog_5424_reconnect, zcf,
+ fd, &zcf->t_reconnect);
zcf->reconn_backoff_cur = zcf->reconn_backoff;
} else {
- thread_add_timer_msec(zcf->master, zlog_5424_reconnect,
- zcf, zcf->reconn_backoff_cur,
- &zcf->t_reconnect);
+ event_add_timer_msec(zcf->master, zlog_5424_reconnect,
+ zcf, zcf->reconn_backoff_cur,
+ &zcf->t_reconnect);
zcf->reconn_backoff_cur += zcf->reconn_backoff_cur / 2;
if (zcf->reconn_backoff_cur > zcf->reconn_backoff_max)
@@ -1053,7 +1053,7 @@ bool zlog_5424_apply_dst(struct zlog_cfg_5424 *zcf)
{
int fd = -1;
- thread_cancel(&zcf->t_reconnect);
+ event_cancel(&zcf->t_reconnect);
if (zcf->prio_min != ZLOG_DISABLED)
fd = zlog_5424_open(zcf, -1);
@@ -1106,7 +1106,7 @@ bool zlog_5424_rotate(struct zlog_cfg_5424 *zcf)
if (!zcf->active)
return true;
- thread_cancel(&zcf->t_reconnect);
+ event_cancel(&zcf->t_reconnect);
/* need to retain the socket type because it also influences
* other fields (packets) and we can't atomically swap these
diff --git a/lib/zlog_5424.h b/lib/zlog_5424.h
index 377e7be220..06525c0044 100644
--- a/lib/zlog_5424.h
+++ b/lib/zlog_5424.h
@@ -13,8 +13,8 @@
#include "zlog_targets.h"
#include "qobj.h"
-struct thread;
-struct thread_master;
+struct event;
+struct event_loop;
enum zlog_5424_dst {
/* can be used to disable a target temporarily */
@@ -78,8 +78,8 @@ struct zlog_cfg_5424 {
*/
/* sockets only - read handler to reconnect on errors */
- struct thread_master *master;
- struct thread *t_reconnect;
+ struct event_loop *master;
+ struct event *t_reconnect;
unsigned int reconn_backoff, reconn_backoff_cur, reconn_backoff_max;
int sock_type;
struct sockaddr_storage sa;
diff --git a/lib/zlog_5424_cli.c b/lib/zlog_5424_cli.c
index 7f070afbc5..3003df542f 100644
--- a/lib/zlog_5424_cli.c
+++ b/lib/zlog_5424_cli.c
@@ -28,7 +28,7 @@ DECLARE_RBTREE_UNIQ(targets, struct zlog_cfg_5424_user, targets_item,
DEFINE_QOBJ_TYPE(zlog_cfg_5424_user);
static struct targets_head targets = INIT_RBTREE_UNIQ(targets);
-static struct thread_master *log_5424_master;
+static struct event_loop *log_5424_master;
static void clear_dst(struct zlog_cfg_5424_user *cfg);
@@ -948,7 +948,7 @@ void log_5424_cmd_init(void)
/* hooks */
-static int log_5424_early_init(struct thread_master *master);
+static int log_5424_early_init(struct event_loop *master);
static int log_5424_rotate(void);
static int log_5424_fini(void);
@@ -959,7 +959,7 @@ __attribute__((_CONSTRUCTOR(475))) static void zlog_5424_startup_init(void)
hook_register(frr_fini, log_5424_fini);
}
-static int log_5424_early_init(struct thread_master *master)
+static int log_5424_early_init(struct event_loop *master)
{
log_5424_master = master;