diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index f276ef0c..00c55430 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -356,31 +356,26 @@ pub fn lock_mutex(mutex: *mut crate::binary::c_types::c_void) -> i32 { trace!("mutex_lock ptr = {:?}", mutex); unsafe { + let ptr = mutex as *mut Mutex; + let current_task = current_task(); loop { - let ptr = mutex as *mut Mutex; - let current_task = current_task(); - - let result = critical_section::with(|_| { + let mutex_locked = critical_section::with(|_| { if (*ptr).count == 0 { (*ptr).locking_pid = current_task; (*ptr).count += 1; - Some(true) - } else if (*ptr).count != 0 && (*ptr).locking_pid == current_task { + true + } else if (*ptr).locking_pid == current_task { (*ptr).count += 1; - Some(true) - } else if (*ptr).count != 0 && (*ptr).locking_pid != current_task { - Some(false) + true } else { - None + false } }); memory_fence(); - if let Some(success) = result { - return if success { 1 } else { 0 }; + if mutex_locked { + return 1; } - - yield_task(); } } }