+#![deny(unsafe_op_in_unsafe_fn)]
+
use crate::ffi::c_void;
use crate::ptr;
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
}
pub unsafe fn init(&mut self) {
- let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0);
- let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0);
+ unsafe {
+ let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0);
+ let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0);
+ }
}
pub unsafe fn notify_one(&self) {
if self.counter.load(SeqCst) > 0 {
self.counter.fetch_sub(1, SeqCst);
- abi::sem_post(self.sem1);
- abi::sem_timedwait(self.sem2, 0);
+ unsafe {
+ abi::sem_post(self.sem1);
+ abi::sem_timedwait(self.sem2, 0);
+ }
}
}
pub unsafe fn notify_all(&self) {
let counter = self.counter.swap(0, SeqCst);
for _ in 0..counter {
- abi::sem_post(self.sem1);
+ unsafe {
+ abi::sem_post(self.sem1);
+ }
}
for _ in 0..counter {
- abi::sem_timedwait(self.sem2, 0);
+ unsafe {
+ abi::sem_timedwait(self.sem2, 0);
+ }
}
}
pub unsafe fn wait(&self, mutex: &Mutex) {
self.counter.fetch_add(1, SeqCst);
mutex.unlock();
- abi::sem_timedwait(self.sem1, 0);
- abi::sem_post(self.sem2);
+ unsafe {
+ abi::sem_timedwait(self.sem1, 0);
+ abi::sem_post(self.sem2);
+ }
mutex.lock();
}
}
pub unsafe fn destroy(&self) {
- let _ = abi::sem_destroy(self.sem1);
- let _ = abi::sem_destroy(self.sem2);
+ unsafe {
+ let _ = abi::sem_destroy(self.sem1);
+ let _ = abi::sem_destroy(self.sem2);
+ }
}
}