diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-07-17 19:24:28 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-07-17 20:13:56 +0200 |
commit | 6bd2c7bb386de16310fa5534275e6e638be60862 (patch) | |
tree | 0a12144dfb4e8d1b069bc09d583b522b5c158b28 /src/libstore/pathlocks.cc | |
parent | 1511aa9f488ba0762c2da0bf8ab61b5fde47305d (diff) |
OCD: foreach -> C++11 ranged for
Diffstat (limited to 'src/libstore/pathlocks.cc')
-rw-r--r-- | src/libstore/pathlocks.cc | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 9db37e8f9..1c87034f8 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -60,7 +60,7 @@ bool lockFile(int fd, LockType lockType, bool wait) while (fcntl(fd, F_SETLK, &lock) != 0) { checkInterrupt(); if (errno == EACCES || errno == EAGAIN) return false; - if (errno != EINTR) + if (errno != EINTR) throw SysError(format("acquiring/releasing lock")); } } @@ -94,7 +94,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg, bool wait) { assert(fds.empty()); - + /* Note that `fds' is built incrementally so that the destructor will only release those locks that we have already acquired. */ @@ -102,11 +102,10 @@ bool PathLocks::lockPaths(const PathSet & _paths, the same order, thus preventing deadlocks. */ Paths paths(_paths.begin(), _paths.end()); paths.sort(); - + /* Acquire the lock for each path. */ - foreach (Paths::iterator, i, paths) { + for (auto & path : paths) { checkInterrupt(); - Path path = *i; Path lockPath = path + ".lock"; debug(format("locking path ‘%1%’") % path); @@ -115,11 +114,11 @@ bool PathLocks::lockPaths(const PathSet & _paths, throw Error("deadlock: trying to re-acquire self-held lock"); AutoCloseFD fd; - + while (1) { /* Open/create the lock file. */ - fd = openLockFile(lockPath, true); + fd = openLockFile(lockPath, true); /* Acquire an exclusive lock. */ if (!lockFile(fd, ltWrite, false)) { @@ -168,15 +167,15 @@ PathLocks::~PathLocks() void PathLocks::unlock() { - foreach (list<FDPair>::iterator, i, fds) { - if (deletePaths) deleteLockFile(i->second, i->first); + for (auto & i : fds) { + if (deletePaths) deleteLockFile(i.second, i.first); - lockedPaths.erase(i->second); - if (close(i->first) == -1) + lockedPaths.erase(i.second); + if (close(i.first) == -1) printMsg(lvlError, - format("error (ignored): cannot close lock file on ‘%1%’") % i->second); + format("error (ignored): cannot close lock file on ‘%1%’") % i.second); - debug(format("lock released on ‘%1%’") % i->second); + debug(format("lock released on ‘%1%’") % i.second); } fds.clear(); @@ -195,5 +194,5 @@ bool pathIsLockedByMe(const Path & path) return lockedPaths.find(lockPath) != lockedPaths.end(); } - + } |