Back to index

glibc  2.9
Functions | Variables
getitimer.c File Reference
#include <stddef.h>
#include <errno.h>
#include <sys/time.h>
#include <hurd.h>

Go to the source code of this file.


static void subtract_timeval (struct timeval *from, const struct timeval *subtract)
int __getitimer (enum __itimer_which which, struct itimerval *value)


spin_lock_t _hurd_itimer_lock

Function Documentation

int __getitimer ( enum __itimer_which  which,
struct itimerval value 

Definition at line 46 of file getitimer.c.

  struct itimerval val;
  struct timeval elapsed;

  switch (which)
      return __hurd_fail (EINVAL);

    case ITIMER_PROF:
      return __hurd_fail (ENOSYS);

    case ITIMER_REAL:

  /* Get the time now.  */
  if (__gettimeofday (&elapsed, NULL) < 0)
    return -1;

  /* Extract the current timer setting; and the time it was set, so we can
     calculate the time elapsed so far.  */
  __spin_lock (&_hurd_itimer_lock);
  val = _hurd_itimerval;
  subtract_timeval (&elapsed, &_hurd_itimer_started);
  __spin_unlock (&_hurd_itimer_lock);

  if ((val.it_value.tv_sec | val.it_value.tv_usec) != 0)
      /* There is a pending alarm set.  VAL indicates the interval it was
        set for, relative to the time recorded in _hurd_itimer_started.
        Now compensate for the time elapsed since to get the user's
        conception of the current value of the timer (as if the value
        stored decreased every microsecond).  */
      if (timercmp (&val.it_value, &elapsed, <))
         /* Hmm.  The timer should have just gone off, but has not been
            reset.  This is a possible timing glitch.  The alarm will signal
            soon, so fabricate a value for how soon.  */
         val.it_value.tv_sec = 0;
         val.it_value.tv_usec = 10; /* Random.  */
       /* Subtract the time elapsed since the timer was set
          from the current timer value the user sees.  */
       subtract_timeval (&val.it_value, &elapsed);

  *value = val;
  return 0;

Here is the call graph for this function:

static void subtract_timeval ( struct timeval from,
const struct timeval subtract 
) [inline, static]

Definition at line 32 of file getitimer.c.

  from->tv_usec -= subtract->tv_usec;
  from->tv_sec -= subtract->tv_sec;
  while (from->tv_usec < 0)
      from->tv_usec += 1000000;

Here is the caller graph for this function:

Variable Documentation

Definition at line 32 of file setitimer.c.