@@ -73,16 +73,22 @@ mod blk;
7373mod data;
7474#[ cfg( target_os = "macos" ) ]
7575mod io;
76+ #[ cfg( target_os = "macos" ) ]
77+ mod sem;
78+ mod time;
7679
7780#[ cfg( target_os = "macos" ) ]
78- pub use blk:: { perform, DispatchBlock , WaitTimeout } ;
81+ pub use blk:: { perform, DispatchBlock } ;
7982#[ cfg( target_os = "macos" ) ]
8083pub use data:: {
8184 dispatch_data_destructor_default, dispatch_data_destructor_free,
8285 dispatch_data_destructor_munmap, Data , Destructor ,
8386} ;
8487#[ cfg( target_os = "macos" ) ]
8588pub use ffi:: { DISPATCH_IO_STOP , DISPATCH_IO_STRICT_INTERVAL } ;
89+ #[ cfg( target_os = "macos" ) ]
90+ pub use sem:: Semaphore ;
91+ pub use time:: { after, at, now, Timeout , WaitTimeout } ;
8692
8793/// The type of a dispatch queue.
8894#[ derive( Clone , Debug , Hash , PartialEq ) ]
@@ -149,28 +155,6 @@ pub struct Queue {
149155 ptr : dispatch_queue_t ,
150156}
151157
152- fn time_after_delay ( delay : Duration ) -> dispatch_time_t {
153- delay
154- . as_secs ( )
155- . checked_mul ( 1_000_000_000 )
156- . and_then ( |i| i. checked_add ( delay. subsec_nanos ( ) as u64 ) )
157- . and_then ( |i| {
158- if i < ( i64:: max_value ( ) as u64 ) {
159- Some ( i as i64 )
160- } else {
161- None
162- }
163- } )
164- . map_or ( DISPATCH_TIME_FOREVER , |i| unsafe {
165- dispatch_time ( DISPATCH_TIME_NOW , i)
166- } )
167- }
168-
169- /// Returns a `dispatch_time_t` corresponding to the wall time.
170- pub fn now ( ) -> dispatch_time_t {
171- unsafe { dispatch_walltime ( ptr:: null ( ) , 0 ) }
172- }
173-
174158fn context_and_function < F > ( closure : F ) -> ( * mut c_void , dispatch_function_t )
175159where
176160 F : FnOnce ( ) ,
@@ -325,11 +309,12 @@ impl Queue {
325309
326310 /// After the specified delay, submits a closure for asynchronous execution
327311 /// on self.
328- pub fn after < F > ( & self , delay : Duration , work : F )
312+ pub fn after < F , T > ( & self , delay : T , work : F )
329313 where
330314 F : ' static + Send + FnOnce ( ) ,
315+ T : Timeout ,
331316 {
332- let when = time_after_delay ( delay) ;
317+ let when = delay. as_raw ( ) ;
333318 let ( context, work) = context_and_function ( work) ;
334319 unsafe {
335320 dispatch_after_f ( when, self . ptr , context, work) ;
@@ -581,8 +566,8 @@ impl Group {
581566 /// Waits for all tasks associated with self to complete within the
582567 /// specified duration.
583568 /// Returns true if the tasks completed or false if the timeout elapsed.
584- pub fn wait_timeout ( & self , timeout : Duration ) -> bool {
585- let when = time_after_delay ( timeout) ;
569+ pub fn wait_timeout < T : Timeout > ( & self , timeout : T ) -> bool {
570+ let when = timeout. as_raw ( ) ;
586571 let result = unsafe { dispatch_group_wait ( self . ptr , when) } ;
587572 result == 0
588573 }
0 commit comments