mdbx: crutch for Windows's UnlockFile().

This commit is contained in:
Leo Yuriev 2017-03-28 17:50:49 +03:00
parent e9ea16a54e
commit 69a6d10a8a

View File

@ -104,12 +104,38 @@ static BOOL flock(mdbx_filehandle_t fd, DWORD flags, off_t offset,
ov.hEvent = 0; ov.hEvent = 0;
ov.Offset = (DWORD)offset; ov.Offset = (DWORD)offset;
ov.OffsetHigh = HIGH_DWORD(offset); ov.OffsetHigh = HIGH_DWORD(offset);
#ifdef MDBX_WINDOWS_UnlockFile_CRUTCH
if (LockFileEx(fd, flags, 0, (DWORD)bytes, HIGH_DWORD(bytes), &ov))
return true;
if ((flags & LOCKFILE_FAIL_IMMEDIATELY) == 0)
return false;
int rc = GetLastError();
if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION)
return false;
/* FIXME: Windows kernel is ugly and mad... */
SwitchToThread();
Sleep(42);
SwitchToThread();
#endif /* MDBX_WINDOWS_UnlockFile_CRUTCH */
return LockFileEx(fd, flags, 0, (DWORD)bytes, HIGH_DWORD(bytes), &ov); return LockFileEx(fd, flags, 0, (DWORD)bytes, HIGH_DWORD(bytes), &ov);
} }
static BOOL funlock(mdbx_filehandle_t fd, off_t offset, size_t bytes) { static BOOL funlock(mdbx_filehandle_t fd, off_t offset, size_t bytes) {
return UnlockFile(fd, (DWORD)offset, HIGH_DWORD(offset), (DWORD)bytes, if (!UnlockFile(fd, (DWORD)offset, HIGH_DWORD(offset), (DWORD)bytes,
HIGH_DWORD(bytes)); HIGH_DWORD(bytes)))
return false;
#ifdef MDBX_WINDOWS_UnlockFile_CRUTCH
/* FIXME: Windows kernel is ugly and mad... */
SwitchToThread();
Sleep(42);
SwitchToThread();
#endif /* MDBX_WINDOWS_UnlockFile_CRUTCH */
return true;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/