Xyris  0.5
Mutex Class Reference

#include <Mutex.hpp>

+ Collaboration diagram for Mutex:

Public Member Functions

 Mutex (const char *name=nullptr)
 
bool lock ()
 
bool tryLock ()
 
bool unlock ()
 

Private Attributes

bool m_isLocked
 
struct task_sync m_taskSync
 

Detailed Description

Definition at line 16 of file Mutex.hpp.

Constructor & Destructor Documentation

◆ Mutex()

Mutex::Mutex ( const char *  name = nullptr)

Construct a new Mutex object.

Parameters
nameMutex name (for debugging / printing)

Definition at line 13 of file Mutex.cpp.

14  : m_isLocked(false)
15 {
17  tasks_sync_init(&m_taskSync);
18 };

Member Function Documentation

◆ lock()

bool Mutex::lock ( )

Aquire the mutex.

Returns
int Returns true on success.

Definition at line 20 of file Mutex.cpp.

21 {
22  while (__atomic_test_and_set(&m_isLocked, __ATOMIC_RELEASE)) {
24  }
25 
26  return true;
27 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tryLock()

bool Mutex::tryLock ( )

Try to aquire the mutex and return immediately if already locked.

Returns
int Returns true on success.

Definition at line 29 of file Mutex.cpp.

30 {
31  if (__atomic_test_and_set(&m_isLocked, __ATOMIC_RELEASE)) {
32  return false;
33  }
34 
35  return true;
36 }

◆ unlock()

bool Mutex::unlock ( )

Release the mutex.

Returns
int Returns true on success.

Definition at line 38 of file Mutex.cpp.

39 {
40  __atomic_clear(&m_isLocked, __ATOMIC_RELEASE);
42 
43  return true;
44 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ m_isLocked

bool Mutex::m_isLocked
private

Definition at line 48 of file Mutex.hpp.

◆ m_taskSync

struct task_sync Mutex::m_taskSync
private

Definition at line 49 of file Mutex.hpp.


The documentation for this class was generated from the following files:
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
tasks_sync_unblock
void tasks_sync_unblock(struct task_sync *ts)
Definition: tasks.cpp:575
TASK_ONLY
#define TASK_ONLY
Definition: tasks.hpp:46
task::name
const char * name
Definition: tasks.hpp:40
tasks_sync_block
void tasks_sync_block(struct task_sync *ts)
Definition: tasks.cpp:560