1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
5 * m2_l1: ALRM_EXP_TIME (alarm's expiration time)
6 * m2_i2: ALRM_ABS_TIME (expiration time is absolute?)
7 * m2_l1: ALRM_TIME_LEFT (return seconds left of previous)
10 #include "../system.h"
12 #include <minix/endpoint.h>
16 FORWARD
_PROTOTYPE( void cause_alarm
, (timer_t
*tp
) );
18 /*===========================================================================*
20 *===========================================================================*/
21 PUBLIC
int do_setalarm(struct proc
* caller
, message
* m_ptr
)
23 /* A process requests a synchronous alarm, or wants to cancel its alarm. */
24 long exp_time
; /* expiration time for this alarm */
25 int use_abs_time
; /* use absolute or relative time */
26 timer_t
*tp
; /* the process' timer structure */
27 clock_t uptime
; /* placeholder for current uptime */
29 /* Extract shared parameters from the request message. */
30 exp_time
= m_ptr
->ALRM_EXP_TIME
; /* alarm's expiration time */
31 use_abs_time
= m_ptr
->ALRM_ABS_TIME
; /* flag for absolute time */
32 if (! (priv(caller
)->s_flags
& SYS_PROC
)) return(EPERM
);
34 /* Get the timer structure and set the parameters for this alarm. */
35 tp
= &(priv(caller
)->s_alarm_timer
);
36 tmr_arg(tp
)->ta_int
= m_ptr
->m_source
;
37 tp
->tmr_func
= cause_alarm
;
39 /* Return the ticks left on the previous alarm. */
40 uptime
= get_uptime();
41 if ((tp
->tmr_exp_time
!= TMR_NEVER
) && (uptime
< tp
->tmr_exp_time
) ) {
42 m_ptr
->ALRM_TIME_LEFT
= (tp
->tmr_exp_time
- uptime
);
44 m_ptr
->ALRM_TIME_LEFT
= 0;
47 /* Finally, (re)set the timer depending on the expiration time. */
51 tp
->tmr_exp_time
= (use_abs_time
) ? exp_time
: exp_time
+ get_uptime();
52 set_timer(tp
, tp
->tmr_exp_time
, tp
->tmr_func
);
57 /*===========================================================================*
59 *===========================================================================*/
60 PRIVATE
void cause_alarm(tp
)
63 /* Routine called if a timer goes off and the process requested a synchronous
64 * alarm. The process number is stored in timer argument 'ta_int'. Notify that
65 * process with a notification message from CLOCK.
67 int proc_nr_e
= tmr_arg(tp
)->ta_int
; /* get process number */
68 mini_notify(proc_addr(CLOCK
), proc_nr_e
); /* notify process */
71 #endif /* USE_SETALARM */