Browse Source

add some definitions to get this build under mingw

1.0.2
Georg Hopp 11 years ago
parent
commit
23c3cd8d7a
  1. 13
      include/tr/timer.h
  2. 15
      src/print_trace.c
  3. 19
      src/syslog.c
  4. 65
      src/timer.c

13
include/tr/timer.h

@ -24,8 +24,21 @@
#ifndef __TR_TIMER_H__ #ifndef __TR_TIMER_H__
#define __TR_TIMER_H__ #define __TR_TIMER_H__
#include <time.h>
#include "trbase.h" #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 { typedef enum {
TR_TBASE_NAN = 0, TR_TBASE_NAN = 0,
TR_TBASE_MIC, TR_TBASE_MIC,

15
src/print_trace.c

@ -20,11 +20,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <execinfo.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */ /* Obtain a backtrace and print it to stdout. */
#ifdef _WIN32
void
print_trace (void)
{
printf ("sorry, bo backtrace under Windows now!\n");
}
#else
#include <execinfo.h>
void void
print_trace (void) print_trace (void)
{ {
@ -44,4 +55,6 @@ print_trace (void)
free (strings); free (strings);
} }
#endif
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

19
src/syslog.c

@ -20,12 +20,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <syslog.h>
#include "trbase.h" #include "trbase.h"
#include "tr/logger.h" #include "tr/logger.h"
#include "tr/interface/logger.h" #include "tr/interface/logger.h"
#ifdef _WIN32
#include <stdio.h>
static
void
logSyslog(void * this, TR_logger_level level, const char * const msg)
{
printf("Sorry, no syslog under Windows!\n");
}
#else
#include <syslog.h>
static static
const const
int syslog_priority[] = { 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); syslog(syslog_priority[level], "[%s] %s", TR_logger_level_str[level], msg);
} }
#endif
TR_INIT_IFACE(TR_Logger, logSyslog); TR_INIT_IFACE(TR_Logger, logSyslog);
TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger)); TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger));

65
src/timer.c

@ -24,6 +24,71 @@
#include "trbase.h" #include "trbase.h"
#ifdef _WIN32
#include <Windows.h>
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 static
int int
timerCtor(void * _this, va_list * params) timerCtor(void * _this, va_list * params)

Loading…
Cancel
Save