@@ -18,7 +18,7 @@ use core_foundation::{
1818} ;
1919use fsevent_sys:: { self as fs, kFSEventStreamCreateFlagFileEvents, kFSEventStreamCreateFlagNoDefer, kFSEventStreamCreateFlagWatchRoot} ;
2020use std:: {
21- ffi:: CStr , ptr, sync :: Arc
21+ ffi:: CStr , ptr
2222} ;
2323
2424struct CallbackContext {
@@ -33,7 +33,7 @@ pub struct NativeEventStream {
3333 queue : dispatch_queue_t ,
3434 stream : Option < fs:: FSEventStreamRef > ,
3535 receiver : chan:: Receiver < Event > ,
36- sender_heap : * mut Arc < CallbackContext > ,
36+ sender_heap : * mut CallbackContext ,
3737}
3838
3939
@@ -62,16 +62,17 @@ impl NativeEventStream {
6262 queue : unsafe { dispatch2:: ffi:: dispatch_queue_create ( ptr:: null ( ) , DISPATCH_QUEUE_SERIAL ) } ,
6363 stream : None ,
6464 receiver : r,
65- sender_heap : Box :: into_raw ( Box :: new ( Arc :: new ( CallbackContext { new_events : Box :: new ( new_events) , channel : s } ) ) )
65+ sender_heap : Box :: into_raw ( Box :: new ( CallbackContext { new_events : Box :: new ( new_events) , channel : s } ) )
6666 }
6767 }
6868
6969 fn build_context ( & mut self ) -> * const fsevent_sys:: FSEventStreamContext {
70+ eprintln ! ( "ctx sending: {?}" , self . sender_heap) ;
7071 & fs:: FSEventStreamContext {
7172 version : 0 ,
7273 info : self . sender_heap as * mut _ ,
73- retain : Some ( retain_arc ) ,
74- release : Some ( release_arc ) ,
74+ retain : None ,
75+ release : None ,
7576 copy_description : None
7677 }
7778 }
@@ -108,7 +109,7 @@ impl NativeEventStream {
108109 fs:: FSEventStreamInvalidate ( stream) ;
109110 dispatch2:: ffi:: dispatch_release ( self . queue as dispatch_object_t ) ;
110111 fs:: FSEventStreamRelease ( stream) ;
111- release_arc ( self . sender_heap as * mut c_void ) ;
112+ drop ( Box :: from ( self . sender_heap ) ) ;
112113 }
113114 None => unsafe {
114115 dispatch2:: ffi:: dispatch_release ( self . queue as dispatch_object_t ) ;
@@ -126,21 +127,6 @@ impl NativeEventStream {
126127
127128}
128129
129-
130- extern "C" fn retain_arc ( info : * mut c_void ) -> * mut c_void {
131- let ctx_ptr = info as * mut Arc < CallbackContext > ;
132- let ctx = unsafe { & mut * ctx_ptr } ;
133- Box :: into_raw ( Box :: new ( & ctx) ) as * mut _
134- }
135-
136- extern "C" fn release_arc ( info : * mut c_void ) {
137- let ctx_ptr = info as * mut Arc < CallbackContext > ;
138- unsafe { drop ( Box :: from_raw ( ctx_ptr) ) ; }
139- }
140-
141-
142-
143-
144130extern "C" fn callback (
145131 _stream_ref : fs:: FSEventStreamRef ,
146132 info : * mut c_void ,
@@ -149,7 +135,8 @@ extern "C" fn callback(
149135 event_flags : * const fs:: FSEventStreamEventFlags ,
150136 event_ids : * const fs:: FSEventStreamEventId ,
151137) {
152- let ctx = unsafe { & mut * ( info as * mut Arc < CallbackContext > ) } ;
138+ let ctx = unsafe { & mut * ( info as * mut CallbackContext ) } ;
139+ eprintln ! ( "ctx restored: {?}" , ctx) ;
153140
154141 let event_paths = event_paths as * const * const c_char ;
155142
@@ -167,7 +154,7 @@ extern "C" fn callback(
167154 }
168155
169156 if num_events > 0 {
170- eprintln ! ( "Sending message to java" ) ;
157+ eprintln ! ( "Sending message to java" ) ;
171158 ( ctx. new_events ) ( ) ;
172159 }
173160}
0 commit comments