コード例 #1
0
ファイル: timers.c プロジェクト: AgamAgarwal/minix
/*===========================================================================*
 *                              set_timer                                    *
 *===========================================================================*/
void set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
{
        int r;
        clock_t now, prev_time = 0, next_time;

        if ((r = getuptime(&now)) != OK)
                panic("set_timer: couldn't get uptime");

        /* Set timer argument and add timer to the list. */
        tmr_arg(tp)->ta_int = arg;
        prev_time = tmrs_settimer(&timers, tp, now+ticks, watchdog, &next_time);

        /* Reschedule our synchronous alarm if necessary. */
        if (expiring == 0 && (! prev_time || prev_time > next_time)) {
                if (sys_setalarm(next_time, 1) != OK)
                        panic("set_timer: couldn't set alarm");
        }
}
コード例 #2
0
/*
 * Set the timer 'tp' to trigger 'ticks' clock ticks in the future.  When it
 * triggers, call function 'watchdog' with argument 'arg'.  The given timer
 * object must have been initialized with init_timer(3) already.  The given
 * number of ticks must be between 0 and TMRDIFF_MAX inclusive.  A ticks value
 * of zero will cause the alarm to trigger on the next clock tick.  If the
 * timer was already set, it will be canceled first.
 */
void
set_timer(minix_timer_t *tp, clock_t ticks, tmr_func_t watchdog, int arg)
{
	clock_t prev_time, next_time;
	int r, had_timers;

	if (ticks > TMRDIFF_MAX)
		panic("set_timer: ticks value too large: %u", (int)ticks);

	/* Add the timer to the list. */
	had_timers = tmrs_settimer(&timers, tp, getticks() + ticks, watchdog,
	    arg, &prev_time, &next_time);

	/* Reschedule our synchronous alarm if necessary. */
	if (!expiring && (!had_timers || next_time != prev_time)) {
		if ((r = sys_setalarm(next_time, TRUE /*abs_time*/)) != OK)
			panic("set_timer: couldn't set alarm: %d", r);
        }
}
コード例 #3
0
/*===========================================================================*
 *				pm_set_timer				     *
 *===========================================================================*/
PUBLIC void pm_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
{
	int r;
	clock_t now, prev_time = 0, next_time;

	if ((r = getuptime(&now)) != OK)
		panic(__FILE__, "PM couldn't get uptime", NO_NUM);

	/* Set timer argument and add timer to the list. */
	tmr_arg(tp)->ta_int = arg;
	prev_time = tmrs_settimer(&pm_timers,tp,now+ticks,watchdog,&next_time);

	/* Reschedule our synchronous alarm if necessary. */
	if (! prev_time || prev_time > next_time) {
		if (sys_setalarm(next_time, 1) != OK)
			panic(__FILE__, "PM set timer couldn't set alarm.", NO_NUM);
	}

	return;
}