Change RawWaker constructor to const fn
This commit is contained in:
parent
8e7ef03141
commit
a1c4cf6889
@ -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 @@ pub fn will_wake(&self, other: &Waker) -> bool {
|
||||
/// 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,
|
||||
|
@ -25,10 +25,7 @@ fn into_waker(wake: Arc<Self>) -> Waker where Self: Sized
|
||||
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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user