Lazuli
mutex.h
Go to the documentation of this file.
1 /*
2  * SPDX-License-Identifier: GPL-3.0-only
3  * This file is part of Lazuli.
4  */
5 
15 #ifndef LAZULI_MUTEX_H
16 #define LAZULI_MUTEX_H
17 
18 #include <stdint.h>
19 
20 #include <Lazuli/common.h>
21 #include <Lazuli/list.h>
22 
24 
28 typedef struct {
29  volatile uint8_t lock;
31 }Lz_Mutex;
32 
39 #define LZ_MUTEX_INIT { 0, LINKED_LIST_INIT }
40 
47 #define LZ_MUTEX_INIT_LOCKED { 1, LINKED_LIST_INIT }
48 
59 void
60 Lz_Mutex_Init(Lz_Mutex * const mutex);
61 
72 void
73 Lz_Mutex_InitLocked(Lz_Mutex * const mutex);
74 
84 void
85 Lz_Mutex_Lock(Lz_Mutex * const mutex);
86 
96 void
97 Lz_Mutex_Unlock(Lz_Mutex * const mutex);
98 
100 
101 #endif /* LAZULI_MUTEX_H */
#define _EXTERN_C_DECL_BEGIN
Open C++ header file declarations.
Definition: common.h:37
Lz_LinkedList waitingTasks
The list of tasks waiting for that mutex.
Definition: mutex.h:30
void Lz_Mutex_Init(Lz_Mutex *const mutex)
Initialize an already allocated Lz_Mutex.
Definition: mutex.c:61
volatile uint8_t lock
The mutex lock.
Definition: mutex.h:29
Doubly linked lists interface.
Represents the main container for doubly linked elements.
Definition: list.h:36
unsigned char uint8_t
Represents a unsigned integer type with width of exactly 8 bits.
Definition: stdint.h:89
void Lz_Mutex_InitLocked(Lz_Mutex *const mutex)
Initialize an already allocated Lz_Mutex.
Definition: mutex.c:69
void Lz_Mutex_Lock(Lz_Mutex *const mutex)
Lock the mutex and enter critical section.
Definition: mutex.c:77
Basic type definitions and useful macros.
Represents a mutex.
Definition: mutex.h:28
#define _EXTERN_C_DECL_END
Close C++ header file declarations.
Definition: common.h:42
void Lz_Mutex_Unlock(Lz_Mutex *const mutex)
Unlock the mutex and leave critical section.
Definition: mutex.c:91