mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: crutch for Windows's UnlockFile().
This commit is contained in:
parent
e9ea16a54e
commit
69a6d10a8a
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
Loading…
Reference in New Issue
Block a user