11use core:: {
22 ptr:: NonNull ,
33 sync:: atomic:: { AtomicBool , Ordering } ,
4- task:: { LocalWaker , UnsafeWake , Waker } ,
4+ task:: { LocalWaker , Waker , RawWaker , RawWakerVTable } ,
55} ;
66
77pub struct EmbrioWaker {
88 woken : AtomicBool ,
99}
1010
11+ static EMBRIO_WAKER_RAW_WAKER_VTABLE : RawWakerVTable = RawWakerVTable {
12+ // "Unsafe closures"
13+ clone : { unsafe fn clone ( data : * const ( ) ) -> RawWaker {
14+ ( data as * const EmbrioWaker as & ' static EmbrioWaker ) . raw_waker ( )
15+ } clone } ,
16+ into_waker : { unsafe fn into_waker ( data : * const ( ) ) -> Option < RawWaker > {
17+ Some ( ( data as * const EmbrioWaker as & ' static EmbrioWaker ) . raw_waker ( ) )
18+ } into_waker } ,
19+ wake : { unsafe fn wake ( data : * const ( ) ) {
20+ ( data as * const EmbrioWaker as & ' static EmbrioWaker ) . wake ( )
21+ } wake } ,
22+ drop_fn : { unsafe fn drop_fn ( data : * const ( ) ) {
23+ // No-op
24+ } drop_fn } ,
25+ } ;
26+
1127impl EmbrioWaker {
1228 pub ( crate ) const fn new ( ) -> Self {
1329 EmbrioWaker {
@@ -17,9 +33,7 @@ impl EmbrioWaker {
1733
1834 pub ( crate ) fn local_waker ( & ' static self ) -> LocalWaker {
1935 unsafe {
20- LocalWaker :: new ( NonNull :: new_unchecked (
21- & self as & UnsafeWake as * const _ as * mut _ ,
22- ) )
36+ LocalWaker :: new_unchecked ( self . raw_waker ( ) )
2337 }
2438 }
2539
@@ -30,20 +44,18 @@ impl EmbrioWaker {
3044 pub ( crate ) fn sleep ( ) {
3145 cortex_m:: asm:: wfe ( ) ;
3246 }
33- }
34-
35- unsafe impl UnsafeWake for & ' static EmbrioWaker {
36- unsafe fn clone_raw ( & self ) -> Waker {
37- Waker :: new ( NonNull :: new_unchecked (
38- self as & UnsafeWake as * const _ as * mut _ ,
39- ) )
40- }
4147
42- unsafe fn drop_raw ( & self ) { }
43-
44- unsafe fn wake ( & self ) {
48+ pub ( crate ) fn wake ( & self ) {
4549 self . woken . store ( true , Ordering :: Release ) ;
4650 // we send an event in case this was a non-interrupt driven wake
4751 cortex_m:: asm:: sev ( ) ;
4852 }
53+
54+ // TODO: Is this unsafe in any way?
55+ pub ( crate ) fn raw_waker ( & ' static self ) -> RawWaker {
56+ RawWaker {
57+ data : self as * const Self as * const ( ) ,
58+ vtable : & EMBRIO_WAKER_RAW_WAKER_VTABLE
59+ }
60+ }
4961}
0 commit comments