Blame winpr/include/winpr/synch.h

Packit 1fb8d4
/**
Packit 1fb8d4
 * WinPR: Windows Portable Runtime
Packit 1fb8d4
 * Synchronization Functions
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit 1fb8d4
 * Copyright 2014 Thincast Technologies GmbH
Packit 1fb8d4
 * Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifndef WINPR_SYNCH_H
Packit 1fb8d4
#define WINPR_SYNCH_H
Packit 1fb8d4
Packit 1fb8d4
#include <stdio.h>
Packit 1fb8d4
#include <stdlib.h>
Packit 1fb8d4
#include <string.h>
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/winpr.h>
Packit 1fb8d4
#include <winpr/wtypes.h>
Packit 1fb8d4
#include <winpr/error.h>
Packit 1fb8d4
#include <winpr/handle.h>
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/nt.h>
Packit 1fb8d4
Packit 1fb8d4
#ifdef __cplusplus
Packit Service 5a9772
extern "C"
Packit Service 5a9772
{
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#ifndef _WIN32
Packit 1fb8d4
Packit 1fb8d4
/* Mutex */
Packit Service 5a9772
#define CREATE_MUTEX_INITIAL_OWNER 0x00000001
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
Packit Service 5a9772
	                              LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
Packit Service 5a9772
	                              LPCWSTR lpName);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateMutexExA(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCSTR lpName,
Packit Service 5a9772
	                                DWORD dwFlags, DWORD dwDesiredAccess);
Packit Service 5a9772
	WINPR_API HANDLE CreateMutexExW(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCWSTR lpName,
Packit Service 5a9772
	                                DWORD dwFlags, DWORD dwDesiredAccess);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API BOOL ReleaseMutex(HANDLE hMutex);
Packit 1fb8d4
Packit 1fb8d4
#ifdef UNICODE
Packit Service 5a9772
#define CreateMutex CreateMutexW
Packit Service 5a9772
#define CreateMutexEx CreateMutexExW
Packit Service 5a9772
#define OpenMutex OpenMutexW
Packit 1fb8d4
#else
Packit Service 5a9772
#define CreateMutex CreateMutexA
Packit Service 5a9772
#define CreateMutexEx CreateMutexExA
Packit Service 5a9772
#define OpenMutex OpenMutexA
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	/* Semaphore */
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
Packit Service 5a9772
	                                  LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
Packit Service 5a9772
	                                  LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
Packit 1fb8d4
Packit 1fb8d4
#ifdef UNICODE
Packit Service 5a9772
#define CreateSemaphore CreateSemaphoreW
Packit Service 5a9772
#define OpenSemaphore OpenSemaphoreW
Packit 1fb8d4
#else
Packit Service 5a9772
#define CreateSemaphore CreateSemaphoreA
Packit Service 5a9772
#define OpenSemaphore OpenSemaphoreA
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount);
Packit 1fb8d4
Packit 1fb8d4
/* Event */
Packit Service 5a9772
#define CREATE_EVENT_MANUAL_RESET 0x00000001
Packit Service 5a9772
#define CREATE_EVENT_INITIAL_SET 0x00000002
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
Packit Service 5a9772
	                              BOOL bInitialState, LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
Packit Service 5a9772
	                              BOOL bInitialState, LPCWSTR lpName);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateEventExA(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCSTR lpName,
Packit Service 5a9772
	                                DWORD dwFlags, DWORD dwDesiredAccess);
Packit Service 5a9772
	WINPR_API HANDLE CreateEventExW(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCWSTR lpName,
Packit Service 5a9772
	                                DWORD dwFlags, DWORD dwDesiredAccess);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE OpenEventA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
Packit Service 5a9772
	WINPR_API HANDLE OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API BOOL SetEvent(HANDLE hEvent);
Packit Service 5a9772
	WINPR_API BOOL ResetEvent(HANDLE hEvent);
Packit 1fb8d4
Packit 1fb8d4
#ifdef UNICODE
Packit Service 5a9772
#define CreateEvent CreateEventW
Packit Service 5a9772
#define CreateEventEx CreateEventExW
Packit Service 5a9772
#define OpenEvent OpenEventW
Packit 1fb8d4
#else
Packit Service 5a9772
#define CreateEvent CreateEventA
Packit Service 5a9772
#define CreateEventEx CreateEventExA
Packit Service 5a9772
#define OpenEvent OpenEventA
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	/* Condition Variable */
Packit 1fb8d4
Packit Service 5a9772
	typedef PVOID RTL_CONDITION_VARIABLE;
Packit Service 5a9772
	typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE, *PCONDITION_VARIABLE;
Packit 1fb8d4
Packit Service 5a9772
	/* Critical Section */
Packit 1fb8d4
Packit Service 5a9772
	typedef struct _RTL_CRITICAL_SECTION
Packit Service 5a9772
	{
Packit Service 5a9772
		PVOID DebugInfo;
Packit Service 5a9772
		LONG LockCount;
Packit Service 5a9772
		LONG RecursionCount;
Packit Service 5a9772
		HANDLE OwningThread;
Packit Service 5a9772
		HANDLE LockSemaphore;
Packit Service 5a9772
		ULONG_PTR SpinCount;
Packit Service 5a9772
	} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
Packit 1fb8d4
Packit Service 5a9772
	typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
Packit Service 5a9772
	typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
Packit Service 5a9772
	typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
Packit Service 5a9772
	WINPR_API BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection,
Packit Service 5a9772
	                                           DWORD dwSpinCount, DWORD Flags);
Packit Service 5a9772
	WINPR_API BOOL InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection,
Packit Service 5a9772
	                                                     DWORD dwSpinCount);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API DWORD SetCriticalSectionSpinCount(LPCRITICAL_SECTION lpCriticalSection,
Packit Service 5a9772
	                                            DWORD dwSpinCount);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
Packit Service 5a9772
	WINPR_API BOOL TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
Packit 1fb8d4
Packit Service 5a9772
	/* Sleep */
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID Sleep(DWORD dwMilliseconds);
Packit Service 5a9772
	WINPR_API DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable);
Packit 1fb8d4
Packit Service 5a9772
	/* Address */
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID WakeByAddressAll(PVOID Address);
Packit Service 5a9772
	WINPR_API VOID WakeByAddressSingle(PVOID Address);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API BOOL WaitOnAddress(VOID volatile* Address, PVOID CompareAddress, SIZE_T AddressSize,
Packit Service 5a9772
	                             DWORD dwMilliseconds);
Packit 1fb8d4
Packit Service 5a9772
	/* Wait */
Packit 1fb8d4
Packit Service 5a9772
#define INFINITE 0xFFFFFFFF
Packit 1fb8d4
Packit Service 5a9772
#define WAIT_OBJECT_0 0x00000000L
Packit Service 5a9772
#define WAIT_ABANDONED 0x00000080L
Packit 1fb8d4
Packit 1fb8d4
#ifndef WAIT_TIMEOUT
Packit Service 5a9772
#define WAIT_TIMEOUT 0x00000102L
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
Packit 1fb8d4
Packit Service 5a9772
#define MAXIMUM_WAIT_OBJECTS 64
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
Packit Service 5a9772
	WINPR_API DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable);
Packit Service 5a9772
	WINPR_API DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll,
Packit Service 5a9772
	                                       DWORD dwMilliseconds);
Packit Service 5a9772
	WINPR_API DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll,
Packit Service 5a9772
	                                         DWORD dwMilliseconds, BOOL bAlertable);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn,
Packit Service 5a9772
	                                    DWORD dwMilliseconds, BOOL bAlertable);
Packit 1fb8d4
Packit Service 5a9772
	/* Waitable Timer */
Packit 1fb8d4
Packit Service 5a9772
#define CREATE_WAITABLE_TIMER_MANUAL_RESET 0x00000001
Packit 1fb8d4
Packit Service 5a9772
	typedef struct _REASON_CONTEXT
Packit 1fb8d4
	{
Packit Service 5a9772
		ULONG Version;
Packit Service 5a9772
		DWORD Flags;
Packit Service 5a9772
Packit Service 5a9772
		union {
Packit Service 5a9772
			struct
Packit Service 5a9772
			{
Packit Service 5a9772
				HMODULE LocalizedReasonModule;
Packit Service 5a9772
				ULONG LocalizedReasonId;
Packit Service 5a9772
				ULONG ReasonStringCount;
Packit Service 5a9772
				LPWSTR* ReasonStrings;
Packit Service 5a9772
			} Detailed;
Packit Service 5a9772
Packit Service 5a9772
			LPWSTR SimpleReasonString;
Packit Service 5a9772
		} Reason;
Packit Service 5a9772
	} REASON_CONTEXT, *PREASON_CONTEXT;
Packit Service 5a9772
Packit Service 5a9772
	typedef VOID (*PTIMERAPCROUTINE)(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue,
Packit Service 5a9772
	                                 DWORD dwTimerHighValue);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes,
Packit Service 5a9772
	                                      BOOL bManualReset, LPCSTR lpTimerName);
Packit Service 5a9772
	WINPR_API HANDLE CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes,
Packit Service 5a9772
	                                      BOOL bManualReset, LPCWSTR lpTimerName);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes,
Packit Service 5a9772
	                                        LPCSTR lpTimerName, DWORD dwFlags,
Packit Service 5a9772
	                                        DWORD dwDesiredAccess);
Packit Service 5a9772
	WINPR_API HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes,
Packit Service 5a9772
	                                        LPCWSTR lpTimerName, DWORD dwFlags,
Packit Service 5a9772
	                                        DWORD dwDesiredAccess);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod,
Packit Service 5a9772
	                                PTIMERAPCROUTINE pfnCompletionRoutine,
Packit Service 5a9772
	                                LPVOID lpArgToCompletionRoutine, BOOL fResume);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API BOOL SetWaitableTimerEx(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod,
Packit Service 5a9772
	                                  PTIMERAPCROUTINE pfnCompletionRoutine,
Packit Service 5a9772
	                                  LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext,
Packit Service 5a9772
	                                  ULONG TolerableDelay);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API HANDLE OpenWaitableTimerA(DWORD dwDesiredAccess, BOOL bInheritHandle,
Packit Service 5a9772
	                                    LPCSTR lpTimerName);
Packit Service 5a9772
	WINPR_API HANDLE OpenWaitableTimerW(DWORD dwDesiredAccess, BOOL bInheritHandle,
Packit Service 5a9772
	                                    LPCWSTR lpTimerName);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API BOOL CancelWaitableTimer(HANDLE hTimer);
Packit 1fb8d4
Packit 1fb8d4
#ifdef UNICODE
Packit Service 5a9772
#define CreateWaitableTimer CreateWaitableTimerW
Packit Service 5a9772
#define CreateWaitableTimerEx CreateWaitableTimerExW
Packit Service 5a9772
#define OpenWaitableTimer OpenWaitableTimerW
Packit 1fb8d4
#else
Packit Service 5a9772
#define CreateWaitableTimer CreateWaitableTimerA
Packit Service 5a9772
#define CreateWaitableTimerEx CreateWaitableTimerExA
Packit Service 5a9772
#define OpenWaitableTimer OpenWaitableTimerA
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	/**
Packit Service 5a9772
	 * Timer-Queue Timer
Packit Service 5a9772
	 */
Packit Service 5a9772
Packit Service 5a9772
#define WT_EXECUTEDEFAULT 0x00000000
Packit Service 5a9772
#define WT_EXECUTEINIOTHREAD 0x00000001
Packit Service 5a9772
#define WT_EXECUTEINUITHREAD 0x00000002
Packit Service 5a9772
#define WT_EXECUTEINWAITTHREAD 0x00000004
Packit Service 5a9772
#define WT_EXECUTEONLYONCE 0x00000008
Packit Service 5a9772
#define WT_EXECUTELONGFUNCTION 0x00000010
Packit Service 5a9772
#define WT_EXECUTEINTIMERTHREAD 0x00000020
Packit Service 5a9772
#define WT_EXECUTEINPERSISTENTIOTHREAD 0x00000040
Packit Service 5a9772
#define WT_EXECUTEINPERSISTENTTHREAD 0x00000080
Packit Service 5a9772
#define WT_TRANSFER_IMPERSONATION 0x00000100
Packit Service 5a9772
Packit Service 5a9772
	typedef VOID (*WAITORTIMERCALLBACK)(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API HANDLE CreateTimerQueue(void);
Packit Service 5a9772
	WINPR_API BOOL DeleteTimerQueue(HANDLE TimerQueue);
Packit Service 5a9772
	WINPR_API BOOL DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent);
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API BOOL CreateTimerQueueTimer(PHANDLE phNewTimer, HANDLE TimerQueue,
Packit Service 5a9772
	                                     WAITORTIMERCALLBACK Callback, PVOID Parameter,
Packit Service 5a9772
	                                     DWORD DueTime, DWORD Period, ULONG Flags);
Packit Service 5a9772
	WINPR_API BOOL ChangeTimerQueueTimer(HANDLE TimerQueue, HANDLE Timer, ULONG DueTime,
Packit Service 5a9772
	                                     ULONG Period);
Packit Service 5a9772
	WINPR_API BOOL DeleteTimerQueueTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE CompletionEvent);
Packit 1fb8d4
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#if (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
Packit Service 5a9772
#define InitializeCriticalSectionEx(lpCriticalSection, dwSpinCount, Flags) \
Packit Service 5a9772
	InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount)
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#ifndef _RTL_RUN_ONCE_DEF
Packit 1fb8d4
#define _RTL_RUN_ONCE_DEF
Packit 1fb8d4
Packit Service 5a9772
#define RTL_RUN_ONCE_INIT \
Packit Service 5a9772
	{                     \
Packit Service 5a9772
		0                 \
Packit Service 5a9772
	}
Packit 1fb8d4
Packit Service 5a9772
#define RTL_RUN_ONCE_CHECK_ONLY 0x00000001
Packit Service 5a9772
#define RTL_RUN_ONCE_ASYNC 0x00000002
Packit Service 5a9772
#define RTL_RUN_ONCE_INIT_FAILED 0x00000004
Packit 1fb8d4
Packit Service 5a9772
#define RTL_RUN_ONCE_CTX_RESERVED_BITS 2
Packit 1fb8d4
Packit Service 5a9772
	typedef struct _RTL_RUN_ONCE
Packit Service 5a9772
	{
Packit Service 5a9772
		PVOID Ptr;
Packit Service 5a9772
	} RTL_RUN_ONCE, *PRTL_RUN_ONCE;
Packit 1fb8d4
Packit Service 5a9772
	typedef ULONG CALLBACK RTL_RUN_ONCE_INIT_FN(PRTL_RUN_ONCE RunOnce, PVOID Parameter,
Packit Service 5a9772
	                                            PVOID* Context);
Packit Service 5a9772
	typedef RTL_RUN_ONCE_INIT_FN* PRTL_RUN_ONCE_INIT_FN;
Packit 1fb8d4
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
Packit 1fb8d4
Packit Service 5a9772
	/* One-Time Initialization */
Packit 1fb8d4
Packit Service 5a9772
#define INIT_ONCE_STATIC_INIT RTL_RUN_ONCE_INIT
Packit 1fb8d4
Packit Service 5a9772
	typedef RTL_RUN_ONCE INIT_ONCE;
Packit Service 5a9772
	typedef PRTL_RUN_ONCE PINIT_ONCE;
Packit Service 5a9772
	typedef PRTL_RUN_ONCE LPINIT_ONCE;
Packit Service 5a9772
	typedef BOOL(CALLBACK* PINIT_ONCE_FN)(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API BOOL winpr_InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags,
Packit Service 5a9772
	                                             PBOOL fPending, LPVOID* lpContext);
Packit Service 5a9772
	WINPR_API BOOL winpr_InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext);
Packit Service 5a9772
	WINPR_API BOOL winpr_InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn,
Packit Service 5a9772
	                                         PVOID Parameter, LPVOID* Context);
Packit Service 5a9772
	WINPR_API VOID winpr_InitOnceInitialize(PINIT_ONCE InitOnce);
Packit 1fb8d4
Packit 1fb8d4
#define InitOnceBeginInitialize winpr_InitOnceBeginInitialize
Packit 1fb8d4
#define InitOnceComplete winpr_InitOnceComplete
Packit 1fb8d4
#define InitOnceExecuteOnce winpr_InitOnceExecuteOnce
Packit 1fb8d4
#define InitOnceInitialize winpr_InitOnceInitialize
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	/* Synchronization Barrier */
Packit 1fb8d4
Packit 1fb8d4
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0602) && !defined(_SYNCHAPI_H_))
Packit Service 5a9772
#define WINPR_SYNCHRONIZATION_BARRIER 1
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#ifdef WINPR_SYNCHRONIZATION_BARRIER
Packit 1fb8d4
Packit Service 5a9772
	typedef struct _RTL_BARRIER
Packit Service 5a9772
	{
Packit Service 5a9772
		DWORD Reserved1;
Packit Service 5a9772
		DWORD Reserved2;
Packit Service 5a9772
		ULONG_PTR Reserved3[2];
Packit Service 5a9772
		DWORD Reserved4;
Packit Service 5a9772
		DWORD Reserved5;
Packit Service 5a9772
	} RTL_BARRIER, *PRTL_BARRIER;
Packit Service 5a9772
Packit Service 5a9772
	typedef RTL_BARRIER SYNCHRONIZATION_BARRIER;
Packit Service 5a9772
	typedef PRTL_BARRIER PSYNCHRONIZATION_BARRIER;
Packit Service 5a9772
	typedef PRTL_BARRIER LPSYNCHRONIZATION_BARRIER;
Packit Service 5a9772
Packit Service 5a9772
#define SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY 0x01
Packit Service 5a9772
#define SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY 0x02
Packit Service 5a9772
#define SYNCHRONIZATION_BARRIER_FLAGS_NO_DELETE 0x04
Packit Service 5a9772
Packit Service 5a9772
	WINPR_API BOOL WINAPI winpr_InitializeSynchronizationBarrier(
Packit Service 5a9772
	    LPSYNCHRONIZATION_BARRIER lpBarrier, LONG lTotalThreads, LONG lSpinCount);
Packit Service 5a9772
	WINPR_API BOOL WINAPI winpr_EnterSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier,
Packit Service 5a9772
	                                                        DWORD dwFlags);
Packit Service 5a9772
	WINPR_API BOOL WINAPI winpr_DeleteSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier);
Packit 1fb8d4
Packit 1fb8d4
#define InitializeSynchronizationBarrier winpr_InitializeSynchronizationBarrier
Packit 1fb8d4
#define EnterSynchronizationBarrier winpr_EnterSynchronizationBarrier
Packit 1fb8d4
#define DeleteSynchronizationBarrier winpr_DeleteSynchronizationBarrier
Packit 1fb8d4
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	/* Extended API */
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API VOID USleep(DWORD dwMicroseconds);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,
Packit Service 5a9772
	                                            BOOL bManualReset, BOOL bInitialState,
Packit Service 5a9772
	                                            int FileDescriptor, ULONG mode);
Packit Service 5a9772
	WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
Packit Service 5a9772
	                                            BOOL bManualReset, BOOL bInitialState,
Packit Service 5a9772
	                                            int FileDescriptor, ULONG mode);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
Packit Service 5a9772
	                                       BOOL bManualReset, BOOL bInitialState, void* pObject);
Packit 1fb8d4
Packit 1fb8d4
#ifdef UNICODE
Packit Service 5a9772
#define CreateFileDescriptorEvent CreateFileDescriptorEventW
Packit 1fb8d4
#else
Packit Service 5a9772
#define CreateFileDescriptorEvent CreateFileDescriptorEventA
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API int GetEventFileDescriptor(HANDLE hEvent);
Packit Service 5a9772
	WINPR_API int SetEventFileDescriptor(HANDLE hEvent, int FileDescriptor, ULONG mode);
Packit 1fb8d4
Packit Service 5a9772
	WINPR_API void* GetEventWaitObject(HANDLE hEvent);
Packit 1fb8d4
Packit 1fb8d4
#ifdef __cplusplus
Packit 1fb8d4
}
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#endif /* WINPR_SYNCH_H */