Skip to content

Commit 0064df1

Browse files
bulislaw0xc0170
authored andcommitted
Add name parameter for C++ mutex wrapper
1 parent e66f9ee commit 0064df1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rtos/Mutex.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,21 @@
2727

2828
namespace rtos {
2929

30-
Mutex::Mutex() {
30+
Mutex::Mutex()
31+
{
32+
constructor();
33+
}
34+
35+
Mutex::Mutex(const char *name)
36+
{
37+
constructor(name);
38+
}
39+
40+
void Mutex::constructor(const char *name)
41+
{
3142
memset(&_obj_mem, 0, sizeof(_obj_mem));
3243
memset(&_attr, 0, sizeof(_attr));
44+
_attr.name = name ? name : "aplication_unnamed_mutex";
3345
_attr.cb_mem = &_obj_mem;
3446
_attr.cb_size = sizeof(_obj_mem);
3547
_attr.attr_bits = osMutexRecursive;

rtos/Mutex.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class Mutex {
4343
/** Create and Initialize a Mutex object */
4444
Mutex();
4545

46+
/** Create and Initialize a Mutex object
47+
48+
@param name name to be used for this mutex. It has to stay allocated for the lifetime of the thread.
49+
*/
50+
Mutex(const char *name);
51+
4652
/** Wait until a Mutex becomes available.
4753
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
4854
@return status code that indicates the execution status of the function.
@@ -62,6 +68,8 @@ class Mutex {
6268
~Mutex();
6369

6470
private:
71+
void constructor(const char *name = NULL);
72+
6573
osMutexId_t _id;
6674
osMutexAttr_t _attr;
6775
mbed_rtos_storage_mutex_t _obj_mem;

0 commit comments

Comments
 (0)