mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 18:13:49 +01:00
core: simplify mutex initializer
This commit is contained in:
parent
e5d6142823
commit
e03e20b7f6
@ -44,14 +44,22 @@ typedef struct mutex_t {
|
|||||||
} mutex_t;
|
} mutex_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes a mutex object.
|
* @brief Static initializer for mutex_t.
|
||||||
*
|
* @details This initializer is preferrable to mutex_init().
|
||||||
* @param[out] mutex pre-allocated mutex structure, must not be NULL.
|
|
||||||
*
|
|
||||||
* @return Always returns 1, always succeeds.
|
|
||||||
*/
|
*/
|
||||||
int mutex_init(mutex_t *mutex);
|
#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.
|
||||||
|
*/
|
||||||
|
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.
|
* @brief Tries to get a mutex, non-blocking.
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#ifndef __QUEUE_H
|
#ifndef __QUEUE_H
|
||||||
#define __QUEUE_H
|
#define __QUEUE_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
@ -41,6 +42,11 @@ typedef struct queue_node_t {
|
|||||||
uint32_t priority; /**< queue node priority */
|
uint32_t priority; /**< queue node priority */
|
||||||
} queue_node_t;
|
} 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
|
* @brief attach `new_obj` to the tail of the queue (identified
|
||||||
* `root`)
|
* `root`)
|
||||||
|
|||||||
@ -35,15 +35,6 @@
|
|||||||
|
|
||||||
static void mutex_wait(struct mutex_t *mutex);
|
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)
|
int mutex_trylock(struct mutex_t *mutex)
|
||||||
{
|
{
|
||||||
DEBUG("%s: trylocking to get mutex. val: %u\n", sched_active_thread->name, mutex->val);
|
DEBUG("%s: trylocking to get mutex. val: %u\n", sched_active_thread->name, mutex->val);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user