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