Exemplo n.º 1
0
static void
run_timers (void)
{
  EMACS_TIME now = current_emacs_time ();

  while (atimers && EMACS_TIME_LE (atimers->expiration, now))
    {
      struct atimer *t = atimers;
      atimers = atimers->next;
      t->fn (t);

      if (t->type == ATIMER_CONTINUOUS)
	{
	  t->expiration = add_emacs_time (now, t->interval);
	  schedule_atimer (t);
	}
      else
	{
	  t->next = free_atimers;
	  free_atimers = t;
	}
    }

  set_alarm ();
}
Exemplo n.º 2
0
static void
set_alarm (void)
{
  if (atimers)
    {
      EMACS_TIME now, timestamp;
#ifdef HAVE_SETITIMER
      struct itimerval it;
#endif

      /* Determine s/us till the next timer is ripe.  */
      EMACS_GET_TIME (now);
      EMACS_SUB_TIME (timestamp, atimers->expiration, now);

#ifdef HAVE_SETITIMER
      /* Don't set the interval to 0; this disables the timer.  */
      if (EMACS_TIME_LE (atimers->expiration, now))
	{
	  EMACS_SET_SECS (timestamp, 0);
	  EMACS_SET_USECS (timestamp, 1000);
	}

      memset (&it, 0, sizeof it);
      it.it_value = timestamp;
      setitimer (ITIMER_REAL, &it, 0);
#else /* not HAVE_SETITIMER */
      alarm (max (EMACS_SECS (timestamp), 1));
#endif /* not HAVE_SETITIMER */
    }
}
Exemplo n.º 3
0
static void
run_timers (void)
{
  EMACS_TIME now;

  EMACS_GET_TIME (now);

  while (atimers
	 && (pending_atimers = interrupt_input_blocked) == 0
	 && EMACS_TIME_LE (atimers->expiration, now))
    {
      struct atimer *t;

      t = atimers;
      atimers = atimers->next;
#ifndef DARWIN_OS
      t->fn (t);
#endif

      if (t->type == ATIMER_CONTINUOUS)
	{
	  EMACS_ADD_TIME (t->expiration, now, t->interval);
	  schedule_atimer (t);
	}
      else
	{
	  t->next = free_atimers;
	  free_atimers = t;
	}
#ifdef DARWIN_OS
      /* Fix for Ctrl-G.  Perhaps this should apply to all platforms. */
      t->fn (t); 
#endif

      EMACS_GET_TIME (now);
    }

  if (! atimers)
    pending_atimers = 0;

#ifdef SYNC_INPUT
  if (pending_atimers)
    pending_signals = 1;
  else
    {
      pending_signals = interrupt_input_pending;
      set_alarm ();
    }
#else
  if (! pending_atimers)
    set_alarm ();
#endif
}
Exemplo n.º 4
0
static void
set_alarm (void)
{
  if (atimers)
    {
#ifdef HAVE_SETITIMER
      struct itimerval it;
#endif
      EMACS_TIME now, interval;

#ifdef HAVE_ITIMERSPEC
      if (alarm_timer_ok)
	{
	  struct itimerspec ispec;
	  ispec.it_value = atimers->expiration;
	  ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0;
	  if (timer_settime (alarm_timer, 0, &ispec, 0) == 0)
	    return;
	}
#endif

      /* Determine interval till the next timer is ripe.
	 Don't set the interval to 0; this disables the timer.  */
      now = current_emacs_time ();
      interval = (EMACS_TIME_LE (atimers->expiration, now)
		  ? make_emacs_time (0, 1000 * 1000)
		  : sub_emacs_time (atimers->expiration, now));

#ifdef HAVE_SETITIMER

      memset (&it, 0, sizeof it);
      it.it_value = make_timeval (interval);
      setitimer (ITIMER_REAL, &it, 0);
#else /* not HAVE_SETITIMER */
      alarm (max (EMACS_SECS (interval), 1));
#endif /* not HAVE_SETITIMER */
    }
}