Fix Occlum building warnings
This commit is contained in:
parent
39f268891e
commit
e8f262808b
@ -109,7 +109,7 @@ impl ToErrno for std::alloc::AllocError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToErrno for std::alloc::LayoutErr {
|
impl ToErrno for std::alloc::LayoutError {
|
||||||
fn errno(&self) -> Errno {
|
fn errno(&self) -> Errno {
|
||||||
EINVAL
|
EINVAL
|
||||||
}
|
}
|
||||||
|
@ -154,8 +154,8 @@ impl Inner {
|
|||||||
pub fn wake(&self) {
|
pub fn wake(&self) {
|
||||||
if self
|
if self
|
||||||
.is_woken
|
.is_woken
|
||||||
.compare_and_swap(false, true, Ordering::SeqCst)
|
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
== false
|
.is_ok()
|
||||||
{
|
{
|
||||||
self.host_eventfd.write_u64(1);
|
self.host_eventfd.write_u64(1);
|
||||||
}
|
}
|
||||||
@ -167,8 +167,8 @@ impl Inner {
|
|||||||
.filter(|inner| {
|
.filter(|inner| {
|
||||||
inner
|
inner
|
||||||
.is_woken
|
.is_woken
|
||||||
.compare_and_swap(false, true, Ordering::SeqCst)
|
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
== false
|
.is_ok()
|
||||||
})
|
})
|
||||||
.map(|inner| inner.host_eventfd.host_fd())
|
.map(|inner| inner.host_eventfd.host_fd())
|
||||||
.collect::<Vec<FileDesc>>();
|
.collect::<Vec<FileDesc>>();
|
||||||
|
@ -71,8 +71,9 @@ impl AtomicIoEvents for Atomic<IoEvents> {
|
|||||||
let new_val = old_val & !*mask | *ready;
|
let new_val = old_val & !*mask | *ready;
|
||||||
let success_ordering = ordering;
|
let success_ordering = ordering;
|
||||||
let failure_ordering = Ordering::Relaxed;
|
let failure_ordering = Ordering::Relaxed;
|
||||||
if let Ok(_) =
|
if self
|
||||||
self.compare_exchange(old_val, new_val, success_ordering, failure_ordering)
|
.compare_exchange(old_val, new_val, success_ordering, failure_ordering)
|
||||||
|
.is_ok()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,4 @@ use fs::{AsEvent, AsINodeFile, AsTimer, CreationFlags, File, FileDesc, FileRef,
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::atomic::spin_loop_hint;
|
|
||||||
use time::timeval_t;
|
use time::timeval_t;
|
||||||
|
@ -563,10 +563,10 @@ process_syscall_table_with_callback!(impl_fmt_syscall);
|
|||||||
/// Generate the code that can dispatch any system call to its actual implementation function.
|
/// Generate the code that can dispatch any system call to its actual implementation function.
|
||||||
macro_rules! impl_dispatch_syscall {
|
macro_rules! impl_dispatch_syscall {
|
||||||
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($(,)?) -> ($($output:tt)*) ) => {
|
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($(,)?) -> ($($output:tt)*) ) => {
|
||||||
impl_dispatch_syscall!(@as_expr $fn($($output)*));
|
impl_dispatch_syscall!(@as_expr $fn($($output)*))
|
||||||
};
|
};
|
||||||
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($_arg_name:ident : $arg_type:ty, $($more_args:tt)*) -> ($($output:tt)*)) => {
|
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($_arg_name:ident : $arg_type:ty, $($more_args:tt)*) -> ($($output:tt)*)) => {
|
||||||
impl_dispatch_syscall!(@do_syscall $fn, $syscall, ($arg_i + 1), ($($more_args)*) -> ($($output)* ($syscall.args[$arg_i] as $arg_type),));
|
impl_dispatch_syscall!(@do_syscall $fn, $syscall, ($arg_i + 1), ($($more_args)*) -> ($($output)* ($syscall.args[$arg_i] as $arg_type),))
|
||||||
};
|
};
|
||||||
(@as_expr $e:expr) => { $e };
|
(@as_expr $e:expr) => { $e };
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::process::{futex_wait, futex_wake};
|
use crate::process::{futex_wait, futex_wake};
|
||||||
use std::sync::atomic::{spin_loop_hint, AtomicI32, Ordering};
|
use std::hint;
|
||||||
|
use std::sync::atomic::{AtomicI32, Ordering};
|
||||||
|
|
||||||
// The implementaion of RwLock
|
// The implementaion of RwLock
|
||||||
//
|
//
|
||||||
@ -97,7 +98,7 @@ impl RwLockInner {
|
|||||||
&& self.rw_lock.load(Ordering::SeqCst) != 0
|
&& self.rw_lock.load(Ordering::SeqCst) != 0
|
||||||
&& self.rw_waiters.load(Ordering::SeqCst) == 0
|
&& self.rw_waiters.load(Ordering::SeqCst) == 0
|
||||||
{
|
{
|
||||||
spin_loop_hint();
|
hint::spin_loop();
|
||||||
spins -= 1;
|
spins -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +122,8 @@ impl RwLockInner {
|
|||||||
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
|
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
let tmp = (val as u32 | 0x8000_0000) as i32;
|
let tmp = (val as u32 | 0x8000_0000) as i32;
|
||||||
self.rw_lock.compare_and_swap(val, tmp, Ordering::SeqCst);
|
self.rw_lock
|
||||||
|
.compare_exchange(val, tmp, Ordering::SeqCst, Ordering::SeqCst);
|
||||||
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
|
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
|
||||||
|
|
||||||
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
|
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
|
||||||
@ -148,8 +150,8 @@ impl RwLockInner {
|
|||||||
|
|
||||||
if self
|
if self
|
||||||
.rw_lock
|
.rw_lock
|
||||||
.compare_and_swap(val, val + 1, Ordering::SeqCst)
|
.compare_exchange(val, val + 1, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
== val
|
.is_ok()
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -168,7 +170,7 @@ impl RwLockInner {
|
|||||||
&& self.rw_lock.load(Ordering::SeqCst) != 0
|
&& self.rw_lock.load(Ordering::SeqCst) != 0
|
||||||
&& self.rw_waiters.load(Ordering::SeqCst) == 0
|
&& self.rw_waiters.load(Ordering::SeqCst) == 0
|
||||||
{
|
{
|
||||||
spin_loop_hint();
|
hint::spin_loop();
|
||||||
spins -= 1;
|
spins -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +188,8 @@ impl RwLockInner {
|
|||||||
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
|
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
let tmp = (val as u32 | 0x8000_0000) as i32;
|
let tmp = (val as u32 | 0x8000_0000) as i32;
|
||||||
self.rw_lock.compare_and_swap(val, tmp, Ordering::SeqCst);
|
self.rw_lock
|
||||||
|
.compare_exchange(val, tmp, Ordering::SeqCst, Ordering::SeqCst);
|
||||||
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
|
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
|
||||||
|
|
||||||
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
|
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
|
||||||
@ -201,12 +204,14 @@ impl RwLockInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_write(&self) -> Result<()> {
|
pub fn try_write(&self) -> Result<()> {
|
||||||
let val = self
|
if self
|
||||||
.rw_lock
|
.rw_lock
|
||||||
.compare_and_swap(0, 0x7FFF_FFFF, Ordering::SeqCst);
|
.compare_exchange(0, 0x7FFF_FFFF, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
match val {
|
.is_ok()
|
||||||
0 => Ok(()),
|
{
|
||||||
_ => return_errno!(EBUSY, "the lock is held for reading or writing"),
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(errno!(EBUSY, "the lock is held for reading or writing"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +232,11 @@ impl RwLockInner {
|
|||||||
_ => val - 1,
|
_ => val - 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.rw_lock.compare_and_swap(val, new, Ordering::SeqCst) == val {
|
if self
|
||||||
|
.rw_lock
|
||||||
|
.compare_exchange(val, new, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user