kern_return_t semaphore_timedwait_signal_trap_internal( mach_port_name_t wait_name, mach_port_name_t signal_name, unsigned int sec, clock_res_t nsec, void (*caller_cont)(kern_return_t)) { semaphore_t wait_semaphore; semaphore_t signal_semaphore; mach_timespec_t wait_time; kern_return_t kr; wait_time.tv_sec = sec; wait_time.tv_nsec = nsec; if(BAD_MACH_TIMESPEC(&wait_time)) return KERN_INVALID_VALUE; kr = port_name_to_semaphore(signal_name, &signal_semaphore); if (kr == KERN_SUCCESS) { kr = port_name_to_semaphore(wait_name, &wait_semaphore); if (kr == KERN_SUCCESS) { kr = semaphore_wait_internal(wait_semaphore, signal_semaphore, &wait_time, caller_cont); semaphore_dereference(wait_semaphore); } semaphore_dereference(signal_semaphore); } return kr; }
kern_return_t semaphore_timedwait_trap_internal( mach_port_name_t name, unsigned int sec, clock_res_t nsec, void (*caller_cont)(kern_return_t)) { semaphore_t semaphore; mach_timespec_t wait_time; kern_return_t kr; wait_time.tv_sec = sec; wait_time.tv_nsec = nsec; if(BAD_MACH_TIMESPEC(&wait_time)) return KERN_INVALID_VALUE; kr = port_name_to_semaphore(name, &semaphore); if (kr == KERN_SUCCESS) { int option = SEMAPHORE_OPTION_NONE; uint64_t deadline = 0; if (sec == 0 && nsec == 0) option = SEMAPHORE_TIMEOUT_NOBLOCK; else deadline = semaphore_deadline(sec, nsec); kr = semaphore_wait_internal(semaphore, SEMAPHORE_NULL, deadline, option, caller_cont); semaphore_dereference(semaphore); } return kr; }
/* * Routine: semaphore_timedwait * * Traditional (non-continuation) interface presented to * in-kernel clients to wait on a semaphore with a timeout. * * A timeout of {0,0} is considered non-blocking. */ kern_return_t semaphore_timedwait( semaphore_t semaphore, mach_timespec_t wait_time) { int option = SEMAPHORE_OPTION_NONE; uint64_t deadline = 0; if (semaphore == SEMAPHORE_NULL) return KERN_INVALID_ARGUMENT; if(BAD_MACH_TIMESPEC(&wait_time)) return KERN_INVALID_VALUE; if (wait_time.tv_sec == 0 && wait_time.tv_nsec == 0) option = SEMAPHORE_TIMEOUT_NOBLOCK; else deadline = semaphore_deadline(wait_time.tv_sec, wait_time.tv_nsec); return (semaphore_wait_internal(semaphore, SEMAPHORE_NULL, deadline, option, (void(*)(kern_return_t))0)); }
/* * Routine: semaphore_timedwait_signal * * Atomically register a wait on a semaphore and THEN signal * another. This is the in-kernel entry point that does not * block at a continuation. * * A timeout of {0,0} is considered non-blocking. */ kern_return_t semaphore_timedwait_signal( semaphore_t wait_semaphore, semaphore_t signal_semaphore, mach_timespec_t wait_time) { if (wait_semaphore == SEMAPHORE_NULL) return KERN_INVALID_ARGUMENT; if(BAD_MACH_TIMESPEC(&wait_time)) return KERN_INVALID_VALUE; return(semaphore_wait_internal(wait_semaphore, signal_semaphore, &wait_time, (void(*)(kern_return_t))0)); }