static void run_timers (void) { struct timespec now = current_timespec (); while (atimers && timespec_cmp (atimers->expiration, now) <= 0) { struct atimer *t = atimers; atimers = atimers->next; t->fn (t); if (t->type == ATIMER_CONTINUOUS) { t->expiration = timespec_add (now, t->interval); schedule_atimer (t); } else { t->next = free_atimers; free_atimers = t; } } set_alarm (); }
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 (); }
struct atimer * start_atimer (enum atimer_type type, struct timespec timestamp, atimer_callback fn, void *client_data) { struct atimer *t; sigset_t oldset; /* Round TIME up to the next full second if we don't have itimers. */ #ifndef HAVE_SETITIMER if (timestamp.tv_nsec != 0 && timestamp.tv_sec < TYPE_MAXIMUM (time_t)) timestamp = make_timespec (timestamp.tv_sec + 1, 0); #endif /* not HAVE_SETITIMER */ /* Get an atimer structure from the free-list, or allocate a new one. */ if (free_atimers) { t = free_atimers; free_atimers = t->next; } else t = xmalloc (sizeof *t); /* Fill the atimer structure. */ memset (t, 0, sizeof *t); t->type = type; t->fn = fn; t->client_data = client_data; block_atimers (&oldset); /* Compute the timer's expiration time. */ switch (type) { case ATIMER_ABSOLUTE: t->expiration = timestamp; break; case ATIMER_RELATIVE: t->expiration = timespec_add (current_timespec (), timestamp); break; case ATIMER_CONTINUOUS: t->expiration = timespec_add (current_timespec (), timestamp); t->interval = timestamp; break; } /* Insert the timer in the list of active atimers. */ schedule_atimer (t); unblock_atimers (&oldset); /* Arrange for a SIGALRM at the time the next atimer is ripe. */ set_alarm (); return t; }
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 }
static void run_all_atimers (void) { if (stopped_atimers) { struct atimer *t = atimers; struct atimer *next; BLOCK_ATIMERS; atimers = stopped_atimers; stopped_atimers = NULL; while (t) { next = t->next; schedule_atimer (t); t = next; } UNBLOCK_ATIMERS; } }
void run_all_atimers (void) { if (stopped_atimers) { struct atimer *t = atimers; struct atimer *next; block_atimers (); atimers = stopped_atimers; stopped_atimers = NULL; while (t) { next = t->next; schedule_atimer (t); t = next; } unblock_atimers (); } }
struct atimer * start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn, void *client_data) { struct atimer *t; /* Round TIME up to the next full second if we don't have itimers. */ #ifndef HAVE_SETITIMER if (EMACS_USECS (timestamp) != 0) { EMACS_SET_USECS (timestamp, 0); EMACS_SET_SECS (timestamp, EMACS_SECS (timestamp) + 1); } #endif /* not HAVE_SETITIMER */ /* Get an atimer structure from the free-list, or allocate a new one. */ if (free_atimers) { t = free_atimers; free_atimers = t->next; } else t = (struct atimer *) xmalloc (sizeof *t); /* Fill the atimer structure. */ memset (t, 0, sizeof *t); t->type = type; t->fn = fn; t->client_data = client_data; BLOCK_ATIMERS; /* Compute the timer's expiration time. */ switch (type) { case ATIMER_ABSOLUTE: t->expiration = timestamp; break; case ATIMER_RELATIVE: EMACS_GET_TIME (t->expiration); EMACS_ADD_TIME (t->expiration, t->expiration, timestamp); break; case ATIMER_CONTINUOUS: EMACS_GET_TIME (t->expiration); EMACS_ADD_TIME (t->expiration, t->expiration, timestamp); t->interval = timestamp; break; } /* Insert the timer in the list of active atimers. */ schedule_atimer (t); UNBLOCK_ATIMERS; /* Arrange for a SIGALRM at the time the next atimer is ripe. */ set_alarm (); return t; }