Implemented timeouts for WaitForSingleObject.

Added assertions for functions not implemented.
This commit is contained in:
Armin Novak 2013-08-13 14:05:38 +02:00
parent ccc5d1b279
commit c3e847f472

View File

@ -25,6 +25,8 @@
#include <unistd.h>
#endif
#include <assert.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
@ -57,14 +59,21 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
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)
{
status = pthread_join(thread->thread, &thread_status);
if (dwMilliseconds != INFINITE)
{
struct timespec timeout;
timeout.tv_sec = dwMilliseconds / 1000;
timeout.tv_nsec = (dwMilliseconds % 1000) * 1000000;
status = pthread_timedjoin_np(thread->thread, &thread_status, &timeout);
}
else
status = pthread_join(thread->thread, &thread_status);
if (status != 0)
fprintf(stderr, "WaitForSingleObject: pthread_join failure: %d\n", status);
@ -80,9 +89,16 @@ 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;
pthread_mutex_lock(&mutex->mutex);
timeout.tv_sec = dwMilliseconds / 1000;
timeout.tv_nsec = (dwMilliseconds % 1000) * 1000000;
pthread_mutex_timedlock(&mutex->mutex, &timeout);
}
else
pthread_mutex_lock(&mutex->mutex);
}
else if (Type == HANDLE_TYPE_EVENT)
{
@ -213,6 +229,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable)
{
assert(0);
return WAIT_OBJECT_0;
}
@ -336,11 +353,13 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl
DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds, BOOL bAlertable)
{
assert(0);
return 0;
}
DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable)
{
assert(0);
return 0;
}