summaryrefslogtreecommitdiff
path: root/src/atimer.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-07-10 16:24:36 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-07-10 16:24:36 -0700
commite9a9ae0350689d352c2bdfa3af0eb722f587b966 (patch)
tree10ed0298079b06838a525f0a4df780d7600e13fe /src/atimer.c
parentffacb12679a1e001981c2e0f690b327eda652d04 (diff)
downloademacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.tar.gz
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/atimer.c')
-rw-r--r--src/atimer.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/atimer.c b/src/atimer.c
index 39ac3e826bb..d67e1375f9a 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "blockinput.h"
#include "atimer.h"
#include <unistd.h>
-#include <sys/time.h>
/* Free-list of atimer structures. */
@@ -93,10 +92,7 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
#ifndef HAVE_SETITIMER
if (EMACS_NSECS (timestamp) != 0
&& EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t))
- {
- EMACS_SET_USECS (timestamp, 0);
- EMACS_SET_SECS (timestamp, EMACS_SECS (timestamp) + 1);
- }
+ timestamp = make_emacs_time (EMACS_SECS (timestamp) + 1, 0);
#endif /* not HAVE_SETITIMER */
/* Get an atimer structure from the free-list, or allocate
@@ -125,13 +121,11 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
break;
case ATIMER_RELATIVE:
- EMACS_GET_TIME (t->expiration);
- EMACS_ADD_TIME (t->expiration, t->expiration, timestamp);
+ t->expiration = add_emacs_time (current_emacs_time (), timestamp);
break;
case ATIMER_CONTINUOUS:
- EMACS_GET_TIME (t->expiration);
- EMACS_ADD_TIME (t->expiration, t->expiration, timestamp);
+ t->expiration = add_emacs_time (current_emacs_time (), timestamp);
t->interval = timestamp;
break;
}
@@ -285,31 +279,25 @@ set_alarm (void)
{
if (atimers)
{
- EMACS_TIME now, timestamp;
#ifdef HAVE_SETITIMER
struct itimerval it;
#endif
/* Determine s/us till the next timer is ripe. */
- EMACS_GET_TIME (now);
+ EMACS_TIME now = current_emacs_time ();
/* Don't set the interval to 0; this disables the timer. */
- if (EMACS_TIME_LE (atimers->expiration, now))
- {
- EMACS_SET_SECS (timestamp, 0);
- EMACS_SET_USECS (timestamp, 1000);
- }
- else
- EMACS_SUB_TIME (timestamp, atimers->expiration, now);
-
+ EMACS_TIME interval = (EMACS_TIME_LE (atimers->expiration, now)
+ ? make_emacs_time (0, 1000 * 1000)
+ : sub_emacs_time (atimers->expiration, now));
#ifdef HAVE_SETITIMER
memset (&it, 0, sizeof it);
- it.it_value = make_timeval (timestamp);
+ it.it_value = make_timeval (interval);
setitimer (ITIMER_REAL, &it, 0);
#else /* not HAVE_SETITIMER */
- alarm (max (EMACS_SECS (timestamp), 1));
+ alarm (max (EMACS_SECS (interval), 1));
#endif /* not HAVE_SETITIMER */
}
}
@@ -344,7 +332,7 @@ run_timers (void)
while (atimers
&& (pending_atimers = interrupt_input_blocked) == 0
- && (EMACS_GET_TIME (now),
+ && (now = current_emacs_time (),
EMACS_TIME_LE (atimers->expiration, now)))
{
struct atimer *t;
@@ -355,7 +343,7 @@ run_timers (void)
if (t->type == ATIMER_CONTINUOUS)
{
- EMACS_ADD_TIME (t->expiration, now, t->interval);
+ t->expiration = add_emacs_time (now, t->interval);
schedule_atimer (t);
}
else