Merge pull request #1421 from akallabeth/winpr_timeouts
Winpr WaitForSingleObject timeouts
This commit is contained in:
commit
abdd98515b
@ -25,6 +25,8 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
@ -43,6 +45,18 @@
|
||||
|
||||
#include "../handle/handle.h"
|
||||
|
||||
static void ts_add_ms(struct timespec *ts, DWORD dwMilliseconds)
|
||||
{
|
||||
ts->tv_sec += dwMilliseconds / 1000L;
|
||||
ts->tv_nsec += (dwMilliseconds % 1000L) * 1000000L;
|
||||
|
||||
while(ts->tv_nsec >= 1000000000L)
|
||||
{
|
||||
ts->tv_sec ++;
|
||||
ts->tv_nsec -= 1000000000L;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
{
|
||||
ULONG Type;
|
||||
@ -53,17 +67,29 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
|
||||
if (Type == HANDLE_TYPE_THREAD)
|
||||
{
|
||||
int status;
|
||||
int status = 0;
|
||||
WINPR_THREAD* thread;
|
||||
void* thread_status = NULL;
|
||||
|
||||
if (dwMilliseconds != INFINITE)
|
||||
fprintf(stderr, "WaitForSingleObject: timeout not implemented for thread wait\n");
|
||||
|
||||
thread = (WINPR_THREAD*) Object;
|
||||
|
||||
if (thread->started)
|
||||
{
|
||||
if (dwMilliseconds != INFINITE)
|
||||
{
|
||||
#if _GNU_SOURCE
|
||||
struct timespec timeout;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &timeout);
|
||||
ts_add_ms(&timeout, dwMilliseconds);
|
||||
|
||||
status = pthread_timedjoin_np(thread->thread, &thread_status, &timeout);
|
||||
#else
|
||||
fprintf(stderr, "[ERROR] %s: Thread timeouts not implemented.\n", __func__);
|
||||
assert(0);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
status = pthread_join(thread->thread, &thread_status);
|
||||
|
||||
if (status != 0)
|
||||
@ -80,8 +106,15 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
mutex = (WINPR_MUTEX*) Object;
|
||||
|
||||
if (dwMilliseconds != INFINITE)
|
||||
fprintf(stderr, "WaitForSingleObject: timeout not implemented for mutex wait\n");
|
||||
{
|
||||
struct timespec timeout;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &timeout);
|
||||
ts_add_ms(&timeout, dwMilliseconds);
|
||||
|
||||
pthread_mutex_timedlock(&mutex->mutex, &timeout);
|
||||
}
|
||||
else
|
||||
pthread_mutex_lock(&mutex->mutex);
|
||||
}
|
||||
else if (Type == HANDLE_TYPE_EVENT)
|
||||
@ -213,6 +246,8 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
|
||||
DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
fprintf(stderr, "[ERROR] %s: Function not implemented.\n", __func__);
|
||||
assert(0);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
@ -235,7 +270,10 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl
|
||||
ZeroMemory(&timeout, sizeof(timeout));
|
||||
|
||||
if (bWaitAll)
|
||||
{
|
||||
fprintf(stderr, "WaitForMultipleObjects: bWaitAll not yet implemented\n");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
for (index = 0; index < nCount; index++)
|
||||
{
|
||||
@ -336,11 +374,15 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl
|
||||
|
||||
DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
fprintf(stderr, "[ERROR] %s: Function not implemented.\n", __func__);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
fprintf(stderr, "[ERROR] %s: Function not implemented.\n", __func__);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user