Skip to content

Commit 9b8e074

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 f699c46 commit 9b8e074

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
@@ -98,7 +98,7 @@ extern {
9898
pub fn dispatch_source_get_mask(source: dispatch_source_t) -> c_ulong;
9999
pub fn dispatch_source_merge_data(source: dispatch_source_t, value: c_ulong);
100100
// void dispatch_source_set_registration_handler ( dispatch_source_t source, dispatch_block_t handler );
101-
pub fn dispatch_source_set_registration_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
101+
// void dispatch_source_set_registration_handler_f ( dispatch_source_t source, dispatch_function_t handler );
102102
// void dispatch_source_set_cancel_handler ( dispatch_source_t source, dispatch_block_t handler );
103103
pub fn dispatch_source_set_cancel_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
104104
// 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
@@ -651,11 +651,6 @@ impl<T: SourceType> SourceBuilder<T> {
651651
}
652652

653653
impl<T> SourceBuilder<T> {
654-
/// Sets a registration handler on the source.
655-
pub fn registration_handler<F>(&mut self, handler: F) where F: 'static + Send + FnOnce(Source<T>) {
656-
self.source_.set_registration_handler(handler);
657-
}
658-
659654
/// Sets a cancelation handler on the source.
660655
pub fn cancel_handler<F>(&mut self, handler: F) where F: 'static + Send + FnOnce(Source<T>) {
661656
self.source_.set_cancel_handler(handler);
@@ -714,7 +709,6 @@ impl<T> Drop for BoxedOnceHandler<T> {
714709
}
715710

716711
struct SourceContext<T> {
717-
registration: Option<BoxedOnceHandler<Source<T>>>,
718712
cancel: Option<BoxedOnceHandler<Source<T>>>,
719713
event: Option<Box<Fn(Source<T>) + Send>>,
720714
source_ptr: dispatch_source_t, // unretained
@@ -723,7 +717,6 @@ struct SourceContext<T> {
723717
impl<T> SourceContext<T> {
724718
fn new(source: dispatch_source_t) -> Self {
725719
SourceContext {
726-
registration: None,
727720
cancel: None,
728721
event: None,
729722
source_ptr: source,
@@ -771,24 +764,6 @@ impl<T> Source<T> {
771764
&mut *(dispatch_get_context(self.ptr) as *mut SourceContext<T>)
772765
}
773766

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

11011076
#[test]
11021077
fn test_source() {
1103-
let reg_barrier = Arc::new(Barrier::new(2));
11041078
let event_barrier = Arc::new(Barrier::new(2));
11051079
let cancel_barrier = Arc::new(Barrier::new(2));
11061080
let num = Arc::new(Mutex::new(0));
11071081
let sum = Arc::new(Mutex::new(0));
11081082

1109-
let reg_num = num.clone();
1110-
let reg_handler_barrier = reg_barrier.clone();
11111083
let ev_num = num.clone();
11121084
let ev_sum = sum.clone();
11131085
let event_handler_barrier = event_barrier.clone();
@@ -1116,26 +1088,20 @@ mod tests {
11161088

11171089
let q = Queue::create("", QueueAttribute::Serial);
11181090
let mut sb = SourceBuilder::new(source::DataAdd, &q).unwrap();
1119-
sb.registration_handler(move |_| {
1120-
let mut num = reg_num.lock().unwrap();
1121-
*num |= 1;
1122-
reg_handler_barrier.wait();
1123-
});
11241091
sb.event_handler(move |source| {
11251092
let mut num = ev_num.lock().unwrap();
11261093
let mut sum = ev_sum.lock().unwrap();
11271094
*sum += source.data();
1128-
*num |= 2;
1095+
*num |= 1;
11291096
event_handler_barrier.wait();
11301097
});
11311098
sb.cancel_handler(move |_| {
11321099
let mut num = cancel_num.lock().unwrap();
1133-
*num |= 4;
1100+
*num |= 2;
11341101
cancel_handler_barrier.wait();
11351102
});
11361103
let source = sb.resume();
11371104

1138-
reg_barrier.wait();
11391105
source.merge_data(3);
11401106
event_barrier.wait();
11411107
assert_eq!(*sum.lock().unwrap(), 3);
@@ -1144,7 +1110,7 @@ mod tests {
11441110
assert_eq!(*sum.lock().unwrap(), 8);
11451111
source.cancel();
11461112
cancel_barrier.wait();
1147-
assert_eq!(*num.lock().unwrap(), 7);
1113+
assert_eq!(*num.lock().unwrap(), 3);
11481114
}
11491115

11501116
#[test]

0 commit comments

Comments
 (0)