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/sysdep.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/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 0d732526528..e43991f41ab 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -306,7 +306,7 @@ get_child_status (pid_t child, int *status, int options, bool interruptible) | |||
| 306 | /* If successful and status is requested, tell wait_reading_process_output | 306 | /* If successful and status is requested, tell wait_reading_process_output |
| 307 | that it needs to wake up and look around. */ | 307 | that it needs to wake up and look around. */ |
| 308 | if (pid && status && input_available_clear_time) | 308 | if (pid && status && input_available_clear_time) |
| 309 | *input_available_clear_time = make_emacs_time (0, 0); | 309 | *input_available_clear_time = make_timespec (0, 0); |
| 310 | 310 | ||
| 311 | return pid; | 311 | return pid; |
| 312 | } | 312 | } |
| @@ -2021,8 +2021,8 @@ seed_random (void *seed, ptrdiff_t seed_size) | |||
| 2021 | void | 2021 | void |
| 2022 | init_random (void) | 2022 | init_random (void) |
| 2023 | { | 2023 | { |
| 2024 | EMACS_TIME t = current_emacs_time (); | 2024 | struct timespec t = current_timespec (); |
| 2025 | uintmax_t v = getpid () ^ EMACS_SECS (t) ^ EMACS_NSECS (t); | 2025 | uintmax_t v = getpid () ^ t.tv_sec ^ t.tv_nsec; |
| 2026 | seed_random (&v, sizeof v); | 2026 | seed_random (&v, sizeof v); |
| 2027 | } | 2027 | } |
| 2028 | 2028 | ||
| @@ -2357,7 +2357,7 @@ emacs_perror (char const *message) | |||
| 2357 | Use the least timeval not less than T. | 2357 | Use the least timeval not less than T. |
| 2358 | Return an extremal value if the result would overflow. */ | 2358 | Return an extremal value if the result would overflow. */ |
| 2359 | struct timeval | 2359 | struct timeval |
| 2360 | make_timeval (EMACS_TIME t) | 2360 | make_timeval (struct timespec t) |
| 2361 | { | 2361 | { |
| 2362 | struct timeval tv; | 2362 | struct timeval tv; |
| 2363 | tv.tv_sec = t.tv_sec; | 2363 | tv.tv_sec = t.tv_sec; |
| @@ -2384,7 +2384,7 @@ make_timeval (EMACS_TIME t) | |||
| 2384 | If FD is nonnegative, then FILE can be NULL. */ | 2384 | If FD is nonnegative, then FILE can be NULL. */ |
| 2385 | int | 2385 | int |
| 2386 | set_file_times (int fd, const char *filename, | 2386 | set_file_times (int fd, const char *filename, |
| 2387 | EMACS_TIME atime, EMACS_TIME mtime) | 2387 | struct timespec atime, struct timespec mtime) |
| 2388 | { | 2388 | { |
| 2389 | struct timespec timespec[2]; | 2389 | struct timespec timespec[2]; |
| 2390 | timespec[0] = atime; | 2390 | timespec[0] = atime; |
| @@ -2701,7 +2701,7 @@ list_system_processes (void) | |||
| 2701 | #endif /* !defined (WINDOWSNT) */ | 2701 | #endif /* !defined (WINDOWSNT) */ |
| 2702 | 2702 | ||
| 2703 | #if defined GNU_LINUX && defined HAVE_LONG_LONG_INT | 2703 | #if defined GNU_LINUX && defined HAVE_LONG_LONG_INT |
| 2704 | static EMACS_TIME | 2704 | static struct timespec |
| 2705 | time_from_jiffies (unsigned long long tval, long hz) | 2705 | time_from_jiffies (unsigned long long tval, long hz) |
| 2706 | { | 2706 | { |
| 2707 | unsigned long long s = tval / hz; | 2707 | unsigned long long s = tval / hz; |
| @@ -2710,34 +2710,34 @@ time_from_jiffies (unsigned long long tval, long hz) | |||
| 2710 | 2710 | ||
| 2711 | if (TYPE_MAXIMUM (time_t) < s) | 2711 | if (TYPE_MAXIMUM (time_t) < s) |
| 2712 | time_overflow (); | 2712 | time_overflow (); |
| 2713 | if (LONG_MAX - 1 <= ULLONG_MAX / EMACS_TIME_RESOLUTION | 2713 | if (LONG_MAX - 1 <= ULLONG_MAX / TIMESPEC_RESOLUTION |
| 2714 | || frac <= ULLONG_MAX / EMACS_TIME_RESOLUTION) | 2714 | || frac <= ULLONG_MAX / TIMESPEC_RESOLUTION) |
| 2715 | ns = frac * EMACS_TIME_RESOLUTION / hz; | 2715 | ns = frac * TIMESPEC_RESOLUTION / hz; |
| 2716 | else | 2716 | else |
| 2717 | { | 2717 | { |
| 2718 | /* This is reachable only in the unlikely case that HZ * HZ | 2718 | /* This is reachable only in the unlikely case that HZ * HZ |
| 2719 | exceeds ULLONG_MAX. It calculates an approximation that is | 2719 | exceeds ULLONG_MAX. It calculates an approximation that is |
| 2720 | guaranteed to be in range. */ | 2720 | guaranteed to be in range. */ |
| 2721 | long hz_per_ns = (hz / EMACS_TIME_RESOLUTION | 2721 | long hz_per_ns = (hz / TIMESPEC_RESOLUTION |
| 2722 | + (hz % EMACS_TIME_RESOLUTION != 0)); | 2722 | + (hz % TIMESPEC_RESOLUTION != 0)); |
| 2723 | ns = frac / hz_per_ns; | 2723 | ns = frac / hz_per_ns; |
| 2724 | } | 2724 | } |
| 2725 | 2725 | ||
| 2726 | return make_emacs_time (s, ns); | 2726 | return make_timespec (s, ns); |
| 2727 | } | 2727 | } |
| 2728 | 2728 | ||
| 2729 | static Lisp_Object | 2729 | static Lisp_Object |
| 2730 | ltime_from_jiffies (unsigned long long tval, long hz) | 2730 | ltime_from_jiffies (unsigned long long tval, long hz) |
| 2731 | { | 2731 | { |
| 2732 | EMACS_TIME t = time_from_jiffies (tval, hz); | 2732 | struct timespec t = time_from_jiffies (tval, hz); |
| 2733 | return make_lisp_time (t); | 2733 | return make_lisp_time (t); |
| 2734 | } | 2734 | } |
| 2735 | 2735 | ||
| 2736 | static EMACS_TIME | 2736 | static struct timespec |
| 2737 | get_up_time (void) | 2737 | get_up_time (void) |
| 2738 | { | 2738 | { |
| 2739 | FILE *fup; | 2739 | FILE *fup; |
| 2740 | EMACS_TIME up = make_emacs_time (0, 0); | 2740 | struct timespec up = make_timespec (0, 0); |
| 2741 | 2741 | ||
| 2742 | block_input (); | 2742 | block_input (); |
| 2743 | fup = emacs_fopen ("/proc/uptime", "r"); | 2743 | fup = emacs_fopen ("/proc/uptime", "r"); |
| @@ -2755,18 +2755,18 @@ get_up_time (void) | |||
| 2755 | if (TYPE_MAXIMUM (time_t) < upsec) | 2755 | if (TYPE_MAXIMUM (time_t) < upsec) |
| 2756 | { | 2756 | { |
| 2757 | upsec = TYPE_MAXIMUM (time_t); | 2757 | upsec = TYPE_MAXIMUM (time_t); |
| 2758 | upfrac = EMACS_TIME_RESOLUTION - 1; | 2758 | upfrac = TIMESPEC_RESOLUTION - 1; |
| 2759 | } | 2759 | } |
| 2760 | else | 2760 | else |
| 2761 | { | 2761 | { |
| 2762 | int upfraclen = upfrac_end - upfrac_start; | 2762 | int upfraclen = upfrac_end - upfrac_start; |
| 2763 | for (; upfraclen < LOG10_EMACS_TIME_RESOLUTION; upfraclen++) | 2763 | for (; upfraclen < LOG10_TIMESPEC_RESOLUTION; upfraclen++) |
| 2764 | upfrac *= 10; | 2764 | upfrac *= 10; |
| 2765 | for (; LOG10_EMACS_TIME_RESOLUTION < upfraclen; upfraclen--) | 2765 | for (; LOG10_TIMESPEC_RESOLUTION < upfraclen; upfraclen--) |
| 2766 | upfrac /= 10; | 2766 | upfrac /= 10; |
| 2767 | upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1); | 2767 | upfrac = min (upfrac, TIMESPEC_RESOLUTION - 1); |
| 2768 | } | 2768 | } |
| 2769 | up = make_emacs_time (upsec, upfrac); | 2769 | up = make_timespec (upsec, upfrac); |
| 2770 | } | 2770 | } |
| 2771 | fclose (fup); | 2771 | fclose (fup); |
| 2772 | } | 2772 | } |
| @@ -2887,7 +2887,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 2887 | unsigned long long u_time, s_time, cutime, cstime, start; | 2887 | unsigned long long u_time, s_time, cutime, cstime, start; |
| 2888 | long priority, niceness, rss; | 2888 | long priority, niceness, rss; |
| 2889 | unsigned long minflt, majflt, cminflt, cmajflt, vsize; | 2889 | unsigned long minflt, majflt, cminflt, cmajflt, vsize; |
| 2890 | EMACS_TIME tnow, tstart, tboot, telapsed, us_time; | 2890 | struct timespec tnow, tstart, tboot, telapsed, us_time; |
| 2891 | double pcpu, pmem; | 2891 | double pcpu, pmem; |
| 2892 | Lisp_Object attrs = Qnil; | 2892 | Lisp_Object attrs = Qnil; |
| 2893 | Lisp_Object cmd_str, decoded_cmd; | 2893 | Lisp_Object cmd_str, decoded_cmd; |
| @@ -3008,20 +3008,19 @@ system_process_attributes (Lisp_Object pid) | |||
| 3008 | attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs); | 3008 | attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs); |
| 3009 | attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount)), | 3009 | attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount)), |
| 3010 | attrs); | 3010 | attrs); |
| 3011 | tnow = current_emacs_time (); | 3011 | tnow = current_timespec (); |
| 3012 | telapsed = get_up_time (); | 3012 | telapsed = get_up_time (); |
| 3013 | tboot = sub_emacs_time (tnow, telapsed); | 3013 | tboot = timespec_sub (tnow, telapsed); |
| 3014 | tstart = time_from_jiffies (start, clocks_per_sec); | 3014 | tstart = time_from_jiffies (start, clocks_per_sec); |
| 3015 | tstart = add_emacs_time (tboot, tstart); | 3015 | tstart = timespec_add (tboot, tstart); |
| 3016 | attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs); | 3016 | attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs); |
| 3017 | attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize / 1024)), | 3017 | attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize / 1024)), |
| 3018 | attrs); | 3018 | attrs); |
| 3019 | attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4 * rss)), attrs); | 3019 | attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4 * rss)), attrs); |
| 3020 | telapsed = sub_emacs_time (tnow, tstart); | 3020 | telapsed = timespec_sub (tnow, tstart); |
| 3021 | attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs); | 3021 | attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs); |
| 3022 | us_time = time_from_jiffies (u_time + s_time, clocks_per_sec); | 3022 | us_time = time_from_jiffies (u_time + s_time, clocks_per_sec); |
| 3023 | pcpu = (EMACS_TIME_TO_DOUBLE (us_time) | 3023 | pcpu = timespectod (us_time) / timespectod (telapsed); |
| 3024 | / EMACS_TIME_TO_DOUBLE (telapsed)); | ||
| 3025 | if (pcpu > 1.0) | 3024 | if (pcpu > 1.0) |
| 3026 | pcpu = 1.0; | 3025 | pcpu = 1.0; |
| 3027 | attrs = Fcons (Fcons (Qpcpu, make_float (100 * pcpu)), attrs); | 3026 | attrs = Fcons (Fcons (Qpcpu, make_float (100 * pcpu)), attrs); |
| @@ -3239,16 +3238,16 @@ system_process_attributes (Lisp_Object pid) | |||
| 3239 | 3238 | ||
| 3240 | #elif defined __FreeBSD__ | 3239 | #elif defined __FreeBSD__ |
| 3241 | 3240 | ||
| 3242 | static EMACS_TIME | 3241 | static struct timespec |
| 3243 | timeval_to_EMACS_TIME (struct timeval t) | 3242 | timeval_to_timespec (struct timeval t) |
| 3244 | { | 3243 | { |
| 3245 | return make_emacs_time (t.tv_sec, t.tv_usec * 1000); | 3244 | return make_timespec (t.tv_sec, t.tv_usec * 1000); |
| 3246 | } | 3245 | } |
| 3247 | 3246 | ||
| 3248 | static Lisp_Object | 3247 | static Lisp_Object |
| 3249 | make_lisp_timeval (struct timeval t) | 3248 | make_lisp_timeval (struct timeval t) |
| 3250 | { | 3249 | { |
| 3251 | return make_lisp_time (timeval_to_EMACS_TIME (t)); | 3250 | return make_lisp_time (timeval_to_timespec (t)); |
| 3252 | } | 3251 | } |
| 3253 | 3252 | ||
| 3254 | Lisp_Object | 3253 | Lisp_Object |
| @@ -3263,7 +3262,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 3263 | char *ttyname; | 3262 | char *ttyname; |
| 3264 | size_t len; | 3263 | size_t len; |
| 3265 | char args[MAXPATHLEN]; | 3264 | char args[MAXPATHLEN]; |
| 3266 | EMACS_TIME t, now; | 3265 | struct timespec t, now; |
| 3267 | 3266 | ||
| 3268 | int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; | 3267 | int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; |
| 3269 | struct kinfo_proc proc; | 3268 | struct kinfo_proc proc; |
| @@ -3350,8 +3349,8 @@ system_process_attributes (Lisp_Object pid) | |||
| 3350 | attrs); | 3349 | attrs); |
| 3351 | attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)), | 3350 | attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)), |
| 3352 | attrs); | 3351 | attrs); |
| 3353 | t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime), | 3352 | t = timespec_add (timeval_to_timespec (proc.ki_rusage.ru_utime), |
| 3354 | timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime)); | 3353 | timeval_to_timespec (proc.ki_rusage.ru_stime)); |
| 3355 | attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); | 3354 | attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); |
| 3356 | 3355 | ||
| 3357 | attrs = Fcons (Fcons (Qcutime, | 3356 | attrs = Fcons (Fcons (Qcutime, |
| @@ -3360,8 +3359,8 @@ system_process_attributes (Lisp_Object pid) | |||
| 3360 | attrs = Fcons (Fcons (Qcstime, | 3359 | attrs = Fcons (Fcons (Qcstime, |
| 3361 | make_lisp_timeval (proc.ki_rusage_ch.ru_utime)), | 3360 | make_lisp_timeval (proc.ki_rusage_ch.ru_utime)), |
| 3362 | attrs); | 3361 | attrs); |
| 3363 | t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime), | 3362 | t = timespec_add (timeval_to_timespec (proc.ki_rusage_ch.ru_utime), |
| 3364 | timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime)); | 3363 | timeval_to_timespec (proc.ki_rusage_ch.ru_stime)); |
| 3365 | attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs); | 3364 | attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs); |
| 3366 | 3365 | ||
| 3367 | attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)), | 3366 | attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)), |
| @@ -3373,8 +3372,8 @@ system_process_attributes (Lisp_Object pid) | |||
| 3373 | attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)), | 3372 | attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)), |
| 3374 | attrs); | 3373 | attrs); |
| 3375 | 3374 | ||
| 3376 | now = current_emacs_time (); | 3375 | now = current_timespec (); |
| 3377 | t = sub_emacs_time (now, timeval_to_EMACS_TIME (proc.ki_start)); | 3376 | t = timespec_sub (now, timeval_to_timespec (proc.ki_start)); |
| 3378 | attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); | 3377 | attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); |
| 3379 | 3378 | ||
| 3380 | len = sizeof fscale; | 3379 | len = sizeof fscale; |