]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/event.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / event.c
index 95c1d7462258467f4cda8c21eca5891bcb3a4a1c..a8eb89f48d6dc495bae6f6b79f5fa6a7962cece7 100644 (file)
@@ -8,7 +8,7 @@
 #include <zebra.h>
 #include <sys/resource.h>
 
-#include "event.h"
+#include "frrevent.h"
 #include "memory.h"
 #include "frrcu.h"
 #include "log.h"
@@ -64,7 +64,7 @@ DECLARE_HEAP(event_timer_list, struct event, timeritem, event_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 event_master *master, struct event *thread);
+static void thread_free(struct event_loop *master, struct event *thread);
 
 #ifndef EXCLUDE_CPU_TIME
 #define EXCLUDE_CPU_TIME 0
@@ -89,23 +89,24 @@ unsigned long walltime_threshold = CONSUMED_TIME_CHECK;
 /* CLI start ---------------------------------------------------------------- */
 #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_EVENT_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_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",
@@ -137,12 +138,12 @@ static void vty_out_cpu_thread_history(struct vty *vty,
 
 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 event_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 event_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 *,
@@ -395,7 +397,7 @@ 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 event_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];
@@ -444,12 +446,11 @@ DEFUN_NOSH (show_thread_poll,
            "Show poll FD's and information\n")
 {
        struct listnode *node;
-       struct event_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,7 +482,7 @@ DEFUN (clear_thread_cpu,
        return CMD_SUCCESS;
 }
 
-static void show_thread_timers_helper(struct vty *vty, struct event_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];
@@ -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 event_master *m;
+       struct event_loop *m;
 
        frr_with_mutex (&masters_mtx) {
                for (ALL_LIST_ELEMENTS_RO(masters, node, m))
@@ -544,14 +545,14 @@ static void initializer(void)
        pthread_key_create(&thread_current, NULL);
 }
 
-struct event_master *thread_master_create(const char *name)
+struct event_loop *event_master_create(const char *name)
 {
-       struct event_master *rv;
+       struct event_loop *rv;
        struct rlimit limit;
 
        pthread_once(&init_once, &initializer);
 
-       rv = XCALLOC(MTYPE_EVENT_MASTER, sizeof(struct event_master));
+       rv = XCALLOC(MTYPE_EVENT_MASTER, sizeof(struct event_loop));
 
        /* Initialize master mutex */
        pthread_mutex_init(&rv->mtx, NULL);
@@ -577,6 +578,7 @@ struct event_master *thread_master_create(const char *name)
                            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(
@@ -623,7 +625,7 @@ struct event_master *thread_master_create(const char *name)
        return rv;
 }
 
-void thread_master_set_name(struct event_master *master, const char *name)
+void event_master_set_name(struct event_loop *master, const char *name)
 {
        frr_with_mutex (&master->mtx) {
                XFREE(MTYPE_EVENT_MASTER, master->name);
@@ -634,7 +636,7 @@ void thread_master_set_name(struct event_master *master, const char *name)
 #define EVENT_UNUSED_DEPTH 10
 
 /* Move thread to unuse list. */
-static void thread_add_unuse(struct event_master *m, struct event *thread)
+static void thread_add_unuse(struct event_loop *m, struct event *thread)
 {
        pthread_mutex_t mtxc = thread->mtx;
 
@@ -656,8 +658,7 @@ static void thread_add_unuse(struct event_master *m, struct event *thread)
 }
 
 /* Free all unused thread. */
-static void thread_list_free(struct event_master *m,
-                            struct event_list_head *list)
+static void thread_list_free(struct event_loop *m, struct event_list_head *list)
 {
        struct event *t;
 
@@ -665,8 +666,7 @@ static void thread_list_free(struct event_master *m,
                thread_free(m, t);
 }
 
-static void thread_array_free(struct event_master *m,
-                             struct event **thread_array)
+static void thread_array_free(struct event_loop *m, struct event **thread_array)
 {
        struct event *t;
        int index;
@@ -682,32 +682,32 @@ static void thread_array_free(struct event_master *m,
 }
 
 /*
- * 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 event_master *m)
+void event_master_free_unused(struct event_loop *m)
 {
        frr_with_mutex (&m->mtx) {
                struct event *t;
+
                while ((t = event_list_pop(&m->unuse)))
                        thread_free(m, t);
        }
 }
 
 /* Stop thread scheduler. */
-void thread_master_free(struct event_master *m)
+void event_master_free(struct event_loop *m)
 {
        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);
@@ -756,6 +756,7 @@ unsigned long event_timer_remain_second(struct event *thread)
 struct timeval event_timer_remain(struct event *thread)
 {
        struct timeval remain;
+
        frr_with_mutex (&thread->mtx) {
                monotime_until(&thread->u.sands, &remain);
        }
@@ -782,21 +783,21 @@ static int time_hhmmss(char *buf, int buf_size, long sec)
 
 char *event_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer)
 {
-       if (t_timer) {
+       if (t_timer)
                time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer));
-       } else {
+       else
                snprintf(buf, buf_size, "--:--:--");
-       }
+
        return buf;
 }
 
 /* Get new thread.  */
-static struct event *thread_get(struct event_master *m, uint8_t type,
+static struct event *thread_get(struct event_loop *m, uint8_t type,
                                void (*func)(struct event *), void *arg,
                                const struct xref_eventsched *xref)
 {
        struct event *thread = event_list_pop(&m->unuse);
-       struct cpu_thread_history tmp;
+       struct cpu_event_history tmp;
 
        if (!thread) {
                thread = XCALLOC(MTYPE_THREAD, sizeof(struct event));
@@ -838,7 +839,7 @@ static struct event *thread_get(struct event_master *m, uint8_t type,
        return thread;
 }
 
-static void thread_free(struct event_master *master, struct event *thread)
+static void thread_free(struct event_loop *master, struct event *thread)
 {
        /* Update statistics. */
        assert(master->alloc > 0);
@@ -849,7 +850,7 @@ static void thread_free(struct event_master *master, struct event *thread)
        XFREE(MTYPE_THREAD, thread);
 }
 
-static int fd_poll(struct event_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;
@@ -858,7 +859,7 @@ static int fd_poll(struct event_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
@@ -871,15 +872,17 @@ static int fd_poll(struct event_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();
@@ -948,7 +951,7 @@ done:
 
 /* Add new read thread. */
 void _event_add_read_write(const struct xref_eventsched *xref,
-                          struct event_master *m, void (*func)(struct event *),
+                          struct event_loop *m, void (*func)(struct event *),
                           void *arg, int fd, struct event **t_ptr)
 {
        int dir = xref->event_type;
@@ -969,8 +972,8 @@ void _event_add_read_write(const struct xref_eventsched *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 */
@@ -981,8 +984,10 @@ void _event_add_read_write(const struct xref_eventsched *xref,
                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;
@@ -1027,7 +1032,7 @@ void _event_add_read_write(const struct xref_eventsched *xref,
 }
 
 static void _event_add_timer_timeval(const struct xref_eventsched *xref,
-                                    struct event_master *m,
+                                    struct event_loop *m,
                                     void (*func)(struct event *), void *arg,
                                     struct timeval *time_relative,
                                     struct event **t_ptr)
@@ -1080,9 +1085,9 @@ static void _event_add_timer_timeval(const struct xref_eventsched *xref,
 
 
 /* Add timer event thread. */
-void _event_add_timer(const struct xref_eventsched *xref,
-                     struct event_master *m, void (*func)(struct event *),
-                     void *arg, long timer, struct event **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;
 
@@ -1096,7 +1101,7 @@ void _event_add_timer(const struct xref_eventsched *xref,
 
 /* Add timer event thread with "millisecond" resolution */
 void _event_add_timer_msec(const struct xref_eventsched *xref,
-                          struct event_master *m, void (*func)(struct event *),
+                          struct event_loop *m, void (*func)(struct event *),
                           void *arg, long timer, struct event **t_ptr)
 {
        struct timeval trel;
@@ -1111,16 +1116,16 @@ void _event_add_timer_msec(const struct xref_eventsched *xref,
 
 /* Add timer event thread with "timeval" resolution */
 void _event_add_timer_tv(const struct xref_eventsched *xref,
-                        struct event_master *m, void (*func)(struct event *),
+                        struct event_loop *m, void (*func)(struct event *),
                         void *arg, struct timeval *tv, struct event **t_ptr)
 {
        _event_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
 }
 
 /* Add simple event thread. */
-void _event_add_event(const struct xref_eventsched *xref,
-                     struct event_master *m, void (*func)(struct event *),
-                     void *arg, int val, struct event **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 event *thread = NULL;
 
@@ -1166,7 +1171,7 @@ void _event_add_event(const struct xref_eventsched *xref,
  *   - POLLIN
  *   - POLLOUT
  */
-static void event_cancel_rw(struct event_master *master, int fd, short state,
+static void event_cancel_rw(struct event_loop *master, int fd, short state,
                            int idx_hint)
 {
        bool found = false;
@@ -1211,8 +1216,10 @@ static void event_cancel_rw(struct event_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;
 
@@ -1224,7 +1231,7 @@ static void event_cancel_rw(struct event_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;
        }
 }
 
@@ -1232,7 +1239,7 @@ static void event_cancel_rw(struct event_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 event_master *master,
+static void cancel_arg_helper(struct event_loop *master,
                              const struct cancel_req *cr)
 {
        struct event *t;
@@ -1320,12 +1327,12 @@ static void cancel_arg_helper(struct event_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_event_cancel(struct event_master *master)
+static void do_event_cancel(struct event_loop *master)
 {
        struct event_list_head *list = NULL;
        struct event **thread_array = NULL;
@@ -1383,11 +1390,10 @@ static void do_event_cancel(struct event_master *master)
                        break;
                }
 
-               if (list) {
+               if (list)
                        event_list_del(list, thread);
-               } else if (thread_array) {
+               else if (thread_array)
                        thread_array[thread->u.fd] = NULL;
-               }
 
                if (thread->ref)
                        *thread->ref = NULL;
@@ -1407,7 +1413,7 @@ static void do_event_cancel(struct event_master *master)
 /*
  * Helper function used for multiple flavors of arg-based cancellation.
  */
-static void cancel_event_helper(struct event_master *m, void *arg, int flags)
+static void cancel_event_helper(struct event_loop *m, void *arg, int flags)
 {
        struct cancel_req *cr;
 
@@ -1433,10 +1439,10 @@ static void cancel_event_helper(struct event_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 event_cancel_event(struct event_master *master, void *arg)
+void event_cancel_event(struct event_loop *master, void *arg)
 {
        cancel_event_helper(master, arg, 0);
 }
@@ -1446,10 +1452,10 @@ void event_cancel_event(struct event_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 event_cancel_event_ready(struct event_master *m, void *arg)
+void event_cancel_event_ready(struct event_loop *m, void *arg)
 {
 
        /* Only cancel ready/event tasks */
@@ -1465,7 +1471,7 @@ void event_cancel_event_ready(struct event_master *m, void *arg)
  */
 void event_cancel(struct event **thread)
 {
-       struct event_master *master;
+       struct event_loop *master;
 
        if (thread == NULL || *thread == NULL)
                return;
@@ -1502,7 +1508,7 @@ void event_cancel(struct event **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
@@ -1514,7 +1520,7 @@ void event_cancel(struct event **thread)
  * @param thread pointer to thread to cancel
  * @param eventobj the event
  */
-void event_cancel_async(struct event_master *master, struct event **thread,
+void event_cancel_async(struct event_loop *master, struct event **thread,
                        void *eventobj)
 {
        assert(!(thread && eventobj) && (thread || eventobj));
@@ -1563,11 +1569,12 @@ static struct timeval *thread_timer_wait(struct event_timer_list_head *timers,
                return NULL;
 
        struct event *next_timer = event_timer_list_first(timers);
+
        monotime_until(&next_timer->u.sands, timer_val);
        return timer_val;
 }
 
-static struct event *thread_run(struct event_master *m, struct event *thread,
+static struct event *thread_run(struct event_loop *m, struct event *thread,
                                struct event *fetch)
 {
        *fetch = *thread;
@@ -1575,9 +1582,8 @@ static struct event *thread_run(struct event_master *m, struct event *thread,
        return fetch;
 }
 
-static int thread_process_io_helper(struct event_master *m,
-                                   struct event *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 event **thread_array;
 
@@ -1623,7 +1629,7 @@ static int thread_process_io_helper(struct event_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 event_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;
@@ -1657,9 +1663,10 @@ static void thread_process_io(struct event_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)
@@ -1681,7 +1688,7 @@ static void thread_process_io(struct event_master *m, unsigned int num)
 }
 
 /* Add all timers that have popped to the ready list. */
-static unsigned int thread_process_timers(struct event_master *m,
+static unsigned int thread_process_timers(struct event_loop *m,
                                          struct timeval *timenow)
 {
        struct timeval prev = *timenow;
@@ -1738,7 +1745,7 @@ static unsigned int thread_process(struct event_list_head *list)
 
 
 /* Fetch next ready thread. */
-struct event *event_fetch(struct event_master *m, struct event *fetch)
+struct event *event_fetch(struct event_loop *m, struct event *fetch)
 {
        struct event *thread = NULL;
        struct timeval now;
@@ -1898,19 +1905,22 @@ unsigned long event_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 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. */
+/*
+ * 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;
@@ -2055,7 +2065,7 @@ void event_call(struct event *thread)
 }
 
 /* Execute thread */
-void _event_execute(const struct xref_eventsched *xref, struct event_master *m,
+void _event_execute(const struct xref_eventsched *xref, struct event_loop *m,
                    void (*func)(struct event *), void *arg, int val)
 {
        struct event *thread;