Skip to content

Commit

Permalink
Fix Windows file locks to actually _work_
Browse files Browse the repository at this point in the history
  • Loading branch information
vector-of-bool committed Nov 9, 2019
1 parent 404738a commit 5a38f5f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dds/util/flock.win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ struct lock_data {
auto lockflags = lm == exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
auto failflags = fm == nonblocking ? LOCKFILE_FAIL_IMMEDIATELY : 0;
auto flags = lockflags | failflags;
const auto okay = ::LockFileEx(file.get(), flags, 0, 0, 0, nullptr);
auto hndl = file.get();
OVERLAPPED ovr = {};
const auto okay = ::LockFileEx(hndl, flags, 0, 0, 0, &ovr);
if (!okay) {
cancellation_point();
if (::GetLastError() == ERROR_IO_PENDING) {
Expand All @@ -41,7 +43,8 @@ struct lock_data {
}

void unlock(path_ref p) {
const auto okay = ::UnlockFileEx(file.get(), 0, 0, 0, nullptr);
OVERLAPPED ovr = {};
const auto okay = ::UnlockFileEx(file.get(), 0, 0, 0, &ovr);
if (!okay) {
cancellation_point();
throw std::system_error(std::error_code(::GetLastError(), std::system_category()),
Expand Down

0 comments on commit 5a38f5f

Please sign in to comment.