prevent wake_by_ref from decreasing refcount. Fixes #22

This commit is contained in:
Carl Fredrik Samson
2020-12-05 23:01:35 +01:00
parent 8dfd7f445c
commit 3ba348601a
2 changed files with 26 additions and 26 deletions

View File

@@ -166,10 +166,10 @@ fn mywaker_clone(s: &MyWaker) -> RawWaker {
// set of functions // set of functions
const VTABLE: RawWakerVTable = unsafe { const VTABLE: RawWakerVTable = unsafe {
RawWakerVTable::new( RawWakerVTable::new(
|s| mywaker_clone(&*(s as *const MyWaker)), // clone |s| mywaker_clone(&*(s as *const MyWaker)), // clone
|s| mywaker_wake(&*(s as *const MyWaker)), // wake |s| mywaker_wake(&*(s as *const MyWaker)), // wake
|s| mywaker_wake(*(s as *const &MyWaker)), // wake by ref |s| (*(s as *const MyWaker)).parker.unpark(), // wake by ref (don't decrease refcount)
|s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount
) )
}; };
@@ -537,7 +537,7 @@ fn main() {
# RawWakerVTable::new( # RawWakerVTable::new(
# |s| mywaker_clone(&*(s as *const MyWaker)), // clone # |s| mywaker_clone(&*(s as *const MyWaker)), // clone
# |s| mywaker_wake(&*(s as *const MyWaker)), // wake # |s| mywaker_wake(&*(s as *const MyWaker)), // wake
# |s| mywaker_wake(*(s as *const &MyWaker)), // wake by ref # |s| (*(s as *const MyWaker)).thread.unpark(), // wake by ref (don't decrease refcount)
# |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount # |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount
# ) # )
# }; # };

View File

@@ -93,7 +93,7 @@ const VTABLE: RawWakerVTable = unsafe {
RawWakerVTable::new( RawWakerVTable::new(
|s| mywaker_clone(&*(s as *const MyWaker)), // clone |s| mywaker_clone(&*(s as *const MyWaker)), // clone
|s| mywaker_wake(&*(s as *const MyWaker)), // wake |s| mywaker_wake(&*(s as *const MyWaker)), // wake
|s| mywaker_wake(*(s as *const &MyWaker)), // wake by ref |s| (*(s as *const MyWaker)).parker.unpark(), // wake by ref (don't decrease refcount)
|s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount
) )
}; };