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