cargo fmt and cargo fix

This commit is contained in:
Jeremy Soller
2022-11-11 13:26:46 -07:00
parent d1a86c850e
commit 16abc91341
25 changed files with 737 additions and 534 deletions
+12 -5
View File
@@ -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<&timespec>) {
@@ -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),
);
}
+9 -4
View File
@@ -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<&timespec>) {
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 {