From 2c03dfca13af6c30d5066fc239c061bff75064e2 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 4 Aug 2020 12:58:39 +0200 Subject: [PATCH] sys/event: Made trivial functions static inline When the expected ROM overhead of a function is bigger than the actual function, it is better to provide the function as static inline function in the header. --- sys/event/event.c | 28 ---------------------------- sys/include/event.h | 32 +++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/sys/event/event.c b/sys/event/event.c index 325c9e7ccf..2337b76859 100644 --- a/sys/event/event.c +++ b/sys/event/event.c @@ -33,25 +33,6 @@ #include "xtimer.h" #endif -void event_queue_init_detached(event_queue_t *queue) -{ - assert(queue); - memset(queue, '\0', sizeof(*queue)); -} - -void event_queue_init(event_queue_t *queue) -{ - assert(queue); - memset(queue, '\0', sizeof(*queue)); - queue->waiter = (thread_t *)sched_active_thread; -} - -void event_queue_claim(event_queue_t *queue) -{ - assert(queue && (queue->waiter == NULL)); - queue->waiter = (thread_t *)sched_active_thread; -} - void event_post(event_queue_t *queue, event_t *event) { assert(queue && event); @@ -152,12 +133,3 @@ event_t *event_wait_timeout64(event_queue_t *queue, uint64_t timeout) return _wait_timeout(queue, &timer); } #endif - -void event_loop_multi(event_queue_t *queues, size_t n_queues) -{ - event_t *event; - - while ((event = event_wait_multi(queues, n_queues))) { - event->handler(event); - } -} diff --git a/sys/include/event.h b/sys/include/event.h index 09ef7ea291..25d87ac846 100644 --- a/sys/include/event.h +++ b/sys/include/event.h @@ -97,10 +97,12 @@ #define EVENT_H #include +#include +#include "assert.h" +#include "clist.h" #include "irq.h" #include "thread_flags.h" -#include "clist.h" #ifdef __cplusplus extern "C" { @@ -156,14 +158,23 @@ typedef struct { * * @param[out] queue event queue object to initialize */ -void event_queue_init(event_queue_t *queue); +static inline void event_queue_init(event_queue_t *queue) +{ + assert(queue); + memset(queue, '\0', sizeof(*queue)); + queue->waiter = (thread_t *)sched_active_thread; +} /** * @brief Initialize an event queue not binding it to a thread * * @param[out] queue event queue object to initialize */ -void event_queue_init_detached(event_queue_t *queue); +static inline void event_queue_init_detached(event_queue_t *queue) +{ + assert(queue); + memset(queue, '\0', sizeof(*queue)); +} /** * @brief Bind an event queue to the calling thread @@ -175,7 +186,11 @@ void event_queue_init_detached(event_queue_t *queue); * * @param[out] queue event queue object to bind to a thread */ -void event_queue_claim(event_queue_t *queue); +static inline void event_queue_claim(event_queue_t *queue) +{ + assert(queue && (queue->waiter == NULL)); + queue->waiter = (thread_t *)sched_active_thread; +} /** * @brief Queue an event @@ -308,7 +323,14 @@ event_t *event_wait_timeout64(event_queue_t *queue, uint64_t timeout); * @param[in] queues Event queues to process * @param[in] n_queues Number of queues passed with @p queues */ -void event_loop_multi(event_queue_t *queues, size_t n_queues); +static inline void event_loop_multi(event_queue_t *queues, size_t n_queues) +{ + event_t *event; + + while ((event = event_wait_multi(queues, n_queues))) { + event->handler(event); + } +} /** * @brief Simple event loop