Add name parameter for C++ mutex wrapper

pull/4294/head
Bartek Szatkowski 2017-05-23 11:28:07 +01:00 committed by Martin Kojtal
parent e66f9ee818
commit 0064df1ce6
2 changed files with 21 additions and 1 deletions

View File

@ -27,9 +27,21 @@
namespace rtos {
Mutex::Mutex() {
Mutex::Mutex()
{
constructor();
}
Mutex::Mutex(const char *name)
{
constructor(name);
}
void Mutex::constructor(const char *name)
{
memset(&_obj_mem, 0, sizeof(_obj_mem));
memset(&_attr, 0, sizeof(_attr));
_attr.name = name ? name : "aplication_unnamed_mutex";
_attr.cb_mem = &_obj_mem;
_attr.cb_size = sizeof(_obj_mem);
_attr.attr_bits = osMutexRecursive;

View File

@ -43,6 +43,12 @@ public:
/** Create and Initialize a Mutex object */
Mutex();
/** Create and Initialize a Mutex object
@param name name to be used for this mutex. It has to stay allocated for the lifetime of the thread.
*/
Mutex(const char *name);
/** Wait until a Mutex becomes available.
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
@return status code that indicates the execution status of the function.
@ -62,6 +68,8 @@ public:
~Mutex();
private:
void constructor(const char *name = NULL);
osMutexId_t _id;
osMutexAttr_t _attr;
mbed_rtos_storage_mutex_t _obj_mem;