summaryrefslogtreecommitdiff
path: root/src/atimer.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-08-27 11:47:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-08-27 11:47:55 -0700
commit43aac990c339c0fc3304aa476ebc8ea8467f107e (patch)
tree24f6477d7ec79c7f3529e08c421f309b1180c436 /src/atimer.c
parent278208b8e6917af1e7e2623a3869614fa70059ed (diff)
downloademacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.tar.gz
Simplify EMACS_TIME-related code.
This portability layer is no longer needed, since Emacs has been using struct timespec as a portability layer for some time. Merge from gnulib, incorporating: 2013-08-27 timespec: new convenience constants and function * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h: Include <time.h> rather than "systime.h"; that's all that's needed now. * src/dispnew.c: Include <timespec.h> rather than "systime.h"; that's all that's needed now. * src/systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. (EMACS_TIME_RESOLUTION): Remove. All uses changed to TIMESPEC_RESOLUTION. (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to LOG10_TIMESPEC_RESOLUTION. (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. (EMACS_NSECS): Remove. All uses changed to tv_nsec. (make_emacs_time): Remove. All used changed to make_timespec. (invalid_timespec): Rename from invalid_emacs_time. All uses changed. (current_timespec): Rename from current_emacs_time. All uses changed. (add_emacs_time): Remove. All uses changed to timespec_add. (sub_emacs_time): Remove. All uses change dot timespec_sub. (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. (current_timespec): Rename from current_emacs_time. All uses changed. (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses changed to timespec_cmp. * src/xgselect.c: Include <timespec.h>, since our .h files don't.
Diffstat (limited to 'src/atimer.c')
-rw-r--r--src/atimer.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/atimer.c b/src/atimer.c
index 219b3502acc..6aef71db873 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -94,17 +94,16 @@ static struct atimer *append_atimer_lists (struct atimer *,
to cancel_atimer; don't free it yourself. */
struct atimer *
-start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
- void *client_data)
+start_atimer (enum atimer_type type, struct timespec 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_NSECS (timestamp) != 0
- && EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t))
- timestamp = make_emacs_time (EMACS_SECS (timestamp) + 1, 0);
+ 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
@@ -133,11 +132,11 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
break;
case ATIMER_RELATIVE:
- t->expiration = add_emacs_time (current_emacs_time (), timestamp);
+ t->expiration = timespec_add (current_timespec (), timestamp);
break;
case ATIMER_CONTINUOUS:
- t->expiration = add_emacs_time (current_emacs_time (), timestamp);
+ t->expiration = timespec_add (current_timespec (), timestamp);
t->interval = timestamp;
break;
}
@@ -284,7 +283,7 @@ set_alarm (void)
#ifdef HAVE_SETITIMER
struct itimerval it;
#endif
- EMACS_TIME now, interval;
+ struct timespec now, interval;
#ifdef HAVE_ITIMERSPEC
if (alarm_timer_ok)
@@ -299,10 +298,10 @@ set_alarm (void)
/* 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));
+ now = current_timespec ();
+ interval = (timespec_cmp (atimers->expiration, now) <= 0
+ ? make_timespec (0, 1000 * 1000)
+ : timespec_sub (atimers->expiration, now));
#ifdef HAVE_SETITIMER
@@ -310,7 +309,7 @@ set_alarm (void)
it.it_value = make_timeval (interval);
setitimer (ITIMER_REAL, &it, 0);
#else /* not HAVE_SETITIMER */
- alarm (max (EMACS_SECS (interval), 1));
+ alarm (max (interval.tv_sec, 1));
#endif /* not HAVE_SETITIMER */
}
}
@@ -326,7 +325,7 @@ schedule_atimer (struct atimer *t)
struct atimer *a = atimers, *prev = NULL;
/* Look for the first atimer that is ripe after T. */
- while (a && EMACS_TIME_LT (a->expiration, t->expiration))
+ while (a && timespec_cmp (a->expiration, t->expiration) < 0)
prev = a, a = a->next;
/* Insert T in front of the atimer found, if any. */
@@ -341,9 +340,9 @@ schedule_atimer (struct atimer *t)
static void
run_timers (void)
{
- EMACS_TIME now = current_emacs_time ();
+ struct timespec now = current_timespec ();
- while (atimers && EMACS_TIME_LE (atimers->expiration, now))
+ while (atimers && timespec_cmp (atimers->expiration, now) <= 0)
{
struct atimer *t = atimers;
atimers = atimers->next;
@@ -351,7 +350,7 @@ run_timers (void)
if (t->type == ATIMER_CONTINUOUS)
{
- t->expiration = add_emacs_time (now, t->interval);
+ t->expiration = timespec_add (now, t->interval);
schedule_atimer (t);
}
else