Skip to content

Commit

Permalink
Merge pull request #1521 from m-mueller678/futex_wake
Browse files Browse the repository at this point in the history
avoid unnecessary dereference in futex_wake
  • Loading branch information
mkroening authored Dec 18, 2024
2 parents 12d4854 + 4ed673d commit be6c4dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/synch/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ pub(crate) fn futex_wait_and_set(
/// Wake `count` threads waiting on the futex at address. Returns the number of threads
/// woken up (saturates to `i32::MAX`). If `count` is `i32::MAX`, wake up all matching
/// waiting threads. If `count` is negative, returns -EINVAL.
pub(crate) fn futex_wake(address: &AtomicU32, count: i32) -> i32 {
/// `address` is used only for its address.
/// It is safe to pass a dangling pointer.
pub(crate) fn futex_wake(address: *const AtomicU32, count: i32) -> i32 {
if count < 0 {
return -EINVAL;
}

let mut parking_lot = PARKING_LOT.lock();
let mut queue = match parking_lot.entry(addr(address)) {
let mut queue = match parking_lot.entry(address.addr()) {
Entry::Occupied(entry) => entry,
Entry::Vacant(_) => return 0,
};
Expand Down
5 changes: 3 additions & 2 deletions src/syscalls/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ pub unsafe extern "C" fn sys_futex_wait(
/// Like `synch::futex_wake`, but does extra sanity checks.
///
/// Returns -EINVAL if `address` is null.
/// `address` is used only for its address.
/// It is safe to pass a dangling pointer.
#[hermit_macro::system]
#[no_mangle]
pub unsafe extern "C" fn sys_futex_wake(address: *mut u32, count: i32) -> i32 {
if address.is_null() {
return -EINVAL;
}

let address = unsafe { &*(address as *const AtomicU32) };
synch::futex_wake(address, count)
synch::futex_wake(address as *const AtomicU32, count)
}

0 comments on commit be6c4dd

Please sign in to comment.