• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::{ptr::NonNull, task::Poll};
2 
3 struct TaskRef;
4 
5 struct Header {
6     vtable: &'static Vtable,
7 }
8 
9 struct Vtable {
10     poll: unsafe fn(TaskRef) -> Poll<()>,
11     deallocate: unsafe fn(NonNull<Header>),
12 }
13 
14 // in the "Header" type, which is a private type in maitake
15 impl Header {
new_stub() -> Self16     pub(crate) const fn new_stub() -> Self {
17         unsafe fn nop(_ptr: TaskRef) -> Poll<()> {
18             Poll::Pending
19         }
20 
21         unsafe fn nop_deallocate(ptr: NonNull<Header>) {
22             unreachable!("stub task ({ptr:p}) should never be deallocated!");
23         }
24 
25         Self { vtable: &Vtable { poll: nop, deallocate: nop_deallocate } }
26     }
27 }
28 
29 // This is a public type in `maitake`
30 #[repr(transparent)]
31 #[cfg_attr(loom, allow(dead_code))]
32 pub struct TaskStub {
33     hdr: Header,
34 }
35 
36 impl TaskStub {
37     /// Create a new unique stub [`Task`].
new() -> Self38     pub const fn new() -> Self {
39         Self { hdr: Header::new_stub() }
40     }
41 }
42