static int TimerGetFd(HANDLE handle)
{
- WINPR_TIMER *timer = (WINPR_TIMER *)handle;
+ WINPR_TIMER* timer = (WINPR_TIMER*)handle;
if (!TimerIsHandled(handle))
return -1;
{
int length;
UINT64 expirations;
- WINPR_TIMER *timer = (WINPR_TIMER *)handle;
+ WINPR_TIMER* timer = (WINPR_TIMER*)handle;
if (!TimerIsHandled(handle))
return WAIT_FAILED;
- length = read(timer->fd, (void *) &expirations, sizeof(UINT64));
+ length = read(timer->fd, (void*) &expirations, sizeof(UINT64));
if (length != 8)
{
return WAIT_OBJECT_0;
}
-BOOL TimerCloseHandle(HANDLE handle) {
+BOOL TimerCloseHandle(HANDLE handle)
+{
WINPR_TIMER* timer;
timer = (WINPR_TIMER*) handle;
- if (!TimerIsHandled(handle))
- return FALSE;
+ if (!TimerIsHandled(handle))
+ return FALSE;
#ifdef __linux__
- if (timer->fd != -1)
+ if (timer->fd != -1)
close(timer->fd);
#endif
free(timer);
-
- return TRUE;
+ return TRUE;
}
#ifdef WITH_POSIX_TIMER
if ((timer_settime(timer->tid, 0, &(timer->timeout), NULL)) != 0)
{
- WLog_ERR(TAG,"timer_settime");
+ WLog_ERR(TAG, "timer_settime");
}
}
}
close(timer->fd);
return -1;
}
+
#else
WLog_ERR(TAG, "%s: os specific implementation is missing", __FUNCTION__);
result = -1;
if ((timer_create(CLOCK_MONOTONIC, &sigev, &(timer->tid))) != 0)
{
- WLog_ERR(TAG,"timer_create");
+ WLog_ERR(TAG, "timer_create");
return -1;
}
+
#else
WLog_ERR(TAG, "%s: os specific implementation is missing", __FUNCTION__);
result = -1;
}
-static HANDLE_OPS ops = {
- TimerIsHandled,
- TimerCloseHandle,
- TimerGetFd,
- TimerCleanupHandle
+static HANDLE_OPS ops =
+{
+ TimerIsHandled,
+ TimerCloseHandle,
+ TimerGetFd,
+ TimerCleanupHandle
};
/**
* Waitable Timer
*/
-HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset, LPCSTR lpTimerName)
+HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset,
+ LPCSTR lpTimerName)
{
HANDLE handle = NULL;
WINPR_TIMER* timer;
-
timer = (WINPR_TIMER*) calloc(1, sizeof(WINPR_TIMER));
+
if (timer)
{
WINPR_HANDLE_SET_TYPE_AND_MODE(timer, HANDLE_TYPE_TIMER, WINPR_FD_READ);
return handle;
}
-HANDLE CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset, LPCWSTR lpTimerName)
+HANDLE CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset,
+ LPCWSTR lpTimerName)
{
return NULL;
}
-HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess)
+HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName,
+ DWORD dwFlags, DWORD dwDesiredAccess)
{
BOOL bManualReset;
bManualReset = (dwFlags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? TRUE : FALSE;
return CreateWaitableTimerA(lpTimerAttributes, bManualReset, lpTimerName);
}
-HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess)
+HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName,
+ DWORD dwFlags, DWORD dwDesiredAccess)
{
return NULL;
}
BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod,
- PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume)
+ PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume)
{
ULONG Type;
WINPR_HANDLE* Object;
{
if ((timer_settime(timer->tid, 0, &(timer->timeout), NULL)) != 0)
{
- WLog_ERR(TAG,"timer_settime");
+ WLog_ERR(TAG, "timer_settime");
return FALSE;
}
}
}
BOOL SetWaitableTimerEx(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod,
- PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay)
+ PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext,
+ ULONG TolerableDelay)
{
ULONG Type;
WINPR_HANDLE* Object;
- WINPR_TIMER* timer;
if (!winpr_Handle_GetInfo(hTimer, &Type, &Object))
return FALSE;
+ (void)Object;
+
if (Type == HANDLE_TYPE_TIMER)
- {
- timer = (WINPR_TIMER*) Object;
return TRUE;
- }
return TRUE;
}
FireExpiredTimerQueueTimers(timerQueue);
pthread_mutex_unlock(&(timerQueue->cond_mutex));
+ if ((status != ETIMEDOUT) && (status != 0))
+ break;
+
if (timerQueue->bCancelled)
break;
}
pthread_cond_signal(&(timerQueue->cond));
pthread_mutex_unlock(&(timerQueue->cond_mutex));
pthread_join(timerQueue->thread, &rvalue);
-
/**
* Quote from MSDN regarding CompletionEvent:
* If this parameter is INVALID_HANDLE_VALUE, the function waits for
* Note: The current WinPR implementation implicitly waits for any
* callback functions to complete (see pthread_join above)
*/
-
{
/* Move all active timers to the inactive timer list */
node = timerQueue->activeHead;
timerQueue->inactiveHead = NULL;
}
-
/* Delete timer queue */
pthread_cond_destroy(&(timerQueue->cond));
pthread_mutex_destroy(&(timerQueue->cond_mutex));
}
BOOL CreateTimerQueueTimer(PHANDLE phNewTimer, HANDLE TimerQueue,
- WAITORTIMERCALLBACK Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
+ WAITORTIMERCALLBACK Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
{
struct timespec CurrentTime;
WINPR_TIMER_QUEUE* timerQueue;
timerQueue = (WINPR_TIMER_QUEUE*) TimerQueue;
timer = (WINPR_TIMER_QUEUE_TIMER*) Timer;
pthread_mutex_lock(&(timerQueue->cond_mutex));
-
/**
* Quote from MSDN regarding CompletionEvent:
* If this parameter is INVALID_HANDLE_VALUE, the function waits for
* Note: The current WinPR implementation implicitly waits for any
* callback functions to complete (see cond_mutex usage)
*/
-
RemoveTimerQueueTimer(&(timerQueue->activeHead), timer);
-
pthread_cond_signal(&(timerQueue->cond));
pthread_mutex_unlock(&(timerQueue->cond_mutex));
free(timer);