cargo fmt and cargo fix
This commit is contained in:
+12
-5
@@ -8,8 +8,10 @@ pub use self::{
|
||||
semaphore::Semaphore,
|
||||
};
|
||||
|
||||
use crate::header::time::timespec;
|
||||
use crate::platform::{types::*, Pal, Sys};
|
||||
use crate::{
|
||||
header::time::timespec,
|
||||
platform::{types::*, Pal, Sys},
|
||||
};
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
ops::Deref,
|
||||
@@ -38,14 +40,19 @@ impl AtomicLock {
|
||||
}
|
||||
}
|
||||
pub fn notify_one(&self) {
|
||||
Sys::futex(unsafe { &mut *self.atomic.get() }.get_mut(), FUTEX_WAKE, 1, 0);
|
||||
Sys::futex(
|
||||
unsafe { &mut *self.atomic.get() }.get_mut(),
|
||||
FUTEX_WAKE,
|
||||
1,
|
||||
0,
|
||||
);
|
||||
}
|
||||
pub fn notify_all(&self) {
|
||||
Sys::futex(
|
||||
unsafe { &mut *self.atomic.get() }.get_mut(),
|
||||
FUTEX_WAKE,
|
||||
c_int::max_value(),
|
||||
0
|
||||
0,
|
||||
);
|
||||
}
|
||||
pub fn wait_if(&self, value: c_int, timeout_opt: Option<×pec>) {
|
||||
@@ -53,7 +60,7 @@ impl AtomicLock {
|
||||
unsafe { &mut *self.atomic.get() }.get_mut(),
|
||||
FUTEX_WAIT,
|
||||
value,
|
||||
timeout_opt.map_or(0, |timeout| timeout as *const timespec as usize)
|
||||
timeout_opt.map_or(0, |timeout| timeout as *const timespec as usize),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
//TODO: improve implementation
|
||||
|
||||
use super::AtomicLock;
|
||||
use crate::header::time::timespec;
|
||||
use crate::platform::{types::*, Pal, Sys};
|
||||
use core::hint::spin_loop;
|
||||
use crate::{
|
||||
header::time::timespec,
|
||||
platform::{types::*, Pal, Sys},
|
||||
};
|
||||
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
pub struct Semaphore {
|
||||
@@ -25,7 +27,10 @@ impl Semaphore {
|
||||
|
||||
pub fn wait(&self, timeout_opt: Option<×pec>) {
|
||||
if let Some(timeout) = timeout_opt {
|
||||
println!("semaphore wait tv_sec: {}, tv_nsec: {}", timeout.tv_sec, timeout.tv_nsec);
|
||||
println!(
|
||||
"semaphore wait tv_sec: {}, tv_nsec: {}",
|
||||
timeout.tv_sec, timeout.tv_nsec
|
||||
);
|
||||
}
|
||||
loop {
|
||||
while self.lock.load(Ordering::Acquire) < 1 {
|
||||
|
||||
Reference in New Issue
Block a user