Fix codding style.

pull/7423/head
Przemyslaw Stekiel 2018-07-06 10:22:22 +02:00
parent ca8070a482
commit 3decd510dc
1 changed files with 18 additions and 9 deletions

View File

@ -41,7 +41,8 @@ Mutex::Mutex(const char *name)
void Mutex::constructor(const char *name) void Mutex::constructor(const char *name)
{ {
memset(&_obj_mem, 0, sizeof(_obj_mem)); memset(&_obj_mem, 0, sizeof(_obj_mem));
osMutexAttr_t attr = { 0 }; osMutexAttr_t attr =
{ 0 };
attr.name = name ? name : "aplication_unnamed_mutex"; attr.name = name ? name : "aplication_unnamed_mutex";
attr.cb_mem = &_obj_mem; attr.cb_mem = &_obj_mem;
attr.cb_size = sizeof(_obj_mem); attr.cb_size = sizeof(_obj_mem);
@ -50,7 +51,8 @@ void Mutex::constructor(const char *name)
MBED_ASSERT(_id); MBED_ASSERT(_id);
} }
void Mutex::lock(void) { void Mutex::lock(void)
{
osStatus status = osMutexAcquire(_id, osWaitForever); osStatus status = osMutexAcquire(_id, osWaitForever);
if (osOK == status) { if (osOK == status) {
_count++; _count++;
@ -59,7 +61,8 @@ void Mutex::lock(void) {
MBED_ASSERT(status == osOK); MBED_ASSERT(status == osOK);
} }
osStatus Mutex::lock(uint32_t millisec) { osStatus Mutex::lock(uint32_t millisec)
{
osStatus status = osMutexAcquire(_id, millisec); osStatus status = osMutexAcquire(_id, millisec);
if (osOK == status) { if (osOK == status) {
_count++; _count++;
@ -72,11 +75,13 @@ osStatus Mutex::lock(uint32_t millisec) {
return status; return status;
} }
bool Mutex::trylock() { bool Mutex::trylock()
{
return trylock_for(0); return trylock_for(0);
} }
bool Mutex::trylock_for(uint32_t millisec) { bool Mutex::trylock_for(uint32_t millisec)
{
osStatus status = osMutexAcquire(_id, millisec); osStatus status = osMutexAcquire(_id, millisec);
if (status == osOK) { if (status == osOK) {
return true; return true;
@ -89,7 +94,8 @@ bool Mutex::trylock_for(uint32_t millisec) {
return false; return false;
} }
bool Mutex::trylock_until(uint64_t millisec) { bool Mutex::trylock_until(uint64_t millisec)
{
uint64_t now = Kernel::get_ms_count(); uint64_t now = Kernel::get_ms_count();
if (now >= millisec) { if (now >= millisec) {
@ -102,16 +108,19 @@ bool Mutex::trylock_until(uint64_t millisec) {
} }
} }
osStatus Mutex::unlock() { osStatus Mutex::unlock()
{
_count--; _count--;
return osMutexRelease(_id); return osMutexRelease(_id);
} }
osThreadId Mutex::get_owner() { osThreadId Mutex::get_owner()
{
return osMutexGetOwner(_id); return osMutexGetOwner(_id);
} }
Mutex::~Mutex() { Mutex::~Mutex()
{
osMutexDelete(_id); osMutexDelete(_id);
} }