diff options
| author | Paul Eggert | 2013-08-27 11:47:55 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-27 11:47:55 -0700 |
| commit | 43aac990c339c0fc3304aa476ebc8ea8467f107e (patch) | |
| tree | 24f6477d7ec79c7f3529e08c421f309b1180c436 /src/atimer.c | |
| parent | 278208b8e6917af1e7e2623a3869614fa70059ed (diff) | |
| download | emacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.tar.gz emacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.zip | |
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.c | 33 |
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 *, | |||
| 94 | to cancel_atimer; don't free it yourself. */ | 94 | to cancel_atimer; don't free it yourself. */ |
| 95 | 95 | ||
| 96 | struct atimer * | 96 | struct atimer * |
| 97 | start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn, | 97 | start_atimer (enum atimer_type type, struct timespec timestamp, |
| 98 | void *client_data) | 98 | atimer_callback fn, void *client_data) |
| 99 | { | 99 | { |
| 100 | struct atimer *t; | 100 | struct atimer *t; |
| 101 | 101 | ||
| 102 | /* Round TIME up to the next full second if we don't have | 102 | /* Round TIME up to the next full second if we don't have |
| 103 | itimers. */ | 103 | itimers. */ |
| 104 | #ifndef HAVE_SETITIMER | 104 | #ifndef HAVE_SETITIMER |
| 105 | if (EMACS_NSECS (timestamp) != 0 | 105 | if (timestamp.tv_nsec != 0 && timestamp.tv_sec < TYPE_MAXIMUM (time_t)) |
| 106 | && EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t)) | 106 | timestamp = make_timespec (timestamp.tv_sec + 1, 0); |
| 107 | timestamp = make_emacs_time (EMACS_SECS (timestamp) + 1, 0); | ||
| 108 | #endif /* not HAVE_SETITIMER */ | 107 | #endif /* not HAVE_SETITIMER */ |
| 109 | 108 | ||
| 110 | /* Get an atimer structure from the free-list, or allocate | 109 | /* 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, | |||
| 133 | break; | 132 | break; |
| 134 | 133 | ||
| 135 | case ATIMER_RELATIVE: | 134 | case ATIMER_RELATIVE: |
| 136 | t->expiration = add_emacs_time (current_emacs_time (), timestamp); | 135 | t->expiration = timespec_add (current_timespec (), timestamp); |
| 137 | break; | 136 | break; |
| 138 | 137 | ||
| 139 | case ATIMER_CONTINUOUS: | 138 | case ATIMER_CONTINUOUS: |
| 140 | t->expiration = add_emacs_time (current_emacs_time (), timestamp); | 139 | t->expiration = timespec_add (current_timespec (), timestamp); |
| 141 | t->interval = timestamp; | 140 | t->interval = timestamp; |
| 142 | break; | 141 | break; |
| 143 | } | 142 | } |
| @@ -284,7 +283,7 @@ set_alarm (void) | |||
| 284 | #ifdef HAVE_SETITIMER | 283 | #ifdef HAVE_SETITIMER |
| 285 | struct itimerval it; | 284 | struct itimerval it; |
| 286 | #endif | 285 | #endif |
| 287 | EMACS_TIME now, interval; | 286 | struct timespec now, interval; |
| 288 | 287 | ||
| 289 | #ifdef HAVE_ITIMERSPEC | 288 | #ifdef HAVE_ITIMERSPEC |
| 290 | if (alarm_timer_ok) | 289 | if (alarm_timer_ok) |
| @@ -299,10 +298,10 @@ set_alarm (void) | |||
| 299 | 298 | ||
| 300 | /* Determine interval till the next timer is ripe. | 299 | /* Determine interval till the next timer is ripe. |
| 301 | Don't set the interval to 0; this disables the timer. */ | 300 | Don't set the interval to 0; this disables the timer. */ |
| 302 | now = current_emacs_time (); | 301 | now = current_timespec (); |
| 303 | interval = (EMACS_TIME_LE (atimers->expiration, now) | 302 | interval = (timespec_cmp (atimers->expiration, now) <= 0 |
| 304 | ? make_emacs_time (0, 1000 * 1000) | 303 | ? make_timespec (0, 1000 * 1000) |
| 305 | : sub_emacs_time (atimers->expiration, now)); | 304 | : timespec_sub (atimers->expiration, now)); |
| 306 | 305 | ||
| 307 | #ifdef HAVE_SETITIMER | 306 | #ifdef HAVE_SETITIMER |
| 308 | 307 | ||
| @@ -310,7 +309,7 @@ set_alarm (void) | |||
| 310 | it.it_value = make_timeval (interval); | 309 | it.it_value = make_timeval (interval); |
| 311 | setitimer (ITIMER_REAL, &it, 0); | 310 | setitimer (ITIMER_REAL, &it, 0); |
| 312 | #else /* not HAVE_SETITIMER */ | 311 | #else /* not HAVE_SETITIMER */ |
| 313 | alarm (max (EMACS_SECS (interval), 1)); | 312 | alarm (max (interval.tv_sec, 1)); |
| 314 | #endif /* not HAVE_SETITIMER */ | 313 | #endif /* not HAVE_SETITIMER */ |
| 315 | } | 314 | } |
| 316 | } | 315 | } |
| @@ -326,7 +325,7 @@ schedule_atimer (struct atimer *t) | |||
| 326 | struct atimer *a = atimers, *prev = NULL; | 325 | struct atimer *a = atimers, *prev = NULL; |
| 327 | 326 | ||
| 328 | /* Look for the first atimer that is ripe after T. */ | 327 | /* Look for the first atimer that is ripe after T. */ |
| 329 | while (a && EMACS_TIME_LT (a->expiration, t->expiration)) | 328 | while (a && timespec_cmp (a->expiration, t->expiration) < 0) |
| 330 | prev = a, a = a->next; | 329 | prev = a, a = a->next; |
| 331 | 330 | ||
| 332 | /* Insert T in front of the atimer found, if any. */ | 331 | /* Insert T in front of the atimer found, if any. */ |
| @@ -341,9 +340,9 @@ schedule_atimer (struct atimer *t) | |||
| 341 | static void | 340 | static void |
| 342 | run_timers (void) | 341 | run_timers (void) |
| 343 | { | 342 | { |
| 344 | EMACS_TIME now = current_emacs_time (); | 343 | struct timespec now = current_timespec (); |
| 345 | 344 | ||
| 346 | while (atimers && EMACS_TIME_LE (atimers->expiration, now)) | 345 | while (atimers && timespec_cmp (atimers->expiration, now) <= 0) |
| 347 | { | 346 | { |
| 348 | struct atimer *t = atimers; | 347 | struct atimer *t = atimers; |
| 349 | atimers = atimers->next; | 348 | atimers = atimers->next; |
| @@ -351,7 +350,7 @@ run_timers (void) | |||
| 351 | 350 | ||
| 352 | if (t->type == ATIMER_CONTINUOUS) | 351 | if (t->type == ATIMER_CONTINUOUS) |
| 353 | { | 352 | { |
| 354 | t->expiration = add_emacs_time (now, t->interval); | 353 | t->expiration = timespec_add (now, t->interval); |
| 355 | schedule_atimer (t); | 354 | schedule_atimer (t); |
| 356 | } | 355 | } |
| 357 | else | 356 | else |