Skip to content

Commit

Permalink
Simplify lock_mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 10, 2023
1 parent faa1c11 commit f808505
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions esp-wifi/src/compat/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down

0 comments on commit f808505

Please sign in to comment.