1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use core::ptr::null;
use core::task::{RawWaker, RawWakerVTable, Waker};
unsafe fn noop_clone(_data: *const ()) -> RawWaker {
noop_raw_waker()
}
unsafe fn noop(_data: *const ()) {}
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
const fn noop_raw_waker() -> RawWaker {
RawWaker::new(null(), &NOOP_WAKER_VTABLE)
}
#[inline]
pub fn noop_waker() -> Waker {
unsafe { Waker::from_raw(noop_raw_waker()) }
}
#[inline]
pub fn noop_waker_ref() -> &'static Waker {
struct SyncRawWaker(RawWaker);
unsafe impl Sync for SyncRawWaker {}
static NOOP_WAKER_INSTANCE: SyncRawWaker = SyncRawWaker(noop_raw_waker());
unsafe { &*(&NOOP_WAKER_INSTANCE.0 as *const RawWaker as *const Waker) }
}
#[cfg(test)]
mod tests {
#[test]
#[cfg(feature = "std")]
fn issue_2091_cross_thread_segfault() {
let waker = std::thread::spawn(super::noop_waker_ref).join().unwrap();
waker.wake_by_ref();
}
}