@@ -63,23 +63,6 @@ impl RawWaker {
63
63
}
64
64
65
65
const RAW_WAKER_VTABLE_V1_PADDING : usize = 0 ;
66
-
67
- /// A virtual function pointer table (vtable) that specifies the behavior
68
- /// of a [`RawWaker`].
69
- ///
70
- /// The pointer passed to all functions inside the vtable is the `data` pointer
71
- /// from the enclosing [`RawWaker`] object.
72
- ///
73
- /// The functions inside this struct are only intended to be called on the `data`
74
- /// pointer of a properly constructed [`RawWaker`] object from inside the
75
- /// [`RawWaker`] implementation. Calling one of the contained functions using
76
- /// any other `data` pointer will cause undefined behavior.
77
- ///
78
- /// These functions must all be thread-safe (even though [`RawWaker`] is
79
- /// <code>\![Send] + \![Sync]</code>)
80
- /// because [`Waker`] is <code>[Send] + [Sync]</code>, and thus wakers may be moved to
81
- /// arbitrary threads or invoked by `&` reference. For example, this means that if the
82
- /// `clone` and `drop` functions manage a reference count, they must do so atomically.
83
66
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
84
67
#[ derive( PartialEq , Copy , Clone , Debug ) ]
85
68
#[ repr( C ) ]
@@ -159,18 +142,42 @@ struct RawWakerVTableV2 {
159
142
padding : [ * const ( ) ; 2 + RAW_WAKER_VTABLE_V1_PADDING ] , // Reserved space for future changes to the v-table, the need for it and amount are debatable.
160
143
}
161
144
145
+ /// A virtual function pointer table (vtable) that specifies the behavior
146
+ /// of a [`RawWaker`].
147
+ ///
148
+ /// The pointer passed to all functions inside the vtable is the `data` pointer
149
+ /// from the enclosing [`RawWaker`] object.
150
+ ///
151
+ /// The functions inside this struct are only intended to be called on the `data`
152
+ /// pointer of a properly constructed [`RawWaker`] object from inside the
153
+ /// [`RawWaker`] implementation. Calling one of the contained functions using
154
+ /// any other `data` pointer will cause undefined behavior.
155
+ ///
156
+ /// These functions must all be thread-safe (even though [`RawWaker`] is
157
+ /// <code>\![Send] + \![Sync]</code>)
158
+ /// because [`Waker`] is <code>[Send] + [Sync]</code>, and thus wakers may be moved to
159
+ /// arbitrary threads or invoked by `&` reference. For example, this means that if the
160
+ /// `clone` and `drop` functions manage a reference count, they must do so atomically.
162
161
#[ repr( C ) ]
163
162
#[ derive( Clone , Copy ) ]
163
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
164
164
pub union RawWakerVTable {
165
165
v1 : RawWakerVTableV1 ,
166
166
v2 : RawWakerVTableV2 ,
167
167
}
168
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
169
+ unsafe impl Send for RawWakerVTable { }
170
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
171
+ unsafe impl Sync for RawWakerVTable { }
168
172
173
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
169
174
impl PartialEq for RawWakerVTable {
170
175
fn eq ( & self , other : & Self ) -> bool {
171
176
unsafe { self . v2 == other. v2 }
172
177
}
173
178
}
179
+
180
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
174
181
impl fmt:: Debug for RawWakerVTable {
175
182
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
176
183
unsafe {
@@ -182,6 +189,21 @@ impl fmt::Debug for RawWakerVTable {
182
189
}
183
190
}
184
191
192
+ #[ allow( improper_ctypes_definitions) ]
193
+ /// # Safety
194
+ /// This function must only be called with function pointers sourced from the same shared object
195
+ unsafe extern "C" fn clone_adapter (
196
+ clone : unsafe fn ( * const ( ) ) -> RawWaker ,
197
+ data : * const ( ) ,
198
+ ) -> RawWaker {
199
+ unsafe { ( clone) ( data) }
200
+ }
201
+ #[ allow( improper_ctypes_definitions) ]
202
+ /// # Safety
203
+ /// This function must only be called with function pointers sourced from the same shared object
204
+ unsafe extern "C" fn other_adapter ( other : unsafe fn ( * const ( ) ) , data : * const ( ) ) {
205
+ unsafe { ( other) ( data) }
206
+ }
185
207
impl RawWakerVTable {
186
208
/// Creates a new `RawWakerVTable` from the provided `clone`, `wake`,
187
209
/// `wake_by_ref`, and `drop` functions.
@@ -192,7 +214,7 @@ impl RawWakerVTable {
192
214
/// arbitrary threads or invoked by `&` reference. For example, this means that if the
193
215
/// `clone` and `drop` functions manage a reference count, they must do so atomically.
194
216
///
195
- /# `clone`
217
+ /// # `clone`
196
218
///
197
219
/// This function will be called when the [`RawWaker`] gets cloned, e.g. when
198
220
/// the [`Waker`] in which the [`RawWaker`] is stored gets cloned.
@@ -202,7 +224,7 @@ impl RawWakerVTable {
202
224
/// task. Calling `wake` on the resulting [`RawWaker`] should result in a wakeup
203
225
/// of the same task that would have been awoken by the original [`RawWaker`].
204
226
///
205
- /# `wake`
227
+ /// # `wake`
206
228
///
207
229
/// This function will be called when `wake` is called on the [`Waker`].
208
230
/// It must wake up the task associated with this [`RawWaker`].
@@ -211,15 +233,15 @@ impl RawWakerVTable {
211
233
/// resources that are associated with this instance of a [`RawWaker`] and
212
234
/// associated task.
213
235
///
214
- /# `wake_by_ref`
236
+ /// # `wake_by_ref`
215
237
///
216
238
/// This function will be called when `wake_by_ref` is called on the [`Waker`].
217
239
/// It must wake up the task associated with this [`RawWaker`].
218
240
///
219
241
/// This function is similar to `wake`, but must not consume the provided data
220
242
/// pointer.
221
243
///
222
- /# `drop`
244
+ /// # `drop`
223
245
///
224
246
/// This function gets called when a [`Waker`] gets dropped.
225
247
///
@@ -229,22 +251,17 @@ impl RawWakerVTable {
229
251
#[ rustc_promotable]
230
252
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
231
253
#[ rustc_const_stable( feature = "futures_api" , since = "1.36.0" ) ]
232
- #[ deprecated = "This constructor makes slower wakers, use new_with_c_abi instead" ]
254
+ #[ deprecated(
255
+ since = "TBD" ,
256
+ note = "This constructor makes slower wakers" ,
257
+ suggestion = "new_with_c_abi"
258
+ ) ]
233
259
pub const fn new (
234
260
clone : unsafe fn ( * const ( ) ) -> RawWaker ,
235
261
wake : unsafe fn ( * const ( ) ) ,
236
262
wake_by_ref : unsafe fn ( * const ( ) ) ,
237
263
drop : unsafe fn ( * const ( ) ) ,
238
264
) -> Self {
239
- unsafe extern "C" fn clone_adapter (
240
- clone : unsafe fn ( * const ( ) ) -> RawWaker ,
241
- data : * const ( ) ,
242
- ) -> RawWaker {
243
- clone ( data)
244
- }
245
- unsafe extern "C" fn other_adapter ( other : unsafe fn ( * const ( ) ) , data : * const ( ) ) {
246
- other ( data)
247
- }
248
265
Self {
249
266
v1 : RawWakerVTableV1 {
250
267
clone,
@@ -267,7 +284,7 @@ impl RawWakerVTable {
267
284
/// arbitrary threads or invoked by `&` reference. For example, this means that if the
268
285
/// `clone` and `drop` functions manage a reference count, they must do so atomically.
269
286
///
270
- /# `clone`
287
+ /// # `clone`
271
288
///
272
289
/// This function will be called when the [`RawWaker`] gets cloned, e.g. when
273
290
/// the [`Waker`] in which the [`RawWaker`] is stored gets cloned.
@@ -277,7 +294,7 @@ impl RawWakerVTable {
277
294
/// task. Calling `wake` on the resulting [`RawWaker`] should result in a wakeup
278
295
/// of the same task that would have been awoken by the original [`RawWaker`].
279
296
///
280
- /# `wake`
297
+ /// # `wake`
281
298
///
282
299
/// This function will be called when `wake` is called on the [`Waker`].
283
300
/// It must wake up the task associated with this [`RawWaker`].
@@ -286,22 +303,24 @@ impl RawWakerVTable {
286
303
/// resources that are associated with this instance of a [`RawWaker`] and
287
304
/// associated task.
288
305
///
289
- /# `wake_by_ref`
306
+ /// # `wake_by_ref`
290
307
///
291
308
/// This function will be called when `wake_by_ref` is called on the [`Waker`].
292
309
/// It must wake up the task associated with this [`RawWaker`].
293
310
///
294
311
/// This function is similar to `wake`, but must not consume the provided data
295
312
/// pointer.
296
313
///
297
- /# `drop`
314
+ /// # `drop`
298
315
///
299
316
/// This function gets called when a [`Waker`] gets dropped.
300
317
///
301
318
/// The implementation of this function must make sure to release any
302
319
/// resources that are associated with this instance of a [`RawWaker`] and
303
320
/// associated task.
304
321
#[ rustc_promotable]
322
+ #[ unstable( feature = "stable_wakers" , issue = "109706" ) ]
323
+ #[ rustc_const_unstable( feature = "stable_wakers" , issue = "109706" ) ]
305
324
pub const fn new_with_c_abi (
306
325
clone : unsafe extern "C" fn ( * const ( ) ) -> RawWaker ,
307
326
wake : unsafe extern "C" fn ( * const ( ) ) ,
@@ -345,11 +364,7 @@ impl<'a> Context<'a> {
345
364
#[ must_use]
346
365
#[ inline]
347
366
pub const fn from_waker ( waker : & ' a Waker ) -> Self {
348
- Context {
349
- waker,
350
- _marker : PhantomData ,
351
- _marker2 : PhantomData ,
352
- }
367
+ Context { waker, _marker : PhantomData , _marker2 : PhantomData }
353
368
}
354
369
355
370
/// Returns a reference to the [`Waker`] for the current task.
@@ -365,9 +380,7 @@ impl<'a> Context<'a> {
365
380
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
366
381
impl fmt:: Debug for Context < ' _ > {
367
382
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
368
- f. debug_struct ( "Context" )
369
- . field ( "waker" , & self . waker )
370
- . finish ( )
383
+ f. debug_struct ( "Context" ) . field ( "waker" , & self . waker ) . finish ( )
371
384
}
372
385
}
373
386
@@ -437,16 +450,9 @@ impl Waker {
437
450
unsafe {
438
451
match * vtable {
439
452
RawWakerVTable {
440
- v1 :
441
- RawWakerVTableV1 {
442
- wake,
443
- other_adapter : Some ( other_adapter) ,
444
- ..
445
- } ,
453
+ v1 : RawWakerVTableV1 { wake, other_adapter : Some ( other_adapter) , .. } ,
446
454
} => ( other_adapter) ( wake, data) ,
447
- RawWakerVTable {
448
- v2 : RawWakerVTableV2 { wake, .. } ,
449
- } => ( wake) ( data) ,
455
+ RawWakerVTable { v2 : RawWakerVTableV2 { wake, .. } } => ( wake) ( data) ,
450
456
}
451
457
} ;
452
458
}
@@ -467,16 +473,9 @@ impl Waker {
467
473
unsafe {
468
474
match * vtable {
469
475
RawWakerVTable {
470
- v1 :
471
- RawWakerVTableV1 {
472
- wake_by_ref,
473
- other_adapter : Some ( other_adapter) ,
474
- ..
475
- } ,
476
+ v1 : RawWakerVTableV1 { wake_by_ref, other_adapter : Some ( other_adapter) , .. } ,
476
477
} => ( other_adapter) ( wake_by_ref, data) ,
477
- RawWakerVTable {
478
- v2 : RawWakerVTableV2 { wake_by_ref, .. } ,
479
- } => ( wake_by_ref) ( data) ,
478
+ RawWakerVTable { v2 : RawWakerVTableV2 { wake_by_ref, .. } } => ( wake_by_ref) ( data) ,
480
479
}
481
480
}
482
481
}
@@ -529,16 +528,9 @@ impl Clone for Waker {
529
528
waker : unsafe {
530
529
match * vtable {
531
530
RawWakerVTable {
532
- v1 :
533
- RawWakerVTableV1 {
534
- clone,
535
- clone_adapter : Some ( clone_adapter) ,
536
- ..
537
- } ,
531
+ v1 : RawWakerVTableV1 { clone, clone_adapter : Some ( clone_adapter) , .. } ,
538
532
} => ( clone_adapter) ( clone, data) ,
539
- RawWakerVTable {
540
- v2 : RawWakerVTableV2 { clone, .. } ,
541
- } => ( clone) ( data) ,
533
+ RawWakerVTable { v2 : RawWakerVTableV2 { clone, .. } } => ( clone) ( data) ,
542
534
}
543
535
} ,
544
536
}
@@ -556,16 +548,9 @@ impl Drop for Waker {
556
548
unsafe {
557
549
match * vtable {
558
550
RawWakerVTable {
559
- v1 :
560
- RawWakerVTableV1 {
561
- drop,
562
- other_adapter : Some ( other_adapter) ,
563
- ..
564
- } ,
551
+ v1 : RawWakerVTableV1 { drop, other_adapter : Some ( other_adapter) , .. } ,
565
552
} => ( other_adapter) ( drop, data) ,
566
- RawWakerVTable {
567
- v2 : RawWakerVTableV2 { drop, .. } ,
568
- } => ( drop) ( data) ,
553
+ RawWakerVTable { v2 : RawWakerVTableV2 { drop, .. } } => ( drop) ( data) ,
569
554
}
570
555
}
571
556
}
0 commit comments