RTOS Wrapper
API reference
Loading...
Searching...
No Matches
Mutex.h
Go to the documentation of this file.
1
22#ifndef MUTEX_H
23#define MUTEX_H
24
25#include <stdint.h>
26#include "OsUtility.h"
27
28class Mutex
29{
30public:
31
37 Mutex( const char* name, const char* nameExtension = 0 ) noexcept;
38
43 Mutex( const Mutex& copy ) = delete;
44
49 Mutex& operator = ( const Mutex& copy ) = delete;
50
55 ~Mutex();
56
60 bool IsInitialized() const noexcept
61 {
62 return initialized;
63 }
64
65
70 bool Lock( uint32_t maxMsecToWait) noexcept;
71
75 bool Unlock() noexcept;
76
77
78
79 uint32_t GetOwnershipCount() const noexcept
80 {
81 // FreeRTOS mutexes don't have ownership count like ThreadX
82 // Return 0 to indicate not supported or implement alternative logic
83 return 0;
84 }
85
86 const char* GetName() const noexcept
87 {
88 return mutexName;
89 }
90
91 bool EnsureInitialized() noexcept
92 {
93 if ( !initialized )
94 {
96 }
97 return initialized;
98 }
99
100
101 static constexpr uint32_t MaxNameLength = 39U; // Not including null terminator
102private:
103
107
108};
109
110
111#endif /* MUTEX_H */
C-facing helper functions for delays, cycle counters, and creation of RTOS handles (queues,...
bool os_mutex_create_ex(OS_Mutex &mutex, const char *mutexName, OS_Uint priority=OS_INHERIT, bool suppressVerbose=true) noexcept
Creates a mutex with the specified parameters.
Definition OsUtility.cpp:151
Definition Mutex.h:29
bool Lock(uint32_t maxMsecToWait) noexcept
This function locks the mutex.
Definition Mutex.cpp:56
bool IsInitialized() const noexcept
Accessor function to support testing.
Definition Mutex.h:60
const char * GetName() const noexcept
Definition Mutex.h:86
static constexpr uint32_t MaxNameLength
Definition Mutex.h:101
bool EnsureInitialized() noexcept
Definition Mutex.h:91
Mutex(const Mutex &copy)=delete
The Copy constructor is deleted to avoid copying instances.
OS_Mutex mutex
Definition Mutex.h:104
bool initialized
Definition Mutex.h:106
~Mutex()
The destructor deletes the mutex.
Definition Mutex.cpp:44
bool Unlock() noexcept
This function unlocks the mutex.
Definition Mutex.cpp:80
Mutex & operator=(const Mutex &copy)=delete
The assignment operator constructor is deleted to avoid copying instances.
uint32_t GetOwnershipCount() const noexcept
Definition Mutex.h:79
char mutexName[MaxNameLength+1]
Definition Mutex.h:105
osMutexId_t OS_Mutex
Definition os_cmsis.h:28