BRISCITS  0.1
RISC "Real-Time" Scheduler
brisc_mutex.h
Go to the documentation of this file.
1 /******************************************************************************
2  ________ ________ ___ ________ ________ ___ _________ ________
3 |\ __ \|\ __ \|\ \|\ ____\|\ ____\|\ \|\___ ___\\ ____\
4 \ \ \|\ /\ \ \|\ \ \ \ \ \___|\ \ \___|\ \ \|___ \ \_\ \ \___|_
5  \ \ __ \ \ _ _\ \ \ \_____ \ \ \ \ \ \ \ \ \ \ \_____ \
6  \ \ \|\ \ \ \\ \\ \ \|____|\ \ \ \____\ \ \ \ \ \ \|____|\ \
7  \ \_______\ \__\\ _\\ \__\____\_\ \ \_______\ \__\ \ \__\ ____\_\ \
8  \|_______|\|__|\|__|\|__|\_________\|_______|\|__| \|__| |\_________\
9  \|_________| \|_________|
10 
11 MIT License
12 
13 Copyright (c) 2021 Mike Sharkey
14 
15 Permission is hereby granted, free of charge, to any person obtaining a copy
16 of this software and associated documentation files (the "Software"), to deal
17 in the Software without restriction, including without limitation the rights
18 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions:
21 
22 The above copyright notice and this permission notice shall be included in all
23 copies or substantial portions of the Software.
24 
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 SOFTWARE.
32 
33 ******************************************************************************/
34 #ifndef _BRISC_MUTEX_H_
35 #define _BRISC_MUTEX_H_
36 
37 #include <cpu.h>
38 #include <stdbool.h>
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
45 typedef uint32_t brisc_mutex_t;
46 
47 #define BRISC_MUTEX_DECL(n) brisc_mutex_t n = 0
48 
52 #define b_mutex_init(mutex) b_mutex_unlock((mutex))
53 
58 extern void b_mutex_lock( brisc_mutex_t* mutex );
59 
65 extern bool b_mutex_try_lock( brisc_mutex_t* mutex );
66 
71 extern void b_mutex_unlock( brisc_mutex_t* mutex );
72 
77 extern void b_mutex_release( brisc_mutex_t* mutex );
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif
bool b_mutex_try_lock(brisc_mutex_t *mutex)
Non-vlocking acquiring mutex lock.
Definition: brisc_mutex.c:43
uint32_t brisc_mutex_t
Definition: brisc_mutex.h:45
void b_mutex_lock(brisc_mutex_t *mutex)
Block while acquiring mutex lock.
Definition: brisc_mutex.c:38
void b_mutex_unlock(brisc_mutex_t *mutex)
Un-lock a mutex and yields CPU after unlock (generally prefered).
Definition: brisc_mutex.c:48
void b_mutex_release(brisc_mutex_t *mutex)
Un-lock a mutex with no-yield CPU after unlock.
Definition: brisc_mutex.c:54