/rust/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/util/wake.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::loom::sync::Arc; |
2 | | |
3 | | use std::marker::PhantomData; |
4 | | use std::mem::ManuallyDrop; |
5 | | use std::ops::Deref; |
6 | | use std::task::{RawWaker, RawWakerVTable, Waker}; |
7 | | |
8 | | /// Simplified waking interface based on Arcs. |
9 | | pub(crate) trait Wake: Send + Sync + Sized + 'static { |
10 | | /// Wake by value. |
11 | | fn wake(arc_self: Arc<Self>); |
12 | | |
13 | | /// Wake by reference. |
14 | | fn wake_by_ref(arc_self: &Arc<Self>); |
15 | | } |
16 | | |
17 | | /// A `Waker` that is only valid for a given lifetime. |
18 | | #[derive(Debug)] |
19 | | pub(crate) struct WakerRef<'a> { |
20 | | waker: ManuallyDrop<Waker>, |
21 | | _p: PhantomData<&'a ()>, |
22 | | } |
23 | | |
24 | | impl Deref for WakerRef<'_> { |
25 | | type Target = Waker; |
26 | | |
27 | 0 | fn deref(&self) -> &Waker { |
28 | 0 | &self.waker |
29 | 0 | } |
30 | | } |
31 | | |
32 | | /// Creates a reference to a `Waker` from a reference to `Arc<impl Wake>`. |
33 | 0 | pub(crate) fn waker_ref<W: Wake>(wake: &Arc<W>) -> WakerRef<'_> { |
34 | 0 | let ptr = Arc::as_ptr(wake).cast::<()>(); |
35 | 0 |
|
36 | 0 | let waker = unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) }; |
37 | 0 |
|
38 | 0 | WakerRef { |
39 | 0 | waker: ManuallyDrop::new(waker), |
40 | 0 | _p: PhantomData, |
41 | 0 | } |
42 | 0 | } Unexecuted instantiation: tokio::util::wake::waker_ref::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::waker_ref::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::waker_ref::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::waker_ref::<tokio::runtime::scheduler::current_thread::Handle> |
43 | | |
44 | 0 | fn waker_vtable<W: Wake>() -> &'static RawWakerVTable { |
45 | 0 | &RawWakerVTable::new( |
46 | 0 | clone_arc_raw::<W>, |
47 | 0 | wake_arc_raw::<W>, |
48 | 0 | wake_by_ref_arc_raw::<W>, |
49 | 0 | drop_arc_raw::<W>, |
50 | 0 | ) |
51 | 0 | } Unexecuted instantiation: tokio::util::wake::waker_vtable::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::waker_vtable::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::waker_vtable::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::waker_vtable::<tokio::runtime::scheduler::current_thread::Handle> |
52 | | |
53 | 0 | unsafe fn clone_arc_raw<T: Wake>(data: *const ()) -> RawWaker { |
54 | 0 | Arc::<T>::increment_strong_count(data as *const T); |
55 | 0 | RawWaker::new(data, waker_vtable::<T>()) |
56 | 0 | } Unexecuted instantiation: tokio::util::wake::clone_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::clone_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::clone_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::clone_arc_raw::<tokio::runtime::scheduler::current_thread::Handle> |
57 | | |
58 | 0 | unsafe fn wake_arc_raw<T: Wake>(data: *const ()) { |
59 | 0 | let arc: Arc<T> = Arc::from_raw(data as *const T); |
60 | 0 | Wake::wake(arc); |
61 | 0 | } Unexecuted instantiation: tokio::util::wake::wake_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::wake_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::wake_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::wake_arc_raw::<tokio::runtime::scheduler::current_thread::Handle> |
62 | | |
63 | | // used by `waker_ref` |
64 | 0 | unsafe fn wake_by_ref_arc_raw<T: Wake>(data: *const ()) { |
65 | 0 | // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop |
66 | 0 | let arc = ManuallyDrop::new(Arc::<T>::from_raw(data.cast())); |
67 | 0 | Wake::wake_by_ref(&arc); |
68 | 0 | } Unexecuted instantiation: tokio::util::wake::wake_by_ref_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::wake_by_ref_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::wake_by_ref_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::wake_by_ref_arc_raw::<tokio::runtime::scheduler::current_thread::Handle> |
69 | | |
70 | 0 | unsafe fn drop_arc_raw<T: Wake>(data: *const ()) { |
71 | 0 | drop(Arc::<T>::from_raw(data.cast())); |
72 | 0 | } Unexecuted instantiation: tokio::util::wake::drop_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), anyhow::Error>>>> Unexecuted instantiation: tokio::util::wake::drop_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<()>>> Unexecuted instantiation: tokio::util::wake::drop_arc_raw::<tokio::util::idle_notified_set::ListEntry<tokio::runtime::task::join::JoinHandle<core::result::Result<(), hickory_proto::error::ProtoError>>>> Unexecuted instantiation: tokio::util::wake::drop_arc_raw::<tokio::runtime::scheduler::current_thread::Handle> |