#include <stdio.h>
#include <stdlib.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else /* not HAVE_STRING_H */
-# include <strings.h>
-#endif /* not HAVE_STRING_H */
-#include <sys/types.h>
+#include <string.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <assert.h>
+#include <time.h>
-/* Cygwin currently (as of 2005-04-08, Cygwin 1.5.14) lack clock_getres,
- but still define _POSIX_TIMERS! Because of that we simply use the
+/* Cygwin currently (as of 2005-04-08, Cygwin 1.5.14) lacks clock_getres,
+ but still defines _POSIX_TIMERS! Because of that we simply use the
Windows timers under Cygwin. */
#ifdef __CYGWIN__
# include <windows.h>
#include "wget.h"
#include "ptimer.h"
-#ifndef errno
-extern int errno;
-#endif
-
-/* Depending on the OS and availability of gettimeofday(), one and
- only one of PTIMER_POSIX, PTIMER_GETTIMEOFDAY, PTIMER_WINDOWS, or
- PTIMER_TIME will be defined. */
+/* Depending on the OS, one and only one of PTIMER_POSIX,
+ PTIMER_GETTIMEOFDAY, or PTIMER_WINDOWS will be defined. */
#undef PTIMER_POSIX
#undef PTIMER_GETTIMEOFDAY
-#undef PTIMER_TIME
#undef PTIMER_WINDOWS
#if defined(WINDOWS) || defined(__CYGWIN__)
# define PTIMER_WINDOWS /* use Windows timers */
+#elif _POSIX_TIMERS - 0 > 0
+# define PTIMER_POSIX /* use POSIX timers (clock_gettime) */
#else
-# if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
-# define PTIMER_POSIX /* use POSIX timers (clock_gettime) */
-# else
-# ifdef HAVE_GETTIMEOFDAY
-# define PTIMER_GETTIMEOFDAY /* use gettimeofday */
-# else
-# define PTIMER_TIME
-# endif
-# endif
+# define PTIMER_GETTIMEOFDAY /* use gettimeofday */
#endif
#ifdef PTIMER_POSIX
int id;
int sysconf_name;
} clocks[] = {
-#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
+#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK - 0 >= 0
{ CLOCK_MONOTONIC, _SC_MONOTONIC_CLOCK },
#endif
#ifdef CLOCK_HIGHRES
}
#endif /* PTIMER_GETTIMEOFDAY */
-#ifdef PTIMER_TIME
-/* Elapsed time measurement using the time(2) call: system time is
- held in time_t, retrieved using time, and resolution is 1 second.
-
- This method is a catch-all for non-Windows systems without
- gettimeofday -- e.g. DOS or really old or non-standard Unix
- systems. */
-
-typedef time_t ptimer_system_time;
-
-#define IMPL_measure time_measure
-#define IMPL_diff time_diff
-#define IMPL_resolution time_resolution
-
-static inline void
-time_measure (ptimer_system_time *pst)
-{
- time (pst);
-}
-
-static inline double
-time_diff (ptimer_system_time *pst1, ptimer_system_time *pst2)
-{
- return 1000.0 * (*pst1 - *pst2);
-}
-
-static inline double
-time_resolution (void)
-{
- return 1;
-}
-#endif /* PTIMER_TIME */
-
#ifdef PTIMER_WINDOWS
/* Elapsed time measurement on Windows: where high-resolution timers
are available, time is stored in a LARGE_INTEGER and retrieved
/* Whether high-resolution timers are used. Set by ptimer_initialize_once
the first time ptimer_new is called. */
-static int windows_hires_timers;
+static bool windows_hires_timers;
/* Frequency of high-resolution timers -- number of updates per
millisecond. Calculated the first time ptimer_new is called
QueryPerformanceFrequency (&freq);
if (freq.QuadPart != 0)
{
- windows_hires_timers = 1;
+ windows_hires_timers = true;
windows_hires_msfreq = (double) freq.QuadPart / 1000.0;
}
}
{
struct ptimer *pt = xnew0 (struct ptimer);
#ifdef IMPL_init
- static int init_done;
+ static bool init_done;
if (!init_done)
{
- init_done = 1;
+ init_done = true;
IMPL_init ();
}
#endif