[KERNEL32_VISTA]
authorPierre Schweitzer <pierre@reactos.org>
Tue, 30 May 2017 21:39:50 +0000 (21:39 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 30 May 2017 21:39:50 +0000 (21:39 +0000)
Add Kernel32 implementation for SRW locks and condition variables.
This is based on Wine implementation.

CORE-7546
CORE-8204

svn path=/trunk/; revision=74705

reactos/dll/win32/kernel32_vista/CMakeLists.txt
reactos/dll/win32/kernel32_vista/kernel32_vista.spec
reactos/dll/win32/kernel32_vista/sync.c [new file with mode: 0644]

index 57333ff..064ee48 100644 (file)
@@ -10,10 +10,11 @@ list(APPEND SOURCE
     GetFileInformationByHandleEx.c
     GetTickCount64.c
     InitOnceExecuteOnce.c
+    sync.c
     ${CMAKE_CURRENT_BINARY_DIR}/kernel32_vista.def)
 
 add_library(kernel32_vista SHARED ${SOURCE})
 set_module_type(kernel32_vista win32dll ENTRYPOINT DllMain 12)
-add_importlibs(kernel32_vista kernel32 ntdll)
+add_importlibs(kernel32_vista kernel32 ntdll_vista ntdll)
 add_dependencies(kernel32_vista psdk)
 add_cd_file(TARGET kernel32_vista DESTINATION reactos/system32 FOR all)
index c046b0e..caa7adc 100644 (file)
@@ -2,3 +2,15 @@
 @ stdcall InitOnceExecuteOnce(ptr ptr ptr ptr)
 @ stdcall GetFileInformationByHandleEx(long long ptr long)
 @ stdcall -ret64 GetTickCount64()
+
+@ stdcall InitializeSRWLock(ptr)
+@ stdcall AcquireSRWLockExclusive(ptr)
+@ stdcall AcquireSRWLockShared(ptr)
+@ stdcall ReleaseSRWLockExclusive(ptr)
+@ stdcall ReleaseSRWLockShared(ptr)
+
+@ stdcall InitializeConditionVariable(ptr)
+@ stdcall SleepConditionVariableCS(ptr ptr long)
+@ stdcall SleepConditionVariableSRW(ptr ptr long long)
+@ stdcall WakeAllConditionVariable(ptr)
+@ stdcall WakeConditionVariable(ptr)
diff --git a/reactos/dll/win32/kernel32_vista/sync.c b/reactos/dll/win32/kernel32_vista/sync.c
new file mode 100644 (file)
index 0000000..a13f984
--- /dev/null
@@ -0,0 +1,150 @@
+#include "k32_vista.h"
+
+#define NDEBUG
+#include <debug.h>
+
+VOID
+NTAPI
+RtlInitializeConditionVariable(OUT PRTL_CONDITION_VARIABLE ConditionVariable);
+
+VOID
+NTAPI
+RtlWakeConditionVariable(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable);
+
+VOID
+NTAPI
+RtlWakeAllConditionVariable(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable);
+
+NTSTATUS
+NTAPI
+RtlSleepConditionVariableCS(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable,
+                            IN OUT PRTL_CRITICAL_SECTION CriticalSection,
+                            IN PLARGE_INTEGER TimeOut OPTIONAL);
+
+NTSTATUS
+NTAPI
+RtlSleepConditionVariableSRW(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable,
+                             IN OUT PRTL_SRWLOCK SRWLock,
+                             IN PLARGE_INTEGER TimeOut OPTIONAL,
+                             IN ULONG Flags);
+
+VOID
+NTAPI
+RtlInitializeSRWLock(OUT PRTL_SRWLOCK SRWLock);
+
+VOID
+NTAPI
+RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock);
+
+VOID
+NTAPI
+RtlReleaseSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock);
+
+VOID
+NTAPI
+RtlAcquireSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock);
+
+VOID
+NTAPI
+RtlReleaseSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock);
+
+ULONG
+NTAPI
+RtlNtStatusToDosError(IN NTSTATUS Status);
+
+VOID
+WINAPI
+AcquireSRWLockExclusive(PSRWLOCK Lock)
+{
+    RtlAcquireSRWLockExclusive((PRTL_SRWLOCK)Lock);
+}
+
+VOID
+WINAPI
+AcquireSRWLockShared(PSRWLOCK Lock)
+{
+    RtlAcquireSRWLockShared((PRTL_SRWLOCK)Lock);
+}
+
+VOID
+WINAPI
+InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
+{
+    RtlInitializeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
+}
+
+VOID
+WINAPI
+InitializeSRWLock(PSRWLOCK Lock)
+{
+    RtlInitializeSRWLock((PRTL_SRWLOCK)Lock);
+}
+
+VOID
+WINAPI
+ReleaseSRWLockExclusive(PSRWLOCK Lock)
+{
+    RtlReleaseSRWLockExclusive((PRTL_SRWLOCK)Lock);
+}
+
+VOID
+WINAPI
+ReleaseSRWLockShared(PSRWLOCK Lock)
+{
+    RtlReleaseSRWLockShared((PRTL_SRWLOCK)Lock);
+}
+
+FORCEINLINE
+PLARGE_INTEGER
+GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
+{
+    if (Timeout == INFINITE) return NULL;
+    Time->QuadPart = (ULONGLONG)Timeout * -10000;
+    return Time;
+}
+
+BOOL
+WINAPI
+SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
+{
+    NTSTATUS Status;
+    LARGE_INTEGER Time;
+
+    Status = RtlSleepConditionVariableCS(ConditionVariable, (PRTL_CRITICAL_SECTION)CriticalSection, GetNtTimeout(&Time, Timeout));
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastError(RtlNtStatusToDosError(Status));
+        return FALSE;
+    }
+    return TRUE;
+}
+
+BOOL
+WINAPI
+SleepConditionVariableSRW(PCONDITION_VARIABLE ConditionVariable, PSRWLOCK Lock, DWORD Timeout, ULONG Flags)
+{
+    NTSTATUS Status;
+    LARGE_INTEGER Time;
+
+    Status = RtlSleepConditionVariableSRW(ConditionVariable, Lock, GetNtTimeout(&Time, Timeout), Flags);
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastError(RtlNtStatusToDosError(Status));
+        return FALSE;
+    }
+    return TRUE;
+}
+
+VOID
+WINAPI
+WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)
+{
+    RtlWakeAllConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
+}
+
+VOID
+WINAPI
+WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
+{
+    RtlWakeConditionVariable((PRTL_CONDITION_VARIABLE)ConditionVariable);
+}