From c3629a65e73153f50f0912291c6fd6d61b5ffbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 13 Oct 2025 09:32:51 +0200 Subject: [PATCH] feat(syscalls): remove condvar module --- src/syscalls/condvar.rs | 153 ---------------------------------------- src/syscalls/mod.rs | 2 - 2 files changed, 155 deletions(-) delete mode 100644 src/syscalls/condvar.rs diff --git a/src/syscalls/condvar.rs b/src/syscalls/condvar.rs deleted file mode 100644 index aefff063f8..0000000000 --- a/src/syscalls/condvar.rs +++ /dev/null @@ -1,153 +0,0 @@ -// The implementation is inspired by Andrew D. Birrell's paper -// "Implementing Condition Variables with Semaphores" - -use alloc::boxed::Box; -use core::sync::atomic::{AtomicIsize, Ordering}; -use core::{mem, ptr}; - -use crate::synch::semaphore::Semaphore; - -struct CondQueue { - counter: AtomicIsize, - sem1: Semaphore, - sem2: Semaphore, -} - -impl CondQueue { - pub fn new() -> Self { - CondQueue { - counter: AtomicIsize::new(0), - sem1: Semaphore::new(0), - sem2: Semaphore::new(0), - } - } -} - -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn sys_destroy_queue(ptr: usize) -> i32 { - unsafe { - let id = ptr::with_exposed_provenance_mut::(ptr); - if id.is_null() { - debug!("sys_wait: invalid address to condition variable"); - return -1; - } - - if *id != 0 { - let cond = Box::from_raw(ptr::with_exposed_provenance_mut::(*id)); - mem::drop(cond); - } - - 0 - } -} - -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn sys_notify(ptr: usize, count: i32) -> i32 { - unsafe { - let id = ptr::with_exposed_provenance::(ptr); - - if id.is_null() { - // invalid argument - debug!("sys_notify: invalid address to condition variable"); - return -1; - } - - if *id == 0 { - debug!("sys_notify: invalid reference to condition variable"); - return -1; - } - - let cond = &mut *(ptr::with_exposed_provenance_mut::(*id)); - - if count < 0 { - // Wake up all task that has been waiting for this condition variable - while cond.counter.load(Ordering::SeqCst) > 0 { - cond.counter.fetch_sub(1, Ordering::SeqCst); - cond.sem1.release(); - cond.sem2.acquire(None); - } - } else { - for _ in 0..count { - cond.counter.fetch_sub(1, Ordering::SeqCst); - cond.sem1.release(); - cond.sem2.acquire(None); - } - } - - 0 - } -} - -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn sys_init_queue(ptr: usize) -> i32 { - unsafe { - let id = ptr::with_exposed_provenance_mut::(ptr); - if id.is_null() { - debug!("sys_init_queue: invalid address to condition variable"); - return -1; - } - - if *id == 0 { - debug!("Create condition variable queue"); - let queue = Box::new(CondQueue::new()); - *id = Box::into_raw(queue) as usize; - } - - 0 - } -} - -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn sys_add_queue(ptr: usize, timeout_ns: i64) -> i32 { - unsafe { - let id = ptr::with_exposed_provenance_mut::(ptr); - if id.is_null() { - debug!("sys_add_queue: invalid address to condition variable"); - return -1; - } - - if *id == 0 { - debug!("Create condition variable queue"); - let queue = Box::new(CondQueue::new()); - *id = Box::into_raw(queue) as usize; - } - - if timeout_ns <= 0 { - let cond = &mut *(ptr::with_exposed_provenance_mut::(*id)); - cond.counter.fetch_add(1, Ordering::SeqCst); - - 0 - } else { - error!("Conditional variables with timeout is currently not supported"); - - -1 - } - } -} - -#[hermit_macro::system] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn sys_wait(ptr: usize) -> i32 { - unsafe { - let id = ptr::with_exposed_provenance_mut::(ptr); - if id.is_null() { - debug!("sys_wait: invalid address to condition variable"); - return -1; - } - - if *id == 0 { - error!("sys_wait: Unable to determine condition variable"); - return -1; - } - - let cond = &mut *(ptr::with_exposed_provenance_mut::(*id)); - cond.sem1.acquire(None); - cond.sem2.release(); - - 0 - } -} diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index fc3fa592ef..bebab528cd 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -10,7 +10,6 @@ use core::ptr::null; use dirent_display::Dirent64Display; use hermit_sync::Lazy; -pub use self::condvar::*; pub use self::entropy::*; pub use self::futex::*; pub use self::processor::*; @@ -33,7 +32,6 @@ use crate::fs::{self, FileAttr, SeekWhence}; use crate::mm::ALLOCATOR; use crate::syscalls::interfaces::SyscallInterface; -mod condvar; mod entropy; mod futex; pub(crate) mod interfaces;