diff --git a/winpr/libwinpr/synch/synch.h b/winpr/libwinpr/synch/synch.h index d41f8283e..9be3cc08e 100644 --- a/winpr/libwinpr/synch/synch.h +++ b/winpr/libwinpr/synch/synch.h @@ -28,6 +28,10 @@ #include +#ifdef __linux__ +#define WITH_POSIX_TIMER 1 +#endif + #ifndef _WIN32 #include "../handle/handle.h" @@ -36,6 +40,7 @@ #if defined __APPLE__ #include +#include #include #include #include @@ -87,11 +92,14 @@ 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; diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c index 34aa4189b..ec5bdb928 100644 --- a/winpr/libwinpr/synch/timer.c +++ b/winpr/libwinpr/synch/timer.c @@ -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; }