Merge branch 'patch5' into 'master'

feat: rwlock

Closes #196

See merge request redox-os/relibc!594
This commit is contained in:
Jeremy Soller
2024-12-30 17:17:05 +00:00
11 changed files with 192 additions and 113 deletions
+1 -24
View File
@@ -7,29 +7,6 @@ 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::*;
pub use redox_rt::{proc::*, thread::*};
+5 -2
View File
@@ -34,6 +34,7 @@ use crate::{
unistd::{F_OK, R_OK, W_OK, X_OK},
},
io::{self, prelude::*, BufReader},
sync::rwlock::RwLock,
};
pub use redox_rt::proc::FdGuard;
@@ -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<pid_t> {
// 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<crate::pthread::OsTid> {
let _guard = clone::rdlock();
let _guard = CLONE_LOCK.read();
let res = clone::rlct_clone_impl(stack);
res.map(|mut fd| crate::pthread::OsTid {