The friendly Operating System for the Internet of Things
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 <stdatomic.h>
25 
26 #include "mutex.h"
27 #include "kernel_types.h"
28 
29 #ifdef __cplusplus
30  extern "C" {
31 #endif
32 
36 typedef struct rmutex_t {
37  /* fields are managed by mutex functions, don't touch */
44 
49  uint16_t refcount;
50 
58  atomic_int_least16_t owner;
59 } rmutex_t;
60 
65 #define RMUTEX_INIT { MUTEX_INIT, 0, ATOMIC_VAR_INIT(KERNEL_PID_UNDEF) }
66 
73 static inline void rmutex_init(rmutex_t *rmutex)
74 {
75  rmutex_t empty_rmutex = RMUTEX_INIT;
76  *rmutex = empty_rmutex;
77 }
78 
88 int rmutex_trylock(rmutex_t *rmutex);
89 
96 void rmutex_lock(rmutex_t *rmutex);
97 
103 void rmutex_unlock(rmutex_t *rmutex);
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* RMUTEX_H_ */
110 
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:49
struct rmutex_t rmutex_t
Mutex structure.
Mutex structure.
Definition: rmutex.h:36
mutex_t mutex
The mutex used for locking.
Definition: rmutex.h:43
void rmutex_unlock(rmutex_t *rmutex)
Unlocks the recursive mutex.
#define RMUTEX_INIT
Static initializer for rmutex_t.
Definition: rmutex.h:65
atomic_int_least16_t owner
Owner thread of the mutex.
Definition: rmutex.h:58
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:73