about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/task/wake.rs28
-rw-r--r--src/test/run-pass/auxiliary/arc_wake.rs10
2 files changed, 26 insertions, 12 deletions
diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs
index a877e033bc6..21f0a8cea41 100644
--- a/src/libcore/task/wake.rs
+++ b/src/libcore/task/wake.rs
@@ -19,9 +19,29 @@ pub struct RawWaker {
     /// that is associated with the task.
     /// The value of this field gets passed to all functions that are part of
     /// the vtable as the first parameter.
-    pub data: *const (),
+    data: *const (),
     /// Virtual function pointer table that customizes the behavior of this waker.
-    pub vtable: &'static RawWakerVTable,
+    vtable: &'static RawWakerVTable,
+}
+
+impl RawWaker {
+    /// Creates a new `RawWaker` from the provided `data` pointer and `vtable`.
+    ///
+    /// The `data` pointer can be used to store arbitrary data as required
+    /// by the executor. This could be e.g. a type-erased pointer to an `Arc`
+    /// that is associated with the task.
+    /// The value of this poiner will get passed to all functions that are part
+    /// of the `vtable` as the first parameter.
+    ///
+    /// The `vtable` customizes the behavior of a `Waker` which gets created
+    /// from a `RawWaker`. For each operation on the `Waker`, the associated
+    /// function in the `vtable` of the underlying `RawWaker` will be called.
+    pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker {
+        RawWaker {
+            data,
+            vtable,
+        }
+    }
 }
 
 /// A virtual function pointer table (vtable) that specifies the behavior
@@ -102,8 +122,8 @@ impl Waker {
     /// Creates a new `Waker` from [`RawWaker`].
     ///
     /// The behavior of the returned `Waker` is undefined if the contract defined
-    /// in [RawWaker]'s documentation is not upheld. Therefore this method is
-    /// unsafe.
+    /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
+    /// Therefore this method is unsafe.
     pub unsafe fn new_unchecked(waker: RawWaker) -> Waker {
         Waker {
             waker,
diff --git a/src/test/run-pass/auxiliary/arc_wake.rs b/src/test/run-pass/auxiliary/arc_wake.rs
index 0baaa378046..034e378af7f 100644
--- a/src/test/run-pass/auxiliary/arc_wake.rs
+++ b/src/test/run-pass/auxiliary/arc_wake.rs
@@ -25,10 +25,7 @@ pub trait ArcWake {
         let ptr = Arc::into_raw(wake) as *const();
 
         unsafe {
-            Waker::new_unchecked(RawWaker{
-                data: ptr,
-                vtable: waker_vtable!(Self),
-            })
+            Waker::new_unchecked(RawWaker::new(ptr, waker_vtable!(Self)))
         }
     }
 }
@@ -44,10 +41,7 @@ unsafe fn increase_refcount<T: ArcWake>(data: *const()) {
 
 unsafe fn clone_arc_raw<T: ArcWake>(data: *const()) -> RawWaker {
     increase_refcount::<T>(data);
-    RawWaker {
-        data: data,
-        vtable: waker_vtable!(T),
-    }
+    RawWaker::new(data, waker_vtable!(T))
 }
 
 unsafe fn drop_arc_raw<T: ArcWake>(data: *const()) {