rmutex.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Theobroma Systems Design & Consulting GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef RMUTEX_H
22 #define RMUTEX_H
23 
24 #include <stdint.h>
25 #include <stdatomic.h>
26 
27 #include "mutex.h"
28 #include "kernel_types.h"
29 
30 #ifdef __cplusplus
31  extern "C" {
32 #endif
33 
37 typedef struct rmutex_t {
38  /* fields are managed by mutex functions, don't touch */
45 
50  uint16_t refcount;
51 
59  atomic_int_least16_t owner;
60 } rmutex_t;
61 
66 #define RMUTEX_INIT { MUTEX_INIT, 0, ATOMIC_VAR_INIT(KERNEL_PID_UNDEF) }
67 
74 static inline void rmutex_init(rmutex_t *rmutex)
75 {
76  rmutex_t empty_rmutex = RMUTEX_INIT;
77  *rmutex = empty_rmutex;
78 }
79 
89 int rmutex_trylock(rmutex_t *rmutex);
90 
97 void rmutex_lock(rmutex_t *rmutex);
98 
104 void rmutex_unlock(rmutex_t *rmutex);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* RMUTEX_H */
111 
Types used by the kernel.
int rmutex_trylock(rmutex_t *rmutex)
Tries to get a recursive mutex, non-blocking.
uint16_t refcount
Number of locks owned by the thread owner.
Definition: rmutex.h:50
struct rmutex_t rmutex_t
Mutex structure.
Mutex structure.
Definition: rmutex.h:37
mutex_t mutex
The mutex used for locking.
Definition: rmutex.h:44
void rmutex_unlock(rmutex_t *rmutex)
Unlocks the recursive mutex.
#define RMUTEX_INIT
Static initializer for rmutex_t.
Definition: rmutex.h:66
atomic_int_least16_t owner
Owner thread of the mutex.
Definition: rmutex.h:59
RIOT synchronization API.
void rmutex_lock(rmutex_t *rmutex)
Locks a recursive mutex, blocking.
Mutex structure.
Definition: mutex.h:36
static void rmutex_init(rmutex_t *rmutex)
Initializes a recursive mutex object.
Definition: rmutex.h:74