libwinpr-synch: fix build on OS X

This commit is contained in:
Marc-André Moreau 2014-01-26 00:06:27 -05:00
parent 6bd4362e6d
commit d5fcd78b65
2 changed files with 21 additions and 3 deletions

View File

@ -28,6 +28,10 @@
#include <winpr/synch.h> #include <winpr/synch.h>
#ifdef __linux__
#define WITH_POSIX_TIMER 1
#endif
#ifndef _WIN32 #ifndef _WIN32
#include "../handle/handle.h" #include "../handle/handle.h"
@ -36,6 +40,7 @@
#if defined __APPLE__ #if defined __APPLE__
#include <pthread.h> #include <pthread.h>
#include <sys/time.h>
#include <semaphore.h> #include <semaphore.h>
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/semaphore.h> #include <mach/semaphore.h>
@ -87,12 +92,15 @@ struct winpr_timer
int fd; int fd;
BOOL bInit; BOOL bInit;
timer_t tid;
LONG lPeriod; LONG lPeriod;
BOOL bManualReset; BOOL bManualReset;
PTIMERAPCROUTINE pfnCompletionRoutine; PTIMERAPCROUTINE pfnCompletionRoutine;
LPVOID lpArgToCompletionRoutine; LPVOID lpArgToCompletionRoutine;
#ifdef WITH_POSIX_TIMER
timer_t tid;
#endif
#ifdef HAVE_TIMERFD_H #ifdef HAVE_TIMERFD_H
struct itimerspec timeout; struct itimerspec timeout;
#endif #endif

View File

@ -36,6 +36,8 @@
#include "../handle/handle.h" #include "../handle/handle.h"
#ifdef WITH_POSIX_TIMER
static BOOL g_WaitableTimerSignalHandlerInstalled = FALSE; static BOOL g_WaitableTimerSignalHandlerInstalled = FALSE;
void WaitableTimerSignalHandler(int signum, siginfo_t* siginfo, void* arg) void WaitableTimerSignalHandler(int signum, siginfo_t* siginfo, void* arg)
@ -82,13 +84,15 @@ int InstallWaitableTimerSignalHandler()
return 0; return 0;
} }
#endif
int InitializeWaitableTimer(WINPR_TIMER* timer) int InitializeWaitableTimer(WINPR_TIMER* timer)
{ {
int status;
if (!timer->lpArgToCompletionRoutine) if (!timer->lpArgToCompletionRoutine)
{ {
#ifdef HAVE_TIMERFD_H #ifdef HAVE_TIMERFD_H
int status;
timer->fd = timerfd_create(CLOCK_MONOTONIC, 0); timer->fd = timerfd_create(CLOCK_MONOTONIC, 0);
if (timer->fd <= 0) if (timer->fd <= 0)
@ -108,6 +112,7 @@ int InitializeWaitableTimer(WINPR_TIMER* timer)
} }
else else
{ {
#ifdef WITH_POSIX_TIMER
struct sigevent sigev; struct sigevent sigev;
InstallWaitableTimerSignalHandler(); InstallWaitableTimerSignalHandler();
@ -123,6 +128,7 @@ int InitializeWaitableTimer(WINPR_TIMER* timer)
perror("timer_create"); perror("timer_create");
return -1; return -1;
} }
#endif
} }
timer->bInit = TRUE; timer->bInit = TRUE;
@ -210,6 +216,8 @@ BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPerio
return FALSE; return FALSE;
} }
#ifdef WITH_POSIX_TIMER
ZeroMemory(&(timer->timeout), sizeof(struct itimerspec)); ZeroMemory(&(timer->timeout), sizeof(struct itimerspec));
if (lpDueTime->QuadPart < 0) if (lpDueTime->QuadPart < 0)
@ -269,6 +277,8 @@ BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPerio
} }
} }
#endif
return TRUE; return TRUE;
} }