Implement a proper mutex type for future usage

This commit is contained in:
jD91mZM2
2018-10-14 15:56:34 +02:00
parent 23fe526c55
commit 75c5c04bee
12 changed files with 185 additions and 20 deletions
+4
View File
@@ -166,6 +166,10 @@ impl Pal for Sys {
e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int
}
fn futex(addr: *mut c_int, op: c_int, val: c_int) -> c_int {
unsafe { syscall!(FUTEX, addr, op, val, 0, 0, 0) as c_int }
}
fn futimens(fd: c_int, times: *const timespec) -> c_int {
e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::<c_char>(), times, 0) }) as c_int
}
+2
View File
@@ -57,6 +57,8 @@ pub trait Pal {
fn ftruncate(fildes: c_int, length: off_t) -> c_int;
fn futex(addr: *mut c_int, op: c_int, val: c_int) -> c_int;
fn futimens(fd: c_int, times: *const timespec) -> c_int;
fn utimens(path: &CStr, times: *const timespec) -> c_int;
+7
View File
@@ -340,6 +340,13 @@ impl Pal for Sys {
e(syscall::ftruncate(fd as usize, len as usize)) as c_int
}
fn futex(addr: *mut c_int, op: c_int, val: c_int) -> c_int {
match unsafe { syscall::futex(addr as *mut i32, op as usize, val as i32, 0, ptr::null_mut()) } {
Ok(success) => success as c_int,
Err(err) => -(err.errno as c_int)
}
}
fn futimens(fd: c_int, times: *const timespec) -> c_int {
let times = [unsafe { redox_timespec::from(&*times) }, unsafe {
redox_timespec::from(&*times.offset(1))