All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
23 #ifndef RMUTEX_H
24 #define RMUTEX_H
25 
26 #include <stdint.h>
27 
28 #include "mutex.h"
29 #include "sched.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 typedef struct rmutex_t {
39  /* fields are managed by mutex functions, don't touch */
46 
51  uint16_t refcount;
52 
62 
67 #define RMUTEX_INIT { MUTEX_INIT, 0, KERNEL_PID_UNDEF }
68 
75 static inline void rmutex_init(rmutex_t *rmutex)
76 {
77  rmutex_t empty_rmutex = RMUTEX_INIT;
78 
79  *rmutex = empty_rmutex;
80 }
81 
91 int rmutex_trylock(rmutex_t *rmutex);
92 
99 void rmutex_lock(rmutex_t *rmutex);
100 
106 void rmutex_unlock(rmutex_t *rmutex);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* RMUTEX_H */
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:139
struct rmutex_t rmutex_t
Mutex structure.
void rmutex_lock(rmutex_t *rmutex)
Locks a recursive mutex, blocking.
#define RMUTEX_INIT
Static initializer for rmutex_t.
Definition: rmutex.h:67
int rmutex_trylock(rmutex_t *rmutex)
Tries to get a recursive mutex, non-blocking.
static void rmutex_init(rmutex_t *rmutex)
Initializes a recursive mutex object.
Definition: rmutex.h:75
void rmutex_unlock(rmutex_t *rmutex)
Unlocks the recursive mutex.
Mutex for thread synchronization.
Scheduler API definition.
Mutex structure.
Definition: mutex.h:146
Mutex structure.
Definition: rmutex.h:38
uint16_t refcount
Number of locks owned by the thread owner.
Definition: rmutex.h:51
kernel_pid_t owner
Owner thread of the mutex.
Definition: rmutex.h:60
mutex_t mutex
The mutex used for locking.
Definition: rmutex.h:45