|
|
|
@ -37,14 +37,16 @@
|
|
|
|
|
#elif defined(__MACH__)
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <mach/thread_policy.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#define DELTA_EPOCH 11644473600000000ULL
|
|
|
|
|
#else
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -128,6 +130,49 @@ common_sleep(unsigned int n)
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CK_CC_INLINE static int
|
|
|
|
|
common_gettimeofday(struct timeval *tv, void *tz)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
FILETIME ft;
|
|
|
|
|
uint64_t tmp_time = 0;
|
|
|
|
|
static bool tzflag = false;
|
|
|
|
|
|
|
|
|
|
if (tv != NULL) {
|
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
tmp_time |= ft.dwHighDateTime;
|
|
|
|
|
tmp_time <<= 32;
|
|
|
|
|
tmp_time |= ft.dwLowDateTime;
|
|
|
|
|
|
|
|
|
|
/* GetSystemTimeAsFileTime returns 100 nanosecond intervals. */
|
|
|
|
|
tmp_time /= 10;
|
|
|
|
|
|
|
|
|
|
/* Windows' epoch starts on 01/01/1601, while Unix' starts on 01/01/1970. */
|
|
|
|
|
tmp_time -= DELTA_EPOCH;
|
|
|
|
|
|
|
|
|
|
tv->tv_sec = (long)(tmp_time / 1000000UL);
|
|
|
|
|
tv->tv_usec = (long)(tmp_time % 1000000UL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tz != NULL) {
|
|
|
|
|
if (tzflag == false) {
|
|
|
|
|
_tzset();
|
|
|
|
|
tzflag = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct timezone *tzp = (struct timezone *)tz;
|
|
|
|
|
|
|
|
|
|
tzp->tz_minuteswest = _timezone / 60;
|
|
|
|
|
tzp->tz_dsttime = _daylight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
#else
|
|
|
|
|
return gettimeofday(tv, tz);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CK_CC_UNUSED static unsigned int
|
|
|
|
|
common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration)
|
|
|
|
|
{
|
|
|
|
@ -150,55 +195,63 @@ common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration)
|
|
|
|
|
#ifndef SECOND_TIMER
|
|
|
|
|
#define SECOND_TIMER 10000000
|
|
|
|
|
#endif
|
|
|
|
|
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) \
|
|
|
|
|
static HANDLE common_win_alarm_timer; \
|
|
|
|
|
static HANDLE alarm_event_name; \
|
|
|
|
|
static LARGE_INTEGER timer_length; \
|
|
|
|
|
\
|
|
|
|
|
static void CALLBACK \
|
|
|
|
|
common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \
|
|
|
|
|
{ \
|
|
|
|
|
(void)arg; \
|
|
|
|
|
(void)timer_low_value; \
|
|
|
|
|
(void)timer_high_value; \
|
|
|
|
|
flag_name = true; \
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
static void * \
|
|
|
|
|
common_win_alarm(void *unused) \
|
|
|
|
|
{ \
|
|
|
|
|
(void)unused; \
|
|
|
|
|
bool timer_success = false; \
|
|
|
|
|
for (;;) { \
|
|
|
|
|
WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \
|
|
|
|
|
timer_success = SetWaitableTimer(common_win_alarm_timer, &timer_length, 0, common_win_alarm_handler, NULL, false); \
|
|
|
|
|
assert(timer_success != false); \
|
|
|
|
|
WaitForSingleObjectEx(common_win_alarm_timer, INFINITE, true); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return NULL; \
|
|
|
|
|
#define COMMON_ALARM_DECLARE_GLOBAL(prefix, alarm_event_name, flag_name) \
|
|
|
|
|
static HANDLE prefix##_common_win_alarm_timer; \
|
|
|
|
|
static HANDLE alarm_event_name; \
|
|
|
|
|
static LARGE_INTEGER prefix##_common_alarm_timer_length; \
|
|
|
|
|
\
|
|
|
|
|
static void CALLBACK \
|
|
|
|
|
prefix##_common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \
|
|
|
|
|
{ \
|
|
|
|
|
(void)arg; \
|
|
|
|
|
(void)timer_low_value; \
|
|
|
|
|
(void)timer_high_value; \
|
|
|
|
|
flag_name = true; \
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
static void * \
|
|
|
|
|
prefix##_common_win_alarm(void *unused) \
|
|
|
|
|
{ \
|
|
|
|
|
(void)unused; \
|
|
|
|
|
bool timer_success = false; \
|
|
|
|
|
for (;;) { \
|
|
|
|
|
WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \
|
|
|
|
|
timer_success = SetWaitableTimer(prefix##_common_win_alarm_timer, \
|
|
|
|
|
&prefix##_common_alarm_timer_length, \
|
|
|
|
|
0, \
|
|
|
|
|
prefix##_common_win_alarm_handler, NULL, false); \
|
|
|
|
|
assert(timer_success != false); \
|
|
|
|
|
WaitForSingleObjectEx(prefix##_common_win_alarm_timer, INFINITE, true); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return NULL; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \
|
|
|
|
|
__int64 tl; \
|
|
|
|
|
pthread_t common_win_alarm_thread;
|
|
|
|
|
|
|
|
|
|
#define COMMON_ALARM_INIT(alarm_event_name, duration) \
|
|
|
|
|
tl = -1 * duration * SECOND_TIMER; \
|
|
|
|
|
timer_length.LowPart = (DWORD) (tl & 0xFFFFFFFF); \
|
|
|
|
|
timer_length.HighPart = (LONG) (tl >> 32); \
|
|
|
|
|
alarm_event_name = CreateEvent(NULL, false, false, NULL); \
|
|
|
|
|
assert(alarm_event_name != NULL); \
|
|
|
|
|
common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \
|
|
|
|
|
assert(common_win_alarm_timer != NULL); \
|
|
|
|
|
if (pthread_create(&common_win_alarm_thread, NULL, common_win_alarm, NULL) != 0) \
|
|
|
|
|
#define COMMON_ALARM_DECLARE_LOCAL(prefix, alarm_event_name) \
|
|
|
|
|
int64_t prefix##_common_alarm_tl; \
|
|
|
|
|
pthread_t prefix##_common_win_alarm_thread;
|
|
|
|
|
|
|
|
|
|
#define COMMON_ALARM_INIT(prefix, alarm_event_name, duration) \
|
|
|
|
|
prefix##_common_alarm_tl = -1 * (duration) * SECOND_TIMER; \
|
|
|
|
|
prefix##_common_alarm_timer_length.LowPart = \
|
|
|
|
|
(DWORD) (prefix##_common_alarm_tl & 0xFFFFFFFF); \
|
|
|
|
|
prefix##_common_alarm_timer_length.HighPart = \
|
|
|
|
|
(LONG) (prefix##_common_alarm_tl >> 32); \
|
|
|
|
|
alarm_event_name = CreateEvent(NULL, false, false, NULL); \
|
|
|
|
|
assert(alarm_event_name != NULL); \
|
|
|
|
|
prefix##_common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \
|
|
|
|
|
assert(prefix##_common_win_alarm_timer != NULL); \
|
|
|
|
|
if (pthread_create(&prefix##_common_win_alarm_thread, \
|
|
|
|
|
NULL, \
|
|
|
|
|
prefix##_common_win_alarm, \
|
|
|
|
|
NULL) != 0) \
|
|
|
|
|
ck_error("ERROR: Failed to create common_win_alarm thread.\n");
|
|
|
|
|
#else
|
|
|
|
|
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name)
|
|
|
|
|
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \
|
|
|
|
|
#define COMMON_ALARM_DECLARE_GLOBAL(prefix, alarm_event_name, flag_name)
|
|
|
|
|
#define COMMON_ALARM_DECLARE_LOCAL(prefix, alarm_event_name) \
|
|
|
|
|
int alarm_event_name = 0;
|
|
|
|
|
#define COMMON_ALARM_INIT(alarm_event_name, duration)
|
|
|
|
|
#define COMMON_ALARM_INIT(prefix, alarm_event_name, duration)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct affinity {
|
|
|
|
|