#include <time.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#ifdef HOST_WIN32
#include <windows.h>
#else
static mach_timebase_info_data_t timebase_info;
#endif
-#ifndef MAP_ANON
+#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#define TICKS_PER_SEC 1000000000LL
-#if (defined(TARGET_X86) || defined(TARGET_AMD64)) && defined(__linux__)
+#if (defined(TARGET_X86) || defined(TARGET_AMD64)) && defined(__linux__) && defined(HAVE_SCHED_GETCPU)
#define HAVE_RDTSC 1
#endif
#ifdef HOST_WIN32
static CRITICAL_SECTION log_lock;
+static LARGE_INTEGER pcounter_freq;
#else
static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
#if defined(__APPLE__)
uint64_t time = mach_absolute_time ();
- time *= info.numer;
- time /= info.denom;
+ time *= timebase_info.numer;
+ time /= timebase_info.denom;
return time;
-#else
+#elif defined(HOST_WIN32)
+ LARGE_INTEGER value;
+ QueryPerformanceCounter (&value);
+ return value.QuadPart * TICKS_PER_SEC / pcounter_freq.QuadPart;
+#elif defined(CLOCK_MONOTONIC)
struct timespec tspec;
clock_gettime (CLOCK_MONOTONIC, &tspec);
return ((uint64_t)tspec.tv_sec * TICKS_PER_SEC + tspec.tv_nsec);
+#else
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ return ((uint64_t)tv.tv_sec * TICKS_PER_SEC + tv.tv_usec * 1000);
#endif
}
TLS_INIT (tls_data);
#ifdef HOST_WIN32
InitializeCriticalSection (&log_lock);
+ QueryPerformanceFrequency (&pcounter_freq);
#endif
#if defined (__APPLE__)
mach_timebase_info (&timebase_info);
#endif
}
+uintptr_t
+process_id (void)
+{
+#ifdef HOST_WIN32
+ return 0; /* FIXME */
+#else
+ return (uintptr_t)getpid ();
+#endif
+}
+