about summary refs log tree commit diff
path: root/src/libcore/task
diff options
context:
space:
mode:
authorMatthias Einwag <matthias.einwag@live.com>2019-02-06 22:56:33 -0800
committerMatthias Einwag <matthias.einwag@live.com>2019-02-06 22:56:33 -0800
commita1c4cf6889f69dc335a3f0b42b29e4d9a081005d (patch)
tree41f0c683d9f7adea20139205b076677ad37323ef /src/libcore/task
parent8e7ef03141c40e34bd740bfe521b656387af9d56 (diff)
downloadrust-a1c4cf6889f69dc335a3f0b42b29e4d9a081005d.tar.gz
rust-a1c4cf6889f69dc335a3f0b42b29e4d9a081005d.zip
Change RawWaker constructor to const fn
Diffstat (limited to 'src/libcore/task')
-rw-r--r--src/libcore/task/wake.rs28
1 files changed, 24 insertions, 4 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,