Skip to content

Commit 993ce4c

Browse files
committed
Remove source registration handler setter.
It's first available in the libdispatch from 10.7, which is newer than is packaged for most other platforms.
1 parent 60ddf27 commit 993ce4c

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

src/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extern {
101101
pub fn dispatch_source_get_mask(source: dispatch_source_t) -> c_ulong;
102102
pub fn dispatch_source_merge_data(source: dispatch_source_t, value: c_ulong);
103103
// void dispatch_source_set_registration_handler ( dispatch_source_t source, dispatch_block_t handler );
104-
pub fn dispatch_source_set_registration_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
104+
// void dispatch_source_set_registration_handler_f ( dispatch_source_t source, dispatch_function_t handler );
105105
// void dispatch_source_set_cancel_handler ( dispatch_source_t source, dispatch_block_t handler );
106106
pub fn dispatch_source_set_cancel_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
107107
// void dispatch_source_set_event_handler ( dispatch_source_t source, dispatch_block_t handler );

src/lib.rs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,6 @@ impl<T: SourceType> SourceBuilder<T> {
653653
}
654654

655655
impl<T> SourceBuilder<T> {
656-
/// Sets a registration handler on the source.
657-
pub fn registration_handler<F>(&mut self, handler: F) where F: 'static + Send + FnOnce(Source<T>) {
658-
self.source_.set_registration_handler(handler);
659-
}
660-
661656
/// Sets a cancelation handler on the source.
662657
pub fn cancel_handler<F>(&mut self, handler: F) where F: 'static + Send + FnOnce(Source<T>) {
663658
self.source_.set_cancel_handler(handler);
@@ -716,7 +711,6 @@ impl<T> Drop for BoxedOnceHandler<T> {
716711
}
717712

718713
struct SourceContext<T> {
719-
registration: Option<BoxedOnceHandler<Source<T>>>,
720714
cancel: Option<BoxedOnceHandler<Source<T>>>,
721715
event: Option<Box<Fn(Source<T>) + Send>>,
722716
source_ptr: dispatch_source_t, // unretained
@@ -725,7 +719,6 @@ struct SourceContext<T> {
725719
impl<T> SourceContext<T> {
726720
fn new(source: dispatch_source_t) -> Self {
727721
SourceContext {
728-
registration: None,
729722
cancel: None,
730723
event: None,
731724
source_ptr: source,
@@ -773,24 +766,6 @@ impl<T> Source<T> {
773766
&mut *(dispatch_get_context(self.ptr) as *mut SourceContext<T>)
774767
}
775768

776-
fn set_registration_handler<F>(&self, handler: F)
777-
where F: 'static + Send + FnOnce(Source<T>)
778-
{
779-
// is only run once per source
780-
extern fn source_handler<F: FnOnce(Source<T>), T>(ptr: *mut c_void) {
781-
unsafe {
782-
let ctx = ptr as *mut SourceContext<T>;
783-
if let Some(f) = (*ctx).registration.take() {
784-
f.call(Source::from_raw((*ctx).source_ptr));
785-
}
786-
}
787-
}
788-
unsafe {
789-
self.context().registration = Some(BoxedOnceHandler::new(handler));
790-
dispatch_source_set_registration_handler_f(self.ptr, source_handler::<F, T>);
791-
}
792-
}
793-
794769
fn set_cancel_handler<F>(&self, handler: F)
795770
where F: 'static + Send + FnOnce(Source<T>)
796771
{
@@ -1103,14 +1078,11 @@ mod tests {
11031078

11041079
#[test]
11051080
fn test_source() {
1106-
let reg_barrier = Arc::new(Barrier::new(2));
11071081
let event_barrier = Arc::new(Barrier::new(2));
11081082
let cancel_barrier = Arc::new(Barrier::new(2));
11091083
let num = Arc::new(Mutex::new(0));
11101084
let sum = Arc::new(Mutex::new(0));
11111085

1112-
let reg_num = num.clone();
1113-
let reg_handler_barrier = reg_barrier.clone();
11141086
let ev_num = num.clone();
11151087
let ev_sum = sum.clone();
11161088
let event_handler_barrier = event_barrier.clone();
@@ -1119,26 +1091,20 @@ mod tests {
11191091

11201092
let q = Queue::create("", QueueAttribute::Serial);
11211093
let mut sb = SourceBuilder::new(source::DataAdd, &q).unwrap();
1122-
sb.registration_handler(move |_| {
1123-
let mut num = reg_num.lock().unwrap();
1124-
*num |= 1;
1125-
reg_handler_barrier.wait();
1126-
});
11271094
sb.event_handler(move |source| {
11281095
let mut num = ev_num.lock().unwrap();
11291096
let mut sum = ev_sum.lock().unwrap();
11301097
*sum += source.data();
1131-
*num |= 2;
1098+
*num |= 1;
11321099
event_handler_barrier.wait();
11331100
});
11341101
sb.cancel_handler(move |_| {
11351102
let mut num = cancel_num.lock().unwrap();
1136-
*num |= 4;
1103+
*num |= 2;
11371104
cancel_handler_barrier.wait();
11381105
});
11391106
let source = sb.resume();
11401107

1141-
reg_barrier.wait();
11421108
source.merge_data(3);
11431109
event_barrier.wait();
11441110
assert_eq!(*sum.lock().unwrap(), 3);
@@ -1147,7 +1113,7 @@ mod tests {
11471113
assert_eq!(*sum.lock().unwrap(), 8);
11481114
source.cancel();
11491115
cancel_barrier.wait();
1150-
assert_eq!(*num.lock().unwrap(), 7);
1116+
assert_eq!(*num.lock().unwrap(), 3);
11511117
}
11521118

11531119
#[test]

0 commit comments

Comments
 (0)