Repository :
https://github.com/FarGroup/FarManager
On branch : master
Link :
https://github.com/FarGroup/FarManager/commit/87245ff3167bc20ec7a16ee3f80d13256e171a27
>---------------------------------------------------------------
commit 87245ff3167bc20ec7a16ee3f80d13256e171a27
Author: Alex Alabuzhev <
alab...@gmail.com>
Date: Sat May 9 13:06:59 2026 +0100
Emulate SRW locks for old OSes
SQLite 3.54 uses them, so they can't be stubs anymore
>---------------------------------------------------------------
87245ff3167bc20ec7a16ee3f80d13256e171a27
far/vc_crt_fix_impl.cpp | 54 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/far/vc_crt_fix_impl.cpp b/far/vc_crt_fix_impl.cpp
index b8a294aa5..6b6a55d83 100644
--- a/far/vc_crt_fix_impl.cpp
+++ b/far/vc_crt_fix_impl.cpp
@@ -340,6 +340,45 @@ extern "C" int WINAPI WRAPPER(LCMapStringEx)(LPCWSTR LocaleName, DWORD MapFlags,
CREATE_AND_RETURN(modules::kernel32, LocaleName, MapFlags, SrcStr, SrcCount, DestStr, DestCount, VersionInformation, Reserved, SortHandle);
}
+namespace srw_lock_impl
+{
+ constexpr uintptr_t EXCLUSIVE_LOCKED = 0x1;
+
+ static void spin_wait(unsigned int Iteration)
+ {
+ if (Iteration < 10)
+ YieldProcessor();
+ else if (Iteration < 20)
+ Sleep(0);
+ else
+ Sleep(1);
+ }
+
+ void initialize(SRWLOCK* SRWLock)
+ {
+ *SRWLock = {};
+ }
+
+ bool try_acquire(SRWLOCK* SRWLock)
+ {
+ return InterlockedCompareExchangePointer(
+ &SRWLock->Ptr,
+ reinterpret_cast<PVOID>(EXCLUSIVE_LOCKED),
+ nullptr) == nullptr;
+ }
+
+ void acquire(SRWLOCK* SRWLock)
+ {
+ for (unsigned int SpinCount = 0; !try_acquire(SRWLock); spin_wait(SpinCount++))
+ ;
+ }
+
+ void release(SRWLOCK* SRWLock)
+ {
+ InterlockedExchangePointer(&SRWLock->Ptr, {});
+ }
+}
+
// VC2022
extern "C" BOOL WINAPI WRAPPER(SleepConditionVariableSRW)(PCONDITION_VARIABLE ConditionVariable, PSRWLOCK SRWLock, DWORD Milliseconds, ULONG Flags)
{
@@ -374,9 +413,9 @@ extern "C" void WINAPI WRAPPER(AcquireSRWLockExclusive)(PSRWLOCK SRWLock)
{
struct implementation
{
- static void WINAPI impl(PSRWLOCK)
+ static void WINAPI impl(PSRWLOCK SRWLock)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ srw_lock_impl::acquire(SRWLock);
}
};
@@ -388,9 +427,9 @@ extern "C" void WINAPI WRAPPER(ReleaseSRWLockExclusive)(PSRWLOCK SRWLock)
{
struct implementation
{
- static void WINAPI impl(PSRWLOCK)
+ static void WINAPI impl(PSRWLOCK SRWLock)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ srw_lock_impl::release(SRWLock);
}
};
@@ -402,10 +441,9 @@ extern "C" BOOLEAN WINAPI WRAPPER(TryAcquireSRWLockExclusive)(PSRWLOCK SRWLock)
{
struct implementation
{
- static BOOLEAN WINAPI impl(PSRWLOCK)
+ static BOOLEAN WINAPI impl(PSRWLOCK SRWLock)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ return srw_lock_impl::try_acquire(SRWLock);
}
};
@@ -419,7 +457,7 @@ extern "C" void WINAPI WRAPPER(InitializeSRWLock)(PSRWLOCK SRWLock)
{
static void WINAPI impl(PSRWLOCK SRWLock)
{
- *SRWLock = SRWLOCK_INIT;
+ srw_lock_impl::initialize(SRWLock);
}
};