More progress :)
parent: tbd commit: 92c3f32
1 | use BoxFuture; |
2 | use FutureExt; |
3 | use |
4 | , | UnsafeCell
5 | , | Future
6 | , | PhantomData
7 | , |
8 | ; |
9 | |
10 | use crate::; |
11 | |
12 | /// Future type for futures within the Runtime. |
13 | /// |
14 | /// Allows for plugins to spawn futures on the runtime. |
15 | |
16 | |
17 | |
18 | /// The plugin's poll function, provided with the poll state for the future. |
19 | poll_fn: unsafe extern "C" fn , |
20 | /// The function to wake the future, should only be called when the future is ready to be polled. |
21 | wake_fn: , |
22 | |
23 | /// The inner value that the owning plugin can use to poll the future |
24 | poll_state: PluginState, |
25 | /// The waker that the plugin uses for notification of the future's completion |
26 | waker_state: , |
27 | |
28 | /// Whether its safe for the plugin to poll this future, panic if we think |
29 | /// we're supposed to poll and this is not set to `true`. |
30 | can_poll: bool, |
31 | |
32 | _output_marker: , |
33 | |
34 | |
35 | unsafe |
36 | unsafe |
37 | |
38 | |
39 | |
40 | callback: PluginState, |
41 | waker_func: unsafe extern "C" fn , |
42 | |
43 | |
44 | |
45 | |
46 | Ready, |
47 | Pending, |
48 | |
49 | |
50 | |
51 | waker: Waker, |
52 | |
53 | |
54 | |
55 | pub unsafe |
56 | todo! |
57 | |
58 | |
59 | |
60 | unsafe extern "C" |
61 | |
62 | |
63 | inner: , |
64 | runtime_future: , |
65 | |
66 | |
67 | unsafe |
68 | unsafe |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | todo! |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | &self, |
81 | future: F, |
82 | ; |
83 | |
84 | |
85 | |
86 | |
87 | &self, |
88 | future: F, |
89 | |
90 | let type_eraser = async move |
91 | let result = future.await; |
92 | |
93 | untyped | from_box .
94 | ; |
95 | |
96 | let runtime_future = RuntimeFuture |
97 | poll_fn: poll_local, |
98 | wake_fn: None, |
99 | poll_state: from, |
100 | waker_state: None, |
101 | can_poll: true, |
102 | _output_marker: PhantomData, |
103 | ; |
104 | |
105 | runtime_future |
106 | |
107 | |
108 | |
109 | unsafe extern "C" |
110 | _future: *const , |
111 | mut future_state: PluginState, |
112 | |
113 | let mut future: = future_state.transmute_owned; |
114 | let runtime_future = future.as_ref; |
115 | |
116 | let raw_waker = new |
117 | Box into_raw as *const , |
118 | &RUNTIME_FUTURE_WAKER_VTABLE, |
119 | ; |
120 | |
121 | let waker = unsafe ; |
122 | |
123 | // SAFETY: Pretty sure this has to be static lol |
124 | let poll_result = future.poll_unpin; |
125 | |
126 | |
127 | |
128 | // This is meant to communicate with the compiler the lifecycle of the object |
129 | future_state = from_raw; |
130 | |
131 | |
132 | match poll_result |
133 | => Ready, | Ready
134 | => Pending, | Pending
135 | |
136 | |
137 | |
138 | pub static RUNTIME_FUTURE_WAKER_VTABLE: RawWakerVTable = new |
139 | , | waker_clone
140 | , | waker_wake
141 | , | waker_wake_by_ref
142 | , | waker_drop
143 | ; |
144 | |
145 | |
146 | use RawWaker; |
147 | |
148 | pub unsafe |
149 | todo! |
150 | |
151 | |
152 | pub unsafe |
153 | todo! |
154 | |
155 | |
156 | pub unsafe |
157 | todo! |
158 | |
159 | |
160 | pub unsafe |
161 | // no-op |
162 | |
163 | |
164 | |
165 | /// Allows for a remote future to be polled on the target. |
166 | /// |
167 | /// The target can be the host or a plugin, but the future should only be polled by one |
168 | /// source. |
169 | |
170 | type Output = Output; |
171 | |
172 | |
173 | mut self: , |
174 | cx: &mut , |
175 | |
176 | let waker_state = WakerState |
177 | waker: cx.waker .clone, |
178 | ; |
179 | |
180 | let waker_state = from; |
181 | |
182 | self.waker_state = Some; |
183 | self.wake_fn = Some; |
184 | |
185 | match unsafe |
186 | |
187 | &*self as *const as *const , |
188 | self.poll_state, |
189 | |
190 | |
191 | => | Ready
192 | let result: Output = unsafe ; |
193 | |
194 | Ready |
195 | |
196 | => Pending, | Pending
197 | |
198 | |
199 | |
200 | |
201 | unsafe extern "C" |
202 | todo! |
203 | |
204 |