Skip to content

Commit 0a365b3

Browse files
authored
Merge pull request #12983 from kjbracey-arm/mutexcount
Mutex::unlock - decrement _count inside lock
2 parents ab43962 + b52a3b3 commit 0a365b3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rtos/source/Mutex.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ bool Mutex::trylock_until(Kernel::Clock::time_point abs_time)
123123

124124
void Mutex::unlock()
125125
{
126+
// Count must be adjusted inside the lock. This would leave it incorrect
127+
// on failure, but it only is used for an assert in ConditionVariable,
128+
// and a mutex release failure means MBED_ERROR anyway.
129+
_count--;
130+
126131
osStatus status = osMutexRelease(_id);
127-
if (osOK == status) {
128-
_count--;
129-
}
130132

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

0 commit comments

Comments
 (0)