From bc51d8e1d5cd3087444c1b086a036ecd8334fbec Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Tue, 31 Dec 2024 01:07:36 +1100 Subject: [PATCH] fix(pal/redox): use RwLock instead of InnerRwLock Signed-off-by: Anhad Singh --- src/platform/redox/clone.rs | 22 ---------------------- src/platform/redox/mod.rs | 7 +++++-- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/platform/redox/clone.rs b/src/platform/redox/clone.rs index 22d8e15053..c0f7414251 100644 --- a/src/platform/redox/clone.rs +++ b/src/platform/redox/clone.rs @@ -7,29 +7,7 @@ use syscall::{ SetSighandlerData, SIGCONT, }; -use crate::sync::rwlock::RwLock; - use redox_rt::{proc::FdGuard, signal::sighandler_function}; pub use redox_rt::proc::*; - -static CLONE_LOCK: RwLock = RwLock::new(crate::pthread::Pshared::Private); - -struct Guard; -impl Drop for Guard { - fn drop(&mut self) { - CLONE_LOCK.unlock() - } -} - -pub fn rdlock() -> impl Drop { - CLONE_LOCK.acquire_read_lock(None); - - Guard -} -pub fn wrlock() -> impl Drop { - CLONE_LOCK.acquire_write_lock(None); - - Guard -} pub use redox_rt::thread::*; diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 2c6c2e9b3f..e684191bf4 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -15,6 +15,7 @@ use crate::{ c_str::{CStr, CString}, error::{self, Errno, Result, ResultExt}, fs::File, + sync::rwlock::RwLock, header::{ dirent::dirent, errno::{ @@ -75,6 +76,8 @@ macro_rules! path_from_c_str { use self::{exec::Executable, path::canonicalize}; +static CLONE_LOCK: RwLock<()> = RwLock::new(()); + /// Redox syscall implementation of the platform abstraction layer. pub struct Sys; @@ -260,7 +263,7 @@ impl Pal for Sys { unsafe fn fork() -> Result { // TODO: Find way to avoid lock. - let _guard = clone::wrlock(); + let _guard = CLONE_LOCK.write(); Ok(clone::fork_impl()? as pid_t) } @@ -726,7 +729,7 @@ impl Pal for Sys { } unsafe fn rlct_clone(stack: *mut usize) -> Result { - let _guard = clone::rdlock(); + let _guard = CLONE_LOCK.read(); let res = clone::rlct_clone_impl(stack); res.map(|mut fd| crate::pthread::OsTid {