Ejemplo n.º 1
0
kern_return_t		mach_wait_until(
						uint64_t		deadline)
{
	struct timespec ts = { deadline / NSEC_PER_SEC, deadline % NSEC_PER_SEC };
	
do_sleep:
	if (clock_sleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, 0) == -1)
	{
		if (errno == EINTR)
			goto do_sleep;
		return KERN_FAILURE;
	}
	
	return KERN_SUCCESS;
}
Ejemplo n.º 2
0
static void
clock_sleep_ns_abs (guint64 ns_abs)
{
	kern_return_t ret;
	mach_timespec_t then, remain_unused;

	then.tv_sec = ns_abs / 1000000000;
	then.tv_nsec = ns_abs % 1000000000;

	do {
		ret = clock_sleep (sampling_clock_service, TIME_ABSOLUTE, then, &remain_unused);

		if (ret != KERN_SUCCESS && ret != KERN_ABORTED)
			g_error ("%s: clock_sleep () returned %d", __func__, ret);
	} while (ret == KERN_ABORTED && mono_atomic_load_i32 (&sampling_thread_running));
}
Ejemplo n.º 3
0
int
rumpuser_clock_sleep(int enum_rumpclock, int64_t sec, long nsec)
{
	enum rumpclock rclk = enum_rumpclock;
	clockid_t clk;

	switch (rclk) {
	case RUMPUSER_CLOCK_RELWALL:
		clk = CLOCK_REALTIME;
		break;
	case RUMPUSER_CLOCK_ABSMONO:
		clk = CLOCK_MONOTONIC;
		break;
	default:
		return EINVAL;
	}

	return clock_sleep(clk, sec, nsec);
}
Ejemplo n.º 4
0
static void *timer_func(void *arg)
{
	timer_thread = mach_thread_self();
	timer_thread_active = true;
	
	while (timer_thread_active) {
		clock_sleep(system_clock, TIME_ABSOLUTE, wakeup_time, NULL);
		semaphore_wait(wakeup_time_sem);
	   
		tm_time_t system_time;
		
		timer_current_time(system_time);
		if (timer_cmp_time(wakeup_time, system_time) < 0) {
			wakeup_time = wakeup_time_max;
			SetInterruptFlag(INTFLAG_TIMER);
			TriggerInterrupt();
		}
		semaphore_signal(wakeup_time_sem);
	}
    return NULL;
}
Ejemplo n.º 5
0
void
usleep(int useconds)
{
    tvalspec_t inval, outval;
    int seconds;

    /*
     * Make sure we initialized ourselves.
     */
    if (!initialized) {
        host_get_clock_service(mach_host_self(),
                               REALTIME_CLOCK, &clock_port);
        initialized=1;
    }

    /*
     * Sleep for the specified number of microseconds.
     */
    seconds = useconds/USEC_PER_SEC;
    useconds -= seconds*USEC_PER_SEC;
    inval.tv_sec = seconds;
    inval.tv_nsec = useconds*NSEC_PER_USEC;
    clock_sleep(clock_port, TIME_RELATIVE, inval, &outval);
}