[KERNEL32_VISTA] Export InitializeCriticalSectionEx.
[reactos.git] / dll / win32 / kernel32_vista / sync.c
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 ULONG
52 NTAPI
53 RtlNtStatusToDosError(IN NTSTATUS Status);
54
55 VOID
56 WINAPI
57 AcquireSRWLockExclusive(PSRWLOCK Lock)
58 {
59 RtlAcquireSRWLockExclusive((PRTL_SRWLOCK)Lock);
60 }
61
62 VOID
63 WINAPI
64 AcquireSRWLockShared(PSRWLOCK Lock)
65 {
66 RtlAcquireSRWLockShared((PRTL_SRWLOCK)Lock);
67 }
68
69 VOID
70 WINAPI
71 InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
72 {
73 RtlInitializeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
74 }
75
76 VOID
77 WINAPI
78 InitializeSRWLock(PSRWLOCK Lock)
79 {
80 RtlInitializeSRWLock((PRTL_SRWLOCK)Lock);
81 }
82
83 VOID
84 WINAPI
85 ReleaseSRWLockExclusive(PSRWLOCK Lock)
86 {
87 RtlReleaseSRWLockExclusive((PRTL_SRWLOCK)Lock);
88 }
89
90 VOID
91 WINAPI
92 ReleaseSRWLockShared(PSRWLOCK Lock)
93 {
94 RtlReleaseSRWLockShared((PRTL_SRWLOCK)Lock);
95 }
96
97 FORCEINLINE
98 PLARGE_INTEGER
99 GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
100 {
101 if (Timeout == INFINITE) return NULL;
102 Time->QuadPart = (ULONGLONG)Timeout * -10000;
103 return Time;
104 }
105
106 BOOL
107 WINAPI
108 SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
109 {
110 NTSTATUS Status;
111 LARGE_INTEGER Time;
112
113 Status = RtlSleepConditionVariableCS(ConditionVariable, (PRTL_CRITICAL_SECTION)CriticalSection, GetNtTimeout(&Time, Timeout));
114 if (!NT_SUCCESS(Status))
115 {
116 SetLastError(RtlNtStatusToDosError(Status));
117 return FALSE;
118 }
119 return TRUE;
120 }
121
122 BOOL
123 WINAPI
124 SleepConditionVariableSRW(PCONDITION_VARIABLE ConditionVariable, PSRWLOCK Lock, DWORD Timeout, ULONG Flags)
125 {
126 NTSTATUS Status;
127 LARGE_INTEGER Time;
128
129 Status = RtlSleepConditionVariableSRW(ConditionVariable, Lock, GetNtTimeout(&Time, Timeout), Flags);
130 if (!NT_SUCCESS(Status))
131 {
132 SetLastError(RtlNtStatusToDosError(Status));
133 return FALSE;
134 }
135 return TRUE;
136 }
137
138 VOID
139 WINAPI
140 WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)
141 {
142 RtlWakeAllConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
143 }
144
145 VOID
146 WINAPI
147 WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
148 {
149 RtlWakeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
150 }
151
152
153 /*
154 * @implemented
155 */
156 BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection,
157 IN DWORD dwSpinCount,
158 IN DWORD flags)
159 {
160 NTSTATUS Status;
161
162 /* FIXME: Flags ignored */
163
164 /* Initialize the critical section */
165 Status = RtlInitializeCriticalSectionAndSpinCount(
166 (PRTL_CRITICAL_SECTION)lpCriticalSection,
167 dwSpinCount);
168 if (!NT_SUCCESS(Status))
169 {
170 /* Set failure code */
171 SetLastError(RtlNtStatusToDosError(Status));
172 return FALSE;
173 }
174
175 /* Success */
176 return TRUE;
177 }
178