1*4e72da08STimo Kreuzer #include "k32_vista.h"
2*4e72da08STimo Kreuzer 
3*4e72da08STimo Kreuzer #define NDEBUG
4*4e72da08STimo Kreuzer #include <debug.h>
5*4e72da08STimo Kreuzer 
6*4e72da08STimo Kreuzer VOID
7*4e72da08STimo Kreuzer WINAPI
AcquireSRWLockExclusive(PSRWLOCK Lock)8*4e72da08STimo Kreuzer AcquireSRWLockExclusive(PSRWLOCK Lock)
9*4e72da08STimo Kreuzer {
10*4e72da08STimo Kreuzer     RtlAcquireSRWLockExclusive((PRTL_SRWLOCK)Lock);
11*4e72da08STimo Kreuzer }
12*4e72da08STimo Kreuzer 
13*4e72da08STimo Kreuzer VOID
14*4e72da08STimo Kreuzer WINAPI
AcquireSRWLockShared(PSRWLOCK Lock)15*4e72da08STimo Kreuzer AcquireSRWLockShared(PSRWLOCK Lock)
16*4e72da08STimo Kreuzer {
17*4e72da08STimo Kreuzer     RtlAcquireSRWLockShared((PRTL_SRWLOCK)Lock);
18*4e72da08STimo Kreuzer }
19*4e72da08STimo Kreuzer 
20*4e72da08STimo Kreuzer VOID
21*4e72da08STimo Kreuzer WINAPI
InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)22*4e72da08STimo Kreuzer InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
23*4e72da08STimo Kreuzer {
24*4e72da08STimo Kreuzer     RtlInitializeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
25*4e72da08STimo Kreuzer }
26*4e72da08STimo Kreuzer 
27*4e72da08STimo Kreuzer VOID
28*4e72da08STimo Kreuzer WINAPI
InitializeSRWLock(PSRWLOCK Lock)29*4e72da08STimo Kreuzer InitializeSRWLock(PSRWLOCK Lock)
30*4e72da08STimo Kreuzer {
31*4e72da08STimo Kreuzer     RtlInitializeSRWLock((PRTL_SRWLOCK)Lock);
32*4e72da08STimo Kreuzer }
33*4e72da08STimo Kreuzer 
34*4e72da08STimo Kreuzer VOID
35*4e72da08STimo Kreuzer WINAPI
ReleaseSRWLockExclusive(PSRWLOCK Lock)36*4e72da08STimo Kreuzer ReleaseSRWLockExclusive(PSRWLOCK Lock)
37*4e72da08STimo Kreuzer {
38*4e72da08STimo Kreuzer     RtlReleaseSRWLockExclusive((PRTL_SRWLOCK)Lock);
39*4e72da08STimo Kreuzer }
40*4e72da08STimo Kreuzer 
41*4e72da08STimo Kreuzer VOID
42*4e72da08STimo Kreuzer WINAPI
ReleaseSRWLockShared(PSRWLOCK Lock)43*4e72da08STimo Kreuzer ReleaseSRWLockShared(PSRWLOCK Lock)
44*4e72da08STimo Kreuzer {
45*4e72da08STimo Kreuzer     RtlReleaseSRWLockShared((PRTL_SRWLOCK)Lock);
46*4e72da08STimo Kreuzer }
47*4e72da08STimo Kreuzer 
48*4e72da08STimo Kreuzer FORCEINLINE
49*4e72da08STimo Kreuzer PLARGE_INTEGER
GetNtTimeout(PLARGE_INTEGER Time,DWORD Timeout)50*4e72da08STimo Kreuzer GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
51*4e72da08STimo Kreuzer {
52*4e72da08STimo Kreuzer     if (Timeout == INFINITE) return NULL;
53*4e72da08STimo Kreuzer     Time->QuadPart = (ULONGLONG)Timeout * -10000;
54*4e72da08STimo Kreuzer     return Time;
55*4e72da08STimo Kreuzer }
56*4e72da08STimo Kreuzer 
57*4e72da08STimo Kreuzer BOOL
58*4e72da08STimo Kreuzer WINAPI
SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable,PCRITICAL_SECTION CriticalSection,DWORD Timeout)59*4e72da08STimo Kreuzer SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
60*4e72da08STimo Kreuzer {
61*4e72da08STimo Kreuzer     NTSTATUS Status;
62*4e72da08STimo Kreuzer     LARGE_INTEGER Time;
63*4e72da08STimo Kreuzer 
64*4e72da08STimo Kreuzer     Status = RtlSleepConditionVariableCS(ConditionVariable, (PRTL_CRITICAL_SECTION)CriticalSection, GetNtTimeout(&Time, Timeout));
65*4e72da08STimo Kreuzer     if (!NT_SUCCESS(Status) || Status == STATUS_TIMEOUT)
66*4e72da08STimo Kreuzer     {
67*4e72da08STimo Kreuzer         SetLastError(RtlNtStatusToDosError(Status));
68*4e72da08STimo Kreuzer         return FALSE;
69*4e72da08STimo Kreuzer     }
70*4e72da08STimo Kreuzer     return TRUE;
71*4e72da08STimo Kreuzer }
72*4e72da08STimo Kreuzer 
73*4e72da08STimo Kreuzer BOOL
74*4e72da08STimo Kreuzer WINAPI
SleepConditionVariableSRW(PCONDITION_VARIABLE ConditionVariable,PSRWLOCK Lock,DWORD Timeout,ULONG Flags)75*4e72da08STimo Kreuzer SleepConditionVariableSRW(PCONDITION_VARIABLE ConditionVariable, PSRWLOCK Lock, DWORD Timeout, ULONG Flags)
76*4e72da08STimo Kreuzer {
77*4e72da08STimo Kreuzer     NTSTATUS Status;
78*4e72da08STimo Kreuzer     LARGE_INTEGER Time;
79*4e72da08STimo Kreuzer 
80*4e72da08STimo Kreuzer     Status = RtlSleepConditionVariableSRW(ConditionVariable, Lock, GetNtTimeout(&Time, Timeout), Flags);
81*4e72da08STimo Kreuzer     if (!NT_SUCCESS(Status) || Status == STATUS_TIMEOUT)
82*4e72da08STimo Kreuzer     {
83*4e72da08STimo Kreuzer         SetLastError(RtlNtStatusToDosError(Status));
84*4e72da08STimo Kreuzer         return FALSE;
85*4e72da08STimo Kreuzer     }
86*4e72da08STimo Kreuzer     return TRUE;
87*4e72da08STimo Kreuzer }
88*4e72da08STimo Kreuzer 
89*4e72da08STimo Kreuzer VOID
90*4e72da08STimo Kreuzer WINAPI
WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)91*4e72da08STimo Kreuzer WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)
92*4e72da08STimo Kreuzer {
93*4e72da08STimo Kreuzer     RtlWakeAllConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
94*4e72da08STimo Kreuzer }
95*4e72da08STimo Kreuzer 
96*4e72da08STimo Kreuzer VOID
97*4e72da08STimo Kreuzer WINAPI
WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)98*4e72da08STimo Kreuzer WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
99*4e72da08STimo Kreuzer {
100*4e72da08STimo Kreuzer     RtlWakeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
101*4e72da08STimo Kreuzer }
102*4e72da08STimo Kreuzer 
103*4e72da08STimo Kreuzer 
104*4e72da08STimo Kreuzer /*
105*4e72da08STimo Kreuzer * @implemented
106*4e72da08STimo Kreuzer */
InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection,IN DWORD dwSpinCount,IN DWORD flags)107*4e72da08STimo Kreuzer BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection,
108*4e72da08STimo Kreuzer                                         IN DWORD dwSpinCount,
109*4e72da08STimo Kreuzer                                         IN DWORD flags)
110*4e72da08STimo Kreuzer {
111*4e72da08STimo Kreuzer     NTSTATUS Status;
112*4e72da08STimo Kreuzer 
113*4e72da08STimo Kreuzer     /* FIXME: Flags ignored */
114*4e72da08STimo Kreuzer 
115*4e72da08STimo Kreuzer     /* Initialize the critical section */
116*4e72da08STimo Kreuzer     Status = RtlInitializeCriticalSectionAndSpinCount(
117*4e72da08STimo Kreuzer         (PRTL_CRITICAL_SECTION)lpCriticalSection,
118*4e72da08STimo Kreuzer         dwSpinCount);
119*4e72da08STimo Kreuzer     if (!NT_SUCCESS(Status))
120*4e72da08STimo Kreuzer     {
121*4e72da08STimo Kreuzer         /* Set failure code */
122*4e72da08STimo Kreuzer         SetLastError(RtlNtStatusToDosError(Status));
123*4e72da08STimo Kreuzer         return FALSE;
124*4e72da08STimo Kreuzer     }
125*4e72da08STimo Kreuzer 
126*4e72da08STimo Kreuzer     /* Success */
127*4e72da08STimo Kreuzer     return TRUE;
128*4e72da08STimo Kreuzer }
129*4e72da08STimo Kreuzer 
130