/* Message logging */
#define ENABLE_LOGGING 1
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
fi
AC_SUBST(USE_UDEV)
-case $is_backend_android in
-yes)
- dnl there are gettimeofday function but configure doesn't seem to be able to find it.
- AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [Define if you have gettimeofday])
- ;;
-*)
- THREAD_CFLAGS="-pthread"
- LIBS="${LIBS} -pthread"
-esac
+ if test "x$is_backend_android" != xyes; then
+ THREAD_CFLAGS="-pthread"
+ LIBS="${LIBS} -pthread"
+ fi
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
# headers not available on all platforms but required on others
AC_CHECK_HEADERS([sys/time.h])
-AC_CHECK_FUNCS(gettimeofday)
# check for -std=gnu99 compiler support
saved_cflags="$CFLAGS"
LIBUSB_RC, "http://libusb.info" };
static int default_context_refcnt = 0;
static usbi_mutex_static_t default_context_lock = USBI_MUTEX_INITIALIZER;
-static struct timeval timestamp_origin = { 0, 0 };
+static struct timespec timestamp_origin = { 0, 0 };
usbi_mutex_static_t active_contexts_lock = USBI_MUTEX_INITIALIZER;
struct list_head active_contexts_list;
usbi_mutex_static_lock(&default_context_lock);
if (!timestamp_origin.tv_sec) {
- usbi_gettimeofday(×tamp_origin, NULL);
+ usbi_backend->clock_gettime(USBI_CLOCK_REALTIME, ×tamp_origin);
}
if (!context && usbi_default_context) {
return 0;
}
-/* this is defined in libusbi.h if needed */
-#ifdef LIBUSB_GETTIMEOFDAY_WIN32
-/*
- * gettimeofday
- * Implementation according to:
- * The Open Group Base Specifications Issue 6
- * IEEE Std 1003.1, 2004 Edition
- */
-
-/*
- * THIS SOFTWARE IS NOT COPYRIGHTED
- *
- * This source code is offered for use in the public domain. You may
- * use, modify or distribute it freely.
- *
- * This code is distributed in the hope that it will be useful but
- * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- * DISCLAIMED. This includes but is not limited to warranties of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Contributed by:
- * Danny Smith <dannysmith@users.sourceforge.net>
- */
-
-/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
-#define _W32_FT_OFFSET (116444736000000000)
-
-int usbi_gettimeofday(struct timeval *tp, void *tzp)
-{
- union {
- unsigned __int64 ns100; /* Time since 1 Jan 1601, in 100ns units */
- FILETIME ft;
- } _now;
- UNUSED(tzp);
-
- if(tp) {
-#if defined(OS_WINCE)
- SYSTEMTIME st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &_now.ft);
-#else
- GetSystemTimeAsFileTime (&_now.ft);
-#endif
- tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 );
- tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000);
- }
- /* Always return 0 as per Open Group Base Specifications Issue 6.
- Do not set errno on error. */
- return 0;
-}
-#endif
-
static void usbi_log_str(struct libusb_context *ctx,
enum libusb_log_level level, const char * str)
{
{
const char *prefix = "";
char buf[USBI_MAX_LOG_LEN];
- struct timeval now;
+ struct timespec now;
int global_debug, header_len, text_len;
static int has_debug_header_been_displayed = 0;
return;
#endif
- usbi_gettimeofday(&now, NULL);
+ usbi_backend->clock_gettime(USBI_CLOCK_REALTIME, &now);
if ((global_debug) && (!has_debug_header_been_displayed)) {
has_debug_header_been_displayed = 1;
usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "[timestamp] [threadID] facility level [function call] <message>" USBI_LOG_LINE_END);
usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "--------------------------------------------------------------------------------" USBI_LOG_LINE_END);
}
- if (now.tv_usec < timestamp_origin.tv_usec) {
+ if (now.tv_nsec < timestamp_origin.tv_nsec) {
now.tv_sec--;
- now.tv_usec += 1000000;
+ now.tv_nsec += 1000000000L;
}
now.tv_sec -= timestamp_origin.tv_sec;
- now.tv_usec -= timestamp_origin.tv_usec;
+ now.tv_nsec -= timestamp_origin.tv_nsec;
switch (level) {
case LIBUSB_LOG_LEVEL_INFO:
if (global_debug) {
header_len = snprintf(buf, sizeof(buf),
"[%2d.%06d] [%08x] libusb: %s [%s] ",
- (int)now.tv_sec, (int)now.tv_usec, usbi_get_tid(), prefix, function);
+ (int)now.tv_sec, (int)(now.tv_nsec / 1000L), usbi_get_tid(), prefix, function);
} else {
header_len = snprintf(buf, sizeof(buf),
"libusb: %s [%s] ", prefix, function);
#if (defined(OS_WINDOWS) || defined(OS_WINCE)) && !defined(__GNUC__)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
-int usbi_gettimeofday(struct timeval *tp, void *tzp);
-#define LIBUSB_GETTIMEOFDAY_WIN32
-#define HAVE_USBI_GETTIMEOFDAY
-#else
-#ifdef HAVE_GETTIMEOFDAY
-#define usbi_gettimeofday(tv, tz) gettimeofday((tv), (tz))
-#define HAVE_USBI_GETTIMEOFDAY
-#endif
#endif
struct usbi_pollfd {
#include "wince_usb.h"
// Global variables
-const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:000 in MS Filetime
int windows_version = WINDOWS_CE;
static uint64_t hires_frequency, hires_ticks_to_ps;
static HANDLE driver_handle = INVALID_HANDLE_VALUE;
// Fall through and return real-time if monotonic read failed or was not detected @ init
case USBI_CLOCK_REALTIME:
// We follow http://msdn.microsoft.com/en-us/library/ms724928%28VS.85%29.aspx
- // with a predef epoch_time to have an epoch that starts at 1970.01.01 00:00
+ // with a predef epoch time to have an epoch that starts at 1970.01.01 00:00
// Note however that our resolution is bounded by the Windows system time
// functions and is at best of the order of 1 ms (or, usually, worse)
GetSystemTime(&st);
SystemTimeToFileTime(&st, &filetime);
rtime.LowPart = filetime.dwLowDateTime;
rtime.HighPart = filetime.dwHighDateTime;
- rtime.QuadPart -= epoch_time;
+ rtime.QuadPart -= EPOCH_TIME;
tp->tv_sec = (long)(rtime.QuadPart / 10000000);
tp->tv_nsec = (long)((rtime.QuadPart % 10000000)*100);
return LIBUSB_SUCCESS;
#define false FALSE
#endif
+#define EPOCH_TIME UINT64_C(116444736000000000) // 1970.01.01 00:00:000 in MS Filetime
+
#if defined(__CYGWIN__ )
#define _stricmp strcasecmp
#define _snprintf snprintf
#include "windows_common.h"
#include "windows_nt_common.h"
-// Global variables
-const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:000 in MS Filetime
-
// Global variables for clock_gettime mechanism
static uint64_t hires_ticks_to_ps;
static uint64_t hires_frequency;
int windows_clock_gettime(int clk_id, struct timespec *tp)
{
struct timer_request request;
+#if !defined(_MSC_VER) || (_MSC_VER < 1900)
FILETIME filetime;
ULARGE_INTEGER rtime;
+#endif
DWORD r;
switch (clk_id) {
}
// Fall through and return real-time if monotonic was not detected @ timer init
case USBI_CLOCK_REALTIME:
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+ timespec_get(tp, TIME_UTC);
+#else
// We follow http://msdn.microsoft.com/en-us/library/ms724928%28VS.85%29.aspx
- // with a predef epoch_time to have an epoch that starts at 1970.01.01 00:00
+ // with a predef epoch time to have an epoch that starts at 1970.01.01 00:00
// Note however that our resolution is bounded by the Windows system time
// functions and is at best of the order of 1 ms (or, usually, worse)
GetSystemTimeAsFileTime(&filetime);
rtime.LowPart = filetime.dwLowDateTime;
rtime.HighPart = filetime.dwHighDateTime;
- rtime.QuadPart -= epoch_time;
+ rtime.QuadPart -= EPOCH_TIME;
tp->tv_sec = (long)(rtime.QuadPart / 10000000);
tp->tv_nsec = (long)((rtime.QuadPart % 10000000) * 100);
+#endif
return LIBUSB_SUCCESS;
default:
return LIBUSB_ERROR_INVALID_PARAM;
-#define LIBUSB_NANO 11169
+#define LIBUSB_NANO 11170