16
16
17
17
use fmt;
18
18
use ptr:: NonNull ;
19
+ use future:: Future ;
20
+ use mem:: PinMut ;
19
21
20
22
/// Indicates whether a value is available or if the current task has been
21
23
/// scheduled to receive a wakeup instead.
@@ -455,8 +457,8 @@ pub trait Executor {
455
457
/// `Box<Future<Output = ()> + Send>`.
456
458
pub struct TaskObj {
457
459
ptr : * mut ( ) ,
458
- poll : unsafe fn ( * mut ( ) , & mut Context ) -> Poll < ( ) > ,
459
- drop : unsafe fn ( * mut ( ) ) ,
460
+ poll_fn : unsafe fn ( * mut ( ) , & mut Context ) -> Poll < ( ) > ,
461
+ drop_fn : unsafe fn ( * mut ( ) ) ,
460
462
}
461
463
462
464
impl fmt:: Debug for TaskObj {
@@ -467,7 +469,6 @@ impl fmt::Debug for TaskObj {
467
469
}
468
470
469
471
unsafe impl Send for TaskObj { }
470
- unsafe impl Sync for TaskObj { }
471
472
472
473
/// A custom implementation of a task trait object for `TaskObj`, providing
473
474
/// a hand-rolled vtable.
@@ -478,7 +479,7 @@ unsafe impl Sync for TaskObj {}
478
479
/// The implementor must guarantee that it is safe to call `poll` repeatedly (in
479
480
/// a non-concurrent fashion) with the result of `into_raw` until `drop` is
480
481
/// called.
481
- pub unsafe trait UnsafePoll : Send + ' static {
482
+ pub unsafe trait UnsafeTask : Send + ' static {
482
483
/// Convert a owned instance into a (conceptually owned) void pointer.
483
484
fn into_raw ( self ) -> * mut ( ) ;
484
485
@@ -504,30 +505,30 @@ pub unsafe trait UnsafePoll: Send + 'static {
504
505
impl TaskObj {
505
506
/// Create a `TaskObj` from a custom trait object representation.
506
507
#[ inline]
507
- pub fn from_poll_task < T : UnsafePoll > ( t : T ) -> TaskObj {
508
+ pub fn new < T : UnsafeTask > ( t : T ) -> TaskObj {
508
509
TaskObj {
509
510
ptr : t. into_raw ( ) ,
510
- poll : T :: poll,
511
- drop : T :: drop,
511
+ poll_fn : T :: poll,
512
+ drop_fn : T :: drop,
512
513
}
513
514
}
515
+ }
516
+
517
+ impl Future for TaskObj {
518
+ type Output = ( ) ;
514
519
515
- /// Poll the task.
516
- ///
517
- /// The semantics here are identical to that for futures, but unlike
518
- /// futures only an `&mut self` reference is needed here.
519
520
#[ inline]
520
- pub fn poll_task ( & mut self , cx : & mut Context ) -> Poll < ( ) > {
521
+ fn poll ( self : PinMut < Self > , cx : & mut Context ) -> Poll < ( ) > {
521
522
unsafe {
522
- ( self . poll ) ( self . ptr , cx)
523
+ ( self . poll_fn ) ( self . ptr , cx)
523
524
}
524
525
}
525
526
}
526
527
527
528
impl Drop for TaskObj {
528
529
fn drop ( & mut self ) {
529
530
unsafe {
530
- ( self . drop ) ( self . ptr )
531
+ ( self . drop_fn ) ( self . ptr )
531
532
}
532
533
}
533
534
}
0 commit comments