regressions: Implement common_gettimeofday.

Windows uses GetSystemTimeAsFileTime, which has some differences
with Unix' gettimeofday.

This commit also reduces the number of iterations for the ck_ticket_pb
validation to 1000 - the test was taking too long on MinGW systems.
ck_pring
David Joseph 12 years ago
parent 36a2ba143a
commit ef2ad6b998

@ -1,2 +1,6 @@
#include "../ck_ticket_pb.h"
#ifdef _WIN32
#undef ITERATE
#define ITERATE 1000
#endif
#include "validate.h"

@ -233,11 +233,11 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, bucket + i);
gettimeofday(&stv, NULL);
common_gettimeofday(&stv, NULL);
barrier = 1;
for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL);
common_gettimeofday(&etv, NULL);
stack_assert();
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));

@ -253,11 +253,11 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, NULL);
gettimeofday(&stv, NULL);
common_gettimeofday(&stv, NULL);
barrier = 1;
for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL);
common_gettimeofday(&etv, NULL);
stack_assert();
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));

@ -232,11 +232,11 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, bucket + i * n);
gettimeofday(&stv, NULL);
common_gettimeofday(&stv, NULL);
barrier = 1;
for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL);
common_gettimeofday(&etv, NULL);
stack_assert();
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));

@ -41,9 +41,12 @@
#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
@ -127,6 +130,48 @@ 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)
{

Loading…
Cancel
Save