make vfs & filesystems use failable copying
[minix3.git] / kernel / system / do_setalarm.c
blobfe065ccbc532cda82bfab408b757be7080c876b4
1 /* The kernel call implemented in this file:
2 * m_type: SYS_SETALARM
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)
8 */
10 #include "kernel/system.h"
12 #include <minix/endpoint.h>
13 #include <assert.h>
15 #if USE_SETALARM
17 static void cause_alarm(minix_timer_t *tp);
19 /*===========================================================================*
20 * do_setalarm *
21 *===========================================================================*/
22 int do_setalarm(struct proc * caller, message * m_ptr)
24 /* A process requests a synchronous alarm, or wants to cancel its alarm. */
25 long exp_time; /* expiration time for this alarm */
26 int use_abs_time; /* use absolute or relative time */
27 minix_timer_t *tp; /* the process' timer structure */
28 clock_t uptime; /* placeholder for current uptime */
30 /* Extract shared parameters from the request message. */
31 exp_time = m_ptr->ALRM_EXP_TIME; /* alarm's expiration time */
32 use_abs_time = m_ptr->ALRM_ABS_TIME; /* flag for absolute time */
33 if (! (priv(caller)->s_flags & SYS_PROC)) return(EPERM);
35 /* Get the timer structure and set the parameters for this alarm. */
36 tp = &(priv(caller)->s_alarm_timer);
37 tmr_arg(tp)->ta_int = caller->p_endpoint;
38 tp->tmr_func = cause_alarm;
40 /* Return the ticks left on the previous alarm. */
41 uptime = get_monotonic();
42 if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) {
43 m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime);
44 } else {
45 m_ptr->ALRM_TIME_LEFT = 0;
48 /* Finally, (re)set the timer depending on the expiration time. */
49 if (exp_time == 0) {
50 reset_kernel_timer(tp);
51 } else {
52 tp->tmr_exp_time = (use_abs_time) ? exp_time : exp_time + get_monotonic();
53 set_kernel_timer(tp, tp->tmr_exp_time, tp->tmr_func);
55 return(OK);
58 /*===========================================================================*
59 * cause_alarm *
60 *===========================================================================*/
61 static void cause_alarm(minix_timer_t *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 endpoint_t 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 */