Skip to content

Commit

Permalink
Merge pull request ARMmbed#12983 from kjbracey-arm/mutexcount
Browse files Browse the repository at this point in the history
Mutex::unlock - decrement _count inside lock
  • Loading branch information
0xc0170 authored Jun 4, 2020
2 parents ab43962 + b52a3b3 commit 0a365b3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rtos/source/Mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ bool Mutex::trylock_until(Kernel::Clock::time_point abs_time)

void Mutex::unlock()
{
// Count must be adjusted inside the lock. This would leave it incorrect
// on failure, but it only is used for an assert in ConditionVariable,
// and a mutex release failure means MBED_ERROR anyway.
_count--;

osStatus status = osMutexRelease(_id);
if (osOK == status) {
_count--;
}

if (status != osOK && !mbed_get_error_in_progress()) {
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_MUTEX_UNLOCK_FAILED), "Mutex unlock failed", status);
Expand Down

0 comments on commit 0a365b3

Please sign in to comment.