Skip to content

Commit

Permalink
Move the data and vtable methods from RawWaker to Waker
Browse files Browse the repository at this point in the history
Per the `waker_getters` FCP:
rust-lang#96992 (comment)
  • Loading branch information
kevinmehall committed Sep 3, 2024
1 parent 1dd630f commit 2ec266b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
44 changes: 22 additions & 22 deletions core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,6 @@ impl RawWaker {
RawWaker { data, vtable }
}

/// Gets the `data` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn data(&self) -> *const () {
self.data
}

/// Gets the `vtable` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.vtable
}

#[unstable(feature = "noop_waker", issue = "98286")]
const NOOP: RawWaker = {
const VTABLE: RawWakerVTable = RawWakerVTable::new(
Expand Down Expand Up @@ -565,12 +549,20 @@ impl Waker {
WAKER
}

/// Gets a reference to the underlying [`RawWaker`].
/// Gets the `data` pointer used to create this `Waker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn as_raw(&self) -> &RawWaker {
&self.waker
pub fn data(&self) -> *const () {
self.waker.data
}

/// Gets the `vtable` pointer used to create this `Waker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.waker.vtable
}
}

Expand Down Expand Up @@ -831,12 +823,20 @@ impl LocalWaker {
WAKER
}

/// Gets a reference to the underlying [`RawWaker`].
/// Gets the `data` pointer used to create this `LocalWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn as_raw(&self) -> &RawWaker {
&self.waker
pub fn data(&self) -> *const () {
self.waker.data
}

/// Gets the `vtable` pointer used to create this `LocalWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.waker.vtable
}
}
#[unstable(feature = "local_waker", issue = "118959")]
Expand Down
11 changes: 5 additions & 6 deletions core/tests/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::task::{RawWaker, RawWakerVTable, Waker};
#[test]
fn test_waker_getters() {
let raw_waker = RawWaker::new(ptr::without_provenance_mut(42usize), &WAKER_VTABLE);
assert_eq!(raw_waker.data() as usize, 42);
assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE));

let waker = unsafe { Waker::from_raw(raw_waker) };
assert_eq!(waker.data() as usize, 42);
assert!(ptr::eq(waker.vtable(), &WAKER_VTABLE));

let waker2 = waker.clone();
let raw_waker2 = waker2.as_raw();
assert_eq!(raw_waker2.data() as usize, 43);
assert!(ptr::eq(raw_waker2.vtable(), &WAKER_VTABLE));
assert_eq!(waker2.data() as usize, 43);
assert!(ptr::eq(waker2.vtable(), &WAKER_VTABLE));
}

static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
Expand Down

0 comments on commit 2ec266b

Please sign in to comment.