libwinpr-synch: implemented Win32 Events
This commit is contained in:
parent
13dbbb9513
commit
4bd217055c
@ -27,6 +27,10 @@
|
||||
|
||||
#include "../synch/synch.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
BOOL CloseHandle(HANDLE hObject)
|
||||
{
|
||||
ULONG Type;
|
||||
@ -38,7 +42,31 @@ BOOL CloseHandle(HANDLE hObject)
|
||||
if (Type == HANDLE_TYPE_MUTEX)
|
||||
{
|
||||
pthread_mutex_destroy((pthread_mutex_t*) Object);
|
||||
winpr_Handle_Remove(Object);
|
||||
free(Object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else if (Type == HANDLE_TYPE_EVENT)
|
||||
{
|
||||
WINPR_EVENT* event;
|
||||
|
||||
event = (WINPR_EVENT*) Object;
|
||||
|
||||
if (event->pipe_fd[0] != -1)
|
||||
{
|
||||
close(event->pipe_fd[0]);
|
||||
event->pipe_fd[0] = -1;
|
||||
}
|
||||
if (event->pipe_fd[1] != -1)
|
||||
{
|
||||
close(event->pipe_fd[1]);
|
||||
event->pipe_fd[1] = -1;
|
||||
}
|
||||
|
||||
winpr_Handle_Remove(Object);
|
||||
free(event);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* WaitOnAddress
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
VOID WakeByAddressAll(PVOID Address)
|
||||
{
|
||||
|
||||
@ -43,3 +45,5 @@ BOOL WaitOnAddress(VOID volatile *Address, PVOID CompareAddress, SIZE_T AddressS
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -29,6 +29,8 @@
|
||||
* DeleteSynchronizationBarrier
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
BOOL InitializeSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier, LONG lTotalThreads, LONG lSpinCount)
|
||||
{
|
||||
return TRUE;
|
||||
@ -43,3 +45,5 @@ BOOL DeleteSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,8 @@
|
||||
* WakeConditionVariable
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
VOID InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
|
||||
{
|
||||
|
||||
@ -57,3 +59,5 @@ VOID WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -34,6 +34,8 @@
|
||||
* DeleteCriticalSection
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
|
||||
{
|
||||
|
||||
@ -73,3 +75,5 @@ VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -34,12 +34,45 @@
|
||||
* ResetEvent
|
||||
*/
|
||||
|
||||
HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "synch.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
|
||||
{
|
||||
WINPR_EVENT* event;
|
||||
HANDLE handle = NULL;
|
||||
|
||||
event = (WINPR_EVENT*) malloc(sizeof(WINPR_EVENT));
|
||||
|
||||
if (!event)
|
||||
{
|
||||
event->bManualReset = bManualReset;
|
||||
|
||||
event->pipe_fd[0] = -1;
|
||||
event->pipe_fd[1] = -1;
|
||||
|
||||
if (pipe(event->pipe_fd) < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = winpr_Handle_Insert(HANDLE_TYPE_EVENT, event);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName)
|
||||
{
|
||||
return CreateEventW(lpEventAttributes, bManualReset, bInitialState, NULL);
|
||||
}
|
||||
|
||||
HANDLE CreateEventExW(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCWSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -49,7 +82,7 @@ HANDLE CreateEventExA(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCSTR lpName, DW
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANDLE CreateEventExW(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCWSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
HANDLE OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -59,17 +92,50 @@ HANDLE OpenEventA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANDLE OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL SetEvent(HANDLE hEvent)
|
||||
{
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
int length;
|
||||
WINPR_EVENT* event;
|
||||
|
||||
if (!winpr_Handle_GetInfo(hEvent, &Type, &Object))
|
||||
return FALSE;
|
||||
|
||||
event = (WINPR_EVENT*) Object;
|
||||
|
||||
if (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0)
|
||||
return TRUE;
|
||||
|
||||
length = write(event->pipe_fd[1], "sig", 4);
|
||||
|
||||
if (length != 4)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL ResetEvent(HANDLE hEvent)
|
||||
{
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
int length;
|
||||
WINPR_EVENT* event;
|
||||
|
||||
if (!winpr_Handle_GetInfo(hEvent, &Type, &Object))
|
||||
return FALSE;
|
||||
|
||||
event = (WINPR_EVENT*) Object;
|
||||
|
||||
while (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0)
|
||||
{
|
||||
length = read(event->pipe_fd[0], &length, 4);
|
||||
|
||||
if (length != 4)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -30,6 +30,8 @@
|
||||
* InitOnceInitialize
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
BOOL InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending, LPVOID* lpContext)
|
||||
{
|
||||
return TRUE;
|
||||
@ -49,3 +51,5 @@ VOID InitOnceInitialize(PINIT_ONCE InitOnce)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,8 @@
|
||||
* SleepEx
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
VOID Sleep(DWORD dwMilliseconds)
|
||||
{
|
||||
|
||||
@ -37,3 +39,5 @@ DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,8 @@
|
||||
* ReleaseSRWLockShared
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
VOID InitializeSRWLock(PSRWLOCK SRWLock)
|
||||
{
|
||||
|
||||
@ -67,3 +69,5 @@ VOID ReleaseSRWLockShared(PSRWLOCK SRWLock)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -37,6 +37,13 @@
|
||||
#define winpr_sem_t sem_t
|
||||
#endif
|
||||
|
||||
struct winpr_event
|
||||
{
|
||||
int pipe_fd[2];
|
||||
BOOL bManualReset;
|
||||
};
|
||||
typedef struct winpr_event WINPR_EVENT;
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_SYNCH_PRIVATE_H */
|
||||
|
@ -31,6 +31,8 @@
|
||||
* CancelWaitableTimer
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
{
|
||||
return NULL;
|
||||
@ -67,3 +69,5 @@ BOOL CancelWaitableTimer(HANDLE hTimer)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -21,6 +21,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "synch.h"
|
||||
@ -46,6 +51,33 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
{
|
||||
pthread_mutex_lock((pthread_mutex_t*) Object);
|
||||
}
|
||||
else if (Type == HANDLE_TYPE_EVENT)
|
||||
{
|
||||
int status;
|
||||
fd_set rfds;
|
||||
WINPR_EVENT* event;
|
||||
struct timeval timeout;
|
||||
|
||||
event = (WINPR_EVENT*) Object;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(event->pipe_fd[0], &rfds);
|
||||
ZeroMemory(&timeout, sizeof(timeout));
|
||||
|
||||
if (dwMilliseconds != INFINITE)
|
||||
{
|
||||
timeout.tv_usec = dwMilliseconds * 1000;
|
||||
}
|
||||
|
||||
status = select(event->pipe_fd[0] + 1, &rfds, 0, 0,
|
||||
(dwMilliseconds == INFINITE) ? NULL : &timeout);
|
||||
|
||||
if (status < 0)
|
||||
return WAIT_FAILED;
|
||||
|
||||
if (status != 1)
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user