aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-10 16:24:36 -0700
committerPaul Eggert2012-07-10 16:24:36 -0700
commite9a9ae0350689d352c2bdfa3af0eb722f587b966 (patch)
tree10ed0298079b06838a525f0a4df780d7600e13fe /src/sysdep.c
parentffacb12679a1e001981c2e0f690b327eda652d04 (diff)
downloademacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.tar.gz
emacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.zip
EMACS_TIME simplification (Bug#11875).
This replaces macros (which typically do not work in GDB) with functions, typedefs and enums, making the code easier to debug. The functional style also makes code easier to read and maintain. * lib-src/profile.c (TV2): Remove no-longer-needed static var. * src/systime.h: Include <sys/time.h> on all hosts, not just if WINDOWSNT, since 'struct timeval' is needed in general. (EMACS_TIME): Now a typedef, not a macro. (EMACS_TIME_RESOLUTION, LOG10_EMACS_TIME_RESOLUTION): Now constants, not macros. (EMACS_SECS, EMACS_NSECS, EMACS_TIME_SIGN, EMACS_TIME_VALID_P) (EMACS_TIME_FROM_DOUBLE, EMACS_TIME_TO_DOUBLE, EMACS_TIME_EQ) (EMACS_TIME_NE, EMACS_TIME_GT, EMACS_TIME_GE, EMACS_TIME_LT) (EMACS_TIME_LE): Now functions, not macros. (EMACS_SET_SECS, EMACS_SET_NSECS, EMACS_SET_SECS_NSECS) (EMACS_SET_USECS, EMACS_SET_SECS_USECS): Remove these macros, which are not functions. All uses rewritten to use: (make_emacs_time): New function. (EMACS_SECS_ADDR, EMACS_SET_INVALID_TIME, EMACS_GET_TIME) (EMACS_ADD_TIME, EMACS_SUB_TIME): Remove these macros, which are not functions. All uses rewritten to use the following, respectively: (emacs_secs_addr, invalid_emacs_time, get_emacs_time) (add_emacs_time, sub_emacs_time): New functions. * src/atimer.c: Don't include <sys/time.h>, as "systime.h" does this. * src/fileio.c (Fcopy_file): * src/xterm.c (XTflash): Get the current time closer to when it's used. * src/makefile.w32-in ($(BLD)/atimer.$(O)): Update dependencies.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index ed926760414..37dc75529d0 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2586,7 +2586,6 @@ time_from_jiffies (unsigned long long tval, long hz)
2586 unsigned long long s = tval / hz; 2586 unsigned long long s = tval / hz;
2587 unsigned long long frac = tval % hz; 2587 unsigned long long frac = tval % hz;
2588 int ns; 2588 int ns;
2589 EMACS_TIME t;
2590 2589
2591 if (TYPE_MAXIMUM (time_t) < s) 2590 if (TYPE_MAXIMUM (time_t) < s)
2592 time_overflow (); 2591 time_overflow ();
@@ -2603,8 +2602,7 @@ time_from_jiffies (unsigned long long tval, long hz)
2603 ns = frac / hz_per_ns; 2602 ns = frac / hz_per_ns;
2604 } 2603 }
2605 2604
2606 EMACS_SET_SECS_NSECS (t, s, ns); 2605 return make_emacs_time (s, ns);
2607 return t;
2608} 2606}
2609 2607
2610static Lisp_Object 2608static Lisp_Object
@@ -2618,9 +2616,7 @@ static EMACS_TIME
2618get_up_time (void) 2616get_up_time (void)
2619{ 2617{
2620 FILE *fup; 2618 FILE *fup;
2621 EMACS_TIME up; 2619 EMACS_TIME up = make_emacs_time (0, 0);
2622
2623 EMACS_SET_SECS_NSECS (up, 0, 0);
2624 2620
2625 BLOCK_INPUT; 2621 BLOCK_INPUT;
2626 fup = fopen ("/proc/uptime", "r"); 2622 fup = fopen ("/proc/uptime", "r");
@@ -2649,7 +2645,7 @@ get_up_time (void)
2649 upfrac /= 10; 2645 upfrac /= 10;
2650 upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1); 2646 upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1);
2651 } 2647 }
2652 EMACS_SET_SECS_NSECS (up, upsec, upfrac); 2648 up = make_emacs_time (upsec, upfrac);
2653 } 2649 }
2654 fclose (fup); 2650 fclose (fup);
2655 } 2651 }
@@ -2874,15 +2870,15 @@ system_process_attributes (Lisp_Object pid)
2874 attrs = Fcons (Fcons (Qpri, make_number (priority)), attrs); 2870 attrs = Fcons (Fcons (Qpri, make_number (priority)), attrs);
2875 attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs); 2871 attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs);
2876 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount_eint)), attrs); 2872 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount_eint)), attrs);
2877 EMACS_GET_TIME (tnow); 2873 tnow = current_emacs_time ();
2878 telapsed = get_up_time (); 2874 telapsed = get_up_time ();
2879 EMACS_SUB_TIME (tboot, tnow, telapsed); 2875 tboot = sub_emacs_time (tnow, telapsed);
2880 tstart = time_from_jiffies (start, clocks_per_sec); 2876 tstart = time_from_jiffies (start, clocks_per_sec);
2881 EMACS_ADD_TIME (tstart, tboot, tstart); 2877 tstart = add_emacs_time (tboot, tstart);
2882 attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs); 2878 attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs);
2883 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize/1024)), attrs); 2879 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize/1024)), attrs);
2884 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4*rss)), attrs); 2880 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4*rss)), attrs);
2885 EMACS_SUB_TIME (telapsed, tnow, tstart); 2881 telapsed = sub_emacs_time (tnow, tstart);
2886 attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs); 2882 attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs);
2887 us_time = time_from_jiffies (u_time + s_time, clocks_per_sec); 2883 us_time = time_from_jiffies (u_time + s_time, clocks_per_sec);
2888 pcpu = (EMACS_TIME_TO_DOUBLE (us_time) 2884 pcpu = (EMACS_TIME_TO_DOUBLE (us_time)
@@ -3101,9 +3097,7 @@ system_process_attributes (Lisp_Object pid)
3101static EMACS_TIME 3097static EMACS_TIME
3102timeval_to_EMACS_TIME (struct timeval t) 3098timeval_to_EMACS_TIME (struct timeval t)
3103{ 3099{
3104 EMACS_TIME e; 3100 return make_emacs_time (t.tv_sec, t.tv_usec * 1000);
3105 EMACS_SET_SECS_NSECS (e, t.tv_sec, t.tv_usec * 1000);
3106 return e;
3107} 3101}
3108 3102
3109static Lisp_Object 3103static Lisp_Object
@@ -3211,9 +3205,8 @@ system_process_attributes (Lisp_Object pid)
3211 attrs); 3205 attrs);
3212 attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)), 3206 attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)),
3213 attrs); 3207 attrs);
3214 EMACS_ADD_TIME (t, 3208 t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime),
3215 timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime), 3209 timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime));
3216 timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime));
3217 attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); 3210 attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
3218 3211
3219 attrs = Fcons (Fcons (Qcutime, 3212 attrs = Fcons (Fcons (Qcutime,
@@ -3222,9 +3215,8 @@ system_process_attributes (Lisp_Object pid)
3222 attrs = Fcons (Fcons (Qcstime, 3215 attrs = Fcons (Fcons (Qcstime,
3223 make_lisp_timeval (proc.ki_rusage_ch.ru_utime)), 3216 make_lisp_timeval (proc.ki_rusage_ch.ru_utime)),
3224 attrs); 3217 attrs);
3225 EMACS_ADD_TIME (t, 3218 t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime),
3226 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime), 3219 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime));
3227 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime));
3228 attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs); 3220 attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs);
3229 3221
3230 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)), 3222 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)),
@@ -3236,8 +3228,8 @@ system_process_attributes (Lisp_Object pid)
3236 attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)), 3228 attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)),
3237 attrs); 3229 attrs);
3238 3230
3239 EMACS_GET_TIME (now); 3231 now = current_emacs_time ();
3240 EMACS_SUB_TIME (t, now, timeval_to_EMACS_TIME (proc.ki_start)); 3232 t = sub_emacs_time (now, timeval_to_EMACS_TIME (proc.ki_start));
3241 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); 3233 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
3242 3234
3243 len = sizeof fscale; 3235 len = sizeof fscale;