The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kernel/system/do_setalarm.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /* The kernel call implemented in this file:
    2  *   m_type:    SYS_SETALARM 
    3  *
    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  */
    9 
   10 #include "../system.h"
   11 
   12 #if USE_SETALARM
   13 
   14 FORWARD _PROTOTYPE( void cause_alarm, (timer_t *tp) );
   15 
   16 /*===========================================================================*
   17  *                              do_setalarm                                  *
   18  *===========================================================================*/
   19 PUBLIC int do_setalarm(m_ptr)
   20 message *m_ptr;                 /* pointer to request message */
   21 {
   22 /* A process requests a synchronous alarm, or wants to cancel its alarm. */
   23   register struct proc *rp;     /* pointer to requesting process */
   24   int proc_nr;                  /* which process wants the alarm */
   25   long exp_time;                /* expiration time for this alarm */
   26   int use_abs_time;             /* use absolute or relative time */
   27   timer_t *tp;                  /* the process' timer structure */
   28   clock_t uptime;               /* placeholder for current uptime */
   29 
   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   proc_nr = m_ptr->m_source;            /* process to interrupt later */
   34   rp = proc_addr(proc_nr);
   35   if (! (priv(rp)->s_flags & SYS_PROC)) return(EPERM);
   36 
   37   /* Get the timer structure and set the parameters for this alarm. */
   38   tp = &(priv(rp)->s_alarm_timer);      
   39   tmr_arg(tp)->ta_int = proc_nr;        
   40   tp->tmr_func = cause_alarm; 
   41 
   42   /* Return the ticks left on the previous alarm. */
   43   uptime = get_uptime(); 
   44   if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) {
   45       m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime);
   46   } else {
   47       m_ptr->ALRM_TIME_LEFT = 0;
   48   }
   49 
   50   /* Finally, (re)set the timer depending on the expiration time. */
   51   if (exp_time == 0) {
   52       reset_timer(tp);
   53   } else {
   54       tp->tmr_exp_time = (use_abs_time) ? exp_time : exp_time + get_uptime();
   55       set_timer(tp, tp->tmr_exp_time, tp->tmr_func);
   56   }
   57   return(OK);
   58 }
   59 
   60 /*===========================================================================*
   61  *                              cause_alarm                                  *
   62  *===========================================================================*/
   63 PRIVATE void cause_alarm(tp)
   64 timer_t *tp;
   65 {
   66 /* Routine called if a timer goes off and the process requested a synchronous
   67  * alarm. The process number is stored in timer argument 'ta_int'. Notify that
   68  * process with a notification message from CLOCK.
   69  */
   70   int proc_nr = tmr_arg(tp)->ta_int;            /* get process number */
   71   lock_notify(CLOCK, proc_nr);                  /* notify process */
   72 }
   73 
   74 #endif /* USE_SETALARM */

Cache object: 56fcac80a980d491fff36087e2331180


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.