mirror of https://github.com/ARMmbed/mbed-os.git
Mutex::unlock - decrement _count inside lock
`Mutex::unlock` was decrementing the `_count` member after releasing the mutex, which meant it was unprotected, exposing a race that could corrupt the count. This could lead to an assert in `ConditionVariable::wait`, which checks that the mutex count is one.pull/12983/head
parent
b53dc6695b
commit
b52a3b3120
|
@ -123,10 +123,12 @@ bool Mutex::trylock_until(Kernel::Clock::time_point abs_time)
|
||||||
|
|
||||||
void Mutex::unlock()
|
void Mutex::unlock()
|
||||||
{
|
{
|
||||||
osStatus status = osMutexRelease(_id);
|
// Count must be adjusted inside the lock. This would leave it incorrect
|
||||||
if (osOK == status) {
|
// on failure, but it only is used for an assert in ConditionVariable,
|
||||||
|
// and a mutex release failure means MBED_ERROR anyway.
|
||||||
_count--;
|
_count--;
|
||||||
}
|
|
||||||
|
osStatus status = osMutexRelease(_id);
|
||||||
|
|
||||||
if (status != osOK && !mbed_get_error_in_progress()) {
|
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);
|
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_MUTEX_UNLOCK_FAILED), "Mutex unlock failed", status);
|
||||||
|
|
Loading…
Reference in New Issue