Skip to content

Commit

Permalink
util: Use unique_ptr in locks map
Browse files Browse the repository at this point in the history
Wrap the boost::interprocess::file_lock in a std::unique_ptr inside
the map that keeps track of per-directory locks.

This fixes a build issue with the clang 4.0.0+boost-1.58.0p8 version combo
on OpenBSD 6.2, and should have no effect otherwise.
  • Loading branch information
laanwj committed Feb 13, 2018
1 parent 9c3ce7a commit ac2bf0f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/util.cpp
Expand Up @@ -380,13 +380,14 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
if (file) fclose(file);

try {
static std::map<std::string, boost::interprocess::file_lock> locks;
boost::interprocess::file_lock& lock = locks.emplace(pathLockFile.string(), pathLockFile.string().c_str()).first->second;
if (!lock.try_lock()) {
static std::map<std::string, std::unique_ptr<boost::interprocess::file_lock>> locks;
std::unique_ptr<boost::interprocess::file_lock> &lock = locks.emplace(pathLockFile.string(),
MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str())).first->second;
if (!lock->try_lock()) {
return false;
}
if (probe_only) {
lock.unlock();
lock->unlock();
}
} catch (const boost::interprocess::interprocess_exception& e) {
return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
Expand Down

0 comments on commit ac2bf0f

Please sign in to comment.