From 23c3cd8d7ae77ea4cd17e8f7fb02491fc3ac3133 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Sat, 25 Oct 2014 09:59:20 +0100 Subject: [PATCH] add some definitions to get this build under mingw --- include/tr/timer.h | 13 ++++++++++ src/print_trace.c | 15 ++++++++++- src/syslog.c | 19 ++++++++++++-- src/timer.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 3 deletions(-) diff --git a/include/tr/timer.h b/include/tr/timer.h index 4a9a882..c352ded 100644 --- a/include/tr/timer.h +++ b/include/tr/timer.h @@ -24,8 +24,21 @@ #ifndef __TR_TIMER_H__ #define __TR_TIMER_H__ +#include + #include "trbase.h" +#ifdef _WIN32 +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +#define CLOCK_REALTIME 1 + +int clock_gettime(int, struct timespec *tv); +#endif + typedef enum { TR_TBASE_NAN = 0, TR_TBASE_MIC, diff --git a/src/print_trace.c b/src/print_trace.c index 48466fc..42cfa11 100644 --- a/src/print_trace.c +++ b/src/print_trace.c @@ -20,11 +20,22 @@ * along with this program. If not, see . */ -#include #include #include /* Obtain a backtrace and print it to stdout. */ +#ifdef _WIN32 + +void +print_trace (void) +{ + printf ("sorry, bo backtrace under Windows now!\n"); +} + +#else + +#include + void print_trace (void) { @@ -44,4 +55,6 @@ print_trace (void) free (strings); } +#endif + // vim: set ts=4 sw=4: diff --git a/src/syslog.c b/src/syslog.c index 3e734a9..3f2aca9 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -20,12 +20,25 @@ * along with this program. If not, see . */ -#include - #include "trbase.h" #include "tr/logger.h" #include "tr/interface/logger.h" +#ifdef _WIN32 + +#include + +static +void +logSyslog(void * this, TR_logger_level level, const char * const msg) +{ + printf("Sorry, no syslog under Windows!\n"); +} + +#else + +#include + static const int syslog_priority[] = { @@ -46,6 +59,8 @@ logSyslog(void * this, TR_logger_level level, const char * const msg) syslog(syslog_priority[level], "[%s] %s", TR_logger_level_str[level], msg); } +#endif + TR_INIT_IFACE(TR_Logger, logSyslog); TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger)); diff --git a/src/timer.c b/src/timer.c index 3038e59..8e554b6 100644 --- a/src/timer.c +++ b/src/timer.c @@ -24,6 +24,71 @@ #include "trbase.h" +#ifdef _WIN32 +#include + +static +LARGE_INTEGER +getFILETIMEoffset() +{ + SYSTEMTIME s; + FILETIME f; + LARGE_INTEGER t; + + s.wYear = 1970; + s.wMonth = 1; + s.wDay = 1; + s.wHour = 0; + s.wMinute = 0; + s.wSecond = 0; + s.wMilliseconds = 0; + SystemTimeToFileTime(&s, &f); + t.QuadPart = f.dwHighDateTime; + t.QuadPart <<= 32; + t.QuadPart |= f.dwLowDateTime; + return (t); +} + +int +clock_gettime(int X, struct timespec *tv) +{ + LARGE_INTEGER t; + FILETIME f; + double microseconds; + static LARGE_INTEGER offset; + static double frequencyToMicroseconds; + static int initialized = 0; + static BOOL usePerformanceCounter = 0; + + if (!initialized) { + LARGE_INTEGER performanceFrequency; + initialized = 1; + usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); + if (usePerformanceCounter) { + QueryPerformanceCounter(&offset); + frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.; + } else { + offset = getFILETIMEoffset(); + frequencyToMicroseconds = 10.; + } + } + if (usePerformanceCounter) QueryPerformanceCounter(&t); + else { + GetSystemTimeAsFileTime(&f); + t.QuadPart = f.dwHighDateTime; + t.QuadPart <<= 32; + t.QuadPart |= f.dwLowDateTime; + } + + t.QuadPart -= offset.QuadPart; + microseconds = (double)t.QuadPart / frequencyToMicroseconds; + t.QuadPart = microseconds; + tv->tv_sec = t.QuadPart / 1000000; + tv->tv_nsec = t.QuadPart % 1000000; + return (0); +} +#endif + static int timerCtor(void * _this, va_list * params)