Xyris  0.5
Mutex.cpp
Go to the documentation of this file.
1 /**
2  * @file Mutex.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief
5  * @version 0.3
6  * @date 2020-08-30
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2020
9  *
10  */
11 #include <Locking/Mutex.hpp>
12 
13 Mutex::Mutex(const char* name)
14  : m_isLocked(false)
15 {
16  m_taskSync.dbg_name = name;
17  tasks_sync_init(&m_taskSync);
18 };
19 
21 {
22  while (__atomic_test_and_set(&m_isLocked, __ATOMIC_RELEASE)) {
24  }
25 
26  return true;
27 }
28 
30 {
31  if (__atomic_test_and_set(&m_isLocked, __ATOMIC_RELEASE)) {
32  return false;
33  }
34 
35  return true;
36 }
37 
39 {
40  __atomic_clear(&m_isLocked, __ATOMIC_RELEASE);
42 
43  return true;
44 }
Mutex::unlock
bool unlock()
Release the mutex.
Definition: Mutex.cpp:38
Mutex::m_isLocked
bool m_isLocked
Definition: Mutex.hpp:48
task_sync::dbg_name
const char * dbg_name
Definition: tasks.hpp:58
Mutex::m_taskSync
struct task_sync m_taskSync
Definition: Mutex.hpp:49
Mutex::lock
bool lock()
Aquire the mutex.
Definition: Mutex.cpp:20
tasks_sync_unblock
void tasks_sync_unblock(struct task_sync *ts)
Definition: tasks.cpp:575
TASK_ONLY
#define TASK_ONLY
Definition: tasks.hpp:46
Mutex::Mutex
Mutex(const char *name=nullptr)
Construct a new Mutex object.
Definition: Mutex.cpp:13
Mutex::tryLock
bool tryLock()
Try to aquire the mutex and return immediately if already locked.
Definition: Mutex.cpp:29
tasks_sync_block
void tasks_sync_block(struct task_sync *ts)
Definition: tasks.cpp:560
Mutex.hpp