diff --git a/core/include/mutex.h b/core/include/mutex.h index 0cdff269d3a0317d80d805fb9ea8399efa2f72e7..ba138a8415bc9ddc1566bc094780a8854aeb6bc3 100644 --- a/core/include/mutex.h +++ b/core/include/mutex.h @@ -43,15 +43,23 @@ typedef struct mutex_t { queue_node_t queue; } mutex_t; +/** + * @brief Static initializer for mutex_t. + * @details This initializer is preferrable to mutex_init(). + */ +#define MUTEX_INIT { 0, QUEUE_NODE_INIT } + /** * @brief Initializes a mutex object. - * + * @details For intialization of variables use MUTEX_INIT instead. + * Only use the function call for dynamically allocated mutexes. * @param[out] mutex pre-allocated mutex structure, must not be NULL. - * - * @return Always returns 1, always succeeds. */ -int mutex_init(mutex_t *mutex); - +static inline void mutex_init(mutex_t *mutex) +{ + mutex_t empty_mutex = MUTEX_INIT; + *mutex = empty_mutex; +} /** * @brief Tries to get a mutex, non-blocking. diff --git a/core/include/queue.h b/core/include/queue.h index a0e6aadfcc52f8852019a60b0bc83f68a26e7f2d..8d9416f056bbd7c9da0b443bc59a2a0ab7fdbc83 100644 --- a/core/include/queue.h +++ b/core/include/queue.h @@ -20,6 +20,7 @@ #ifndef __QUEUE_H #define __QUEUE_H +#include <stddef.h> #include <stdint.h> #include <inttypes.h> @@ -41,6 +42,11 @@ typedef struct queue_node_t { uint32_t priority; /**< queue node priority */ } queue_node_t; +/** + * @brief Static initializer for queue_node_t. + */ +#define QUEUE_NODE_INIT { NULL, 0, 0 } + /** * @brief attach `new_obj` to the tail of the queue (identified * `root`) diff --git a/core/mutex.c b/core/mutex.c index 180b3416bf097940e6740d181ecba31dc4110c23..41fdcee8185ef85a273efae403ab115054dd48d8 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -35,15 +35,6 @@ static void mutex_wait(struct mutex_t *mutex); -void mutex_init(struct mutex_t *mutex) -{ - mutex->val = 0; - - mutex->queue.priority = 0; - mutex->queue.data = 0; - mutex->queue.next = NULL; -} - int mutex_trylock(struct mutex_t *mutex) { DEBUG("%s: trylocking to get mutex. val: %u\n", sched_active_thread->name, mutex->val);