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

View File

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