More explicit; CFG on atomic pointer

This commit is contained in:
Without Boats 2020-02-02 16:51:54 +01:00
parent ede03a4175
commit 3ae74cafe4
2 changed files with 4 additions and 3 deletions

View File

@ -161,6 +161,7 @@ pub mod str;
pub mod string; pub mod string;
#[cfg(target_has_atomic = "ptr")] #[cfg(target_has_atomic = "ptr")]
pub mod sync; pub mod sync;
#[cfg(target_has_atomic = "ptr")]
pub mod task; pub mod task;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -59,20 +59,20 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
// Increment the reference count of the arc to clone it. // Increment the reference count of the arc to clone it.
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker { unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
let waker: Arc<W> = Arc::from_raw(waker as *const W); let waker: Arc<W> = Arc::from_raw(waker as *const W);
mem::forget(waker.clone()); mem::forget(Arc::clone(&waker));
raw_waker(waker) raw_waker(waker)
} }
// Wake by value, moving the Arc into the Wake::wake function // Wake by value, moving the Arc into the Wake::wake function
unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) { unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: Arc<W> = Arc::from_raw(waker as *const W); let waker: Arc<W> = Arc::from_raw(waker as *const W);
Wake::wake(waker); <W as Wake>::wake(waker);
} }
// Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it // Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) { unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: ManuallyDrop<Arc<W>> = ManuallyDrop::new(Arc::from_raw(waker as *const W)); let waker: ManuallyDrop<Arc<W>> = ManuallyDrop::new(Arc::from_raw(waker as *const W));
Wake::wake_by_ref(&waker); <W as Wake>::wake_by_ref(&waker);
} }
// Decrement the reference count of the Arc on drop // Decrement the reference count of the Arc on drop