|
1 | | -use core::mem; |
2 | | -use core::task::{Waker, RawWaker, RawWakerVTable}; |
3 | 1 | use alloc::sync::Arc; |
4 | 2 |
|
5 | 3 | /// A way of waking up a specific task. |
@@ -35,52 +33,4 @@ pub trait ArcWake: Send + Sync { |
35 | 33 | /// This function is similar to `wake`, but must not consume the provided data |
36 | 34 | /// pointer. |
37 | 35 | fn wake_by_ref(arc_self: &Arc<Self>); |
38 | | - |
39 | | - /// Creates a `Waker` from an Arc<T>, if T implements `ArcWake`. |
40 | | - /// |
41 | | - /// If `wake()` is called on the returned `Waker`, |
42 | | - /// the `wake()` function that is defined inside this trait will get called. |
43 | | - fn into_waker(self: Arc<Self>) -> Waker where Self: Sized |
44 | | - { |
45 | | - let ptr = Arc::into_raw(self) as *const (); |
46 | | - |
47 | | - unsafe { |
48 | | - Waker::from_raw(RawWaker::new(ptr, waker_vtable!(Self))) |
49 | | - } |
50 | | - } |
51 | | -} |
52 | | - |
53 | | -// FIXME: panics on Arc::clone / refcount changes could wreak havoc on the |
54 | | -// code here. We should guard against this by aborting. |
55 | | - |
56 | | -unsafe fn increase_refcount<T: ArcWake>(data: *const ()) { |
57 | | - // Retain Arc by creating a copy |
58 | | - let arc: Arc<T> = Arc::from_raw(data as *const T); |
59 | | - let arc_clone = arc.clone(); |
60 | | - // Forget the Arcs again, so that the refcount isn't decrased |
61 | | - mem::forget(arc); |
62 | | - mem::forget(arc_clone); |
63 | | -} |
64 | | - |
65 | | -// used by `waker_ref` |
66 | | -pub(super) unsafe fn clone_arc_raw<T: ArcWake>(data: *const ()) -> RawWaker { |
67 | | - increase_refcount::<T>(data); |
68 | | - RawWaker::new(data, waker_vtable!(T)) |
69 | | -} |
70 | | - |
71 | | -unsafe fn drop_arc_raw<T: ArcWake>(data: *const ()) { |
72 | | - drop(Arc::<T>::from_raw(data as *const T)) |
73 | | -} |
74 | | - |
75 | | -// used by `waker_ref` |
76 | | -pub(super) unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) { |
77 | | - let arc: Arc<T> = Arc::from_raw(data as *const T); |
78 | | - ArcWake::wake(arc); |
79 | | -} |
80 | | - |
81 | | -// used by `waker_ref` |
82 | | -pub(super) unsafe fn wake_by_ref_arc_raw<T: ArcWake>(data: *const ()) { |
83 | | - let arc: Arc<T> = Arc::from_raw(data as *const T); |
84 | | - ArcWake::wake_by_ref(&arc); |
85 | | - mem::forget(arc); |
86 | 36 | } |
0 commit comments