Commit 23c3cd8d7ae77ea4cd17e8f7fb02491fc3ac3133

Authored by Georg Hopp
1 parent 25979161

add some definitions to get this build under mingw

... ... @@ -24,8 +24,21 @@
24 24 #ifndef __TR_TIMER_H__
25 25 #define __TR_TIMER_H__
26 26
  27 +#include <time.h>
  28 +
27 29 #include "trbase.h"
28 30
  31 +#ifdef _WIN32
  32 +struct timespec {
  33 + time_t tv_sec;
  34 + long tv_nsec;
  35 +};
  36 +
  37 +#define CLOCK_REALTIME 1
  38 +
  39 +int clock_gettime(int, struct timespec *tv);
  40 +#endif
  41 +
29 42 typedef enum {
30 43 TR_TBASE_NAN = 0,
31 44 TR_TBASE_MIC,
... ...
... ... @@ -20,11 +20,22 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <execinfo.h>
24 23 #include <stdio.h>
25 24 #include <stdlib.h>
26 25
27 26 /* Obtain a backtrace and print it to stdout. */
  27 +#ifdef _WIN32
  28 +
  29 +void
  30 +print_trace (void)
  31 +{
  32 + printf ("sorry, bo backtrace under Windows now!\n");
  33 +}
  34 +
  35 +#else
  36 +
  37 +#include <execinfo.h>
  38 +
28 39 void
29 40 print_trace (void)
30 41 {
... ... @@ -44,4 +55,6 @@ print_trace (void)
44 55 free (strings);
45 56 }
46 57
  58 +#endif
  59 +
47 60 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,12 +20,25 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <syslog.h>
24   -
25 23 #include "trbase.h"
26 24 #include "tr/logger.h"
27 25 #include "tr/interface/logger.h"
28 26
  27 +#ifdef _WIN32
  28 +
  29 +#include <stdio.h>
  30 +
  31 +static
  32 +void
  33 +logSyslog(void * this, TR_logger_level level, const char * const msg)
  34 +{
  35 + printf("Sorry, no syslog under Windows!\n");
  36 +}
  37 +
  38 +#else
  39 +
  40 +#include <syslog.h>
  41 +
29 42 static
30 43 const
31 44 int syslog_priority[] = {
... ... @@ -46,6 +59,8 @@ logSyslog(void * this, TR_logger_level level, const char * const msg)
46 59 syslog(syslog_priority[level], "[%s] %s", TR_logger_level_str[level], msg);
47 60 }
48 61
  62 +#endif
  63 +
49 64 TR_INIT_IFACE(TR_Logger, logSyslog);
50 65 TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger));
51 66
... ...
... ... @@ -24,6 +24,71 @@
24 24
25 25 #include "trbase.h"
26 26
  27 +#ifdef _WIN32
  28 +#include <Windows.h>
  29 +
  30 +static
  31 +LARGE_INTEGER
  32 +getFILETIMEoffset()
  33 +{
  34 + SYSTEMTIME s;
  35 + FILETIME f;
  36 + LARGE_INTEGER t;
  37 +
  38 + s.wYear = 1970;
  39 + s.wMonth = 1;
  40 + s.wDay = 1;
  41 + s.wHour = 0;
  42 + s.wMinute = 0;
  43 + s.wSecond = 0;
  44 + s.wMilliseconds = 0;
  45 + SystemTimeToFileTime(&s, &f);
  46 + t.QuadPart = f.dwHighDateTime;
  47 + t.QuadPart <<= 32;
  48 + t.QuadPart |= f.dwLowDateTime;
  49 + return (t);
  50 +}
  51 +
  52 +int
  53 +clock_gettime(int X, struct timespec *tv)
  54 +{
  55 + LARGE_INTEGER t;
  56 + FILETIME f;
  57 + double microseconds;
  58 + static LARGE_INTEGER offset;
  59 + static double frequencyToMicroseconds;
  60 + static int initialized = 0;
  61 + static BOOL usePerformanceCounter = 0;
  62 +
  63 + if (!initialized) {
  64 + LARGE_INTEGER performanceFrequency;
  65 + initialized = 1;
  66 + usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
  67 + if (usePerformanceCounter) {
  68 + QueryPerformanceCounter(&offset);
  69 + frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
  70 + } else {
  71 + offset = getFILETIMEoffset();
  72 + frequencyToMicroseconds = 10.;
  73 + }
  74 + }
  75 + if (usePerformanceCounter) QueryPerformanceCounter(&t);
  76 + else {
  77 + GetSystemTimeAsFileTime(&f);
  78 + t.QuadPart = f.dwHighDateTime;
  79 + t.QuadPart <<= 32;
  80 + t.QuadPart |= f.dwLowDateTime;
  81 + }
  82 +
  83 + t.QuadPart -= offset.QuadPart;
  84 + microseconds = (double)t.QuadPart / frequencyToMicroseconds;
  85 + t.QuadPart = microseconds;
  86 + tv->tv_sec = t.QuadPart / 1000000;
  87 + tv->tv_nsec = t.QuadPart % 1000000;
  88 + return (0);
  89 +}
  90 +#endif
  91 +
27 92 static
28 93 int
29 94 timerCtor(void * _this, va_list * params)
... ...
Please register or login to post a comment