FileFd: fix sleeping while mutex is locked
GitOrigin-RevId: fb6b5bb1967a4c144e9393b2ab82ccf6dfe2f15a
This commit is contained in:
parent
ad686717e7
commit
4e03ee1293
@ -301,21 +301,23 @@ Status FileFd::lock(const LockFlags flags, const string &path, int32 max_tries)
|
|||||||
CHECK(flags == LockFlags::Write);
|
CHECK(flags == LockFlags::Write);
|
||||||
VLOG(fd) << "Trying to lock file \"" << path << '"';
|
VLOG(fd) << "Trying to lock file \"" << path << '"';
|
||||||
while (true) {
|
while (true) {
|
||||||
std::unique_lock<std::mutex> lock(in_process_lock_mutex);
|
{ // mutex lock scope
|
||||||
if (locked_files.find(path) != locked_files.end()) {
|
std::lock_guard<std::mutex> lock(in_process_lock_mutex);
|
||||||
if (--max_tries > 0) {
|
if (locked_files.find(path) == locked_files.end()) {
|
||||||
usleep_for(100000);
|
VLOG(fd) << "Lock file \"" << path << '"';
|
||||||
continue;
|
need_local_unlock = true;
|
||||||
|
locked_files.insert(path);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::Error(
|
|
||||||
0, PSLICE() << "Can't lock file \"" << path << "\", because it is already in use by current program");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VLOG(fd) << "Lock file \"" << path << '"';
|
if (--max_tries > 0) {
|
||||||
need_local_unlock = true;
|
usleep_for(100000);
|
||||||
locked_files.insert(path);
|
continue;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
return Status::Error(
|
||||||
|
0, PSLICE() << "Can't lock file \"" << path << "\", because it is already in use by current program");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user