diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-05-11 18:05:44 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-05-11 18:05:44 +0000 |
commit | c8d3882cdc8f9e22c58af285c1996265c1af75d5 (patch) | |
tree | bca454268647fa6edf6cd349fc92543b9789d188 /src/libstore/pathlocks.cc | |
parent | aea436503e9126b06cd15acf1f0c6b738ffbc7de (diff) |
* True parallel builds. Nix can now run as many build jobs in
parallel as possible (similar to GNU Make's `-j' switch). This is
useful on SMP systems, but it is especially useful for doing builds
on multiple machines. The idea is that a large derivation is
initiated on one master machine, which then distributes
sub-derivations to any number of slave machines. This should not
happen synchronously or in lock-step, so the master must be capable
of dealing with multiple parallel build jobs. We now have the
infrastructure to support this.
TODO: substitutes are currently broken.
Diffstat (limited to 'src/libstore/pathlocks.cc')
-rw-r--r-- | src/libstore/pathlocks.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index d4f980c64..79ccf7d66 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -45,9 +45,24 @@ bool lockFile(int fd, LockType lockType, bool wait) static StringSet lockedPaths; /* !!! not thread-safe */ -PathLocks::PathLocks(const PathSet & _paths) +PathLocks::PathLocks() : deletePaths(false) { +} + + +PathLocks::PathLocks(const PathSet & paths) + : deletePaths(false) +{ + lockPaths(paths); +} + + +void PathLocks::lockPaths(const PathSet & _paths) +{ + /* May be called only once! */ + assert(this->paths.empty()); + /* Note that `fds' is built incrementally so that the destructor will only release those locks that we have already acquired. */ @@ -80,6 +95,8 @@ PathLocks::PathLocks(const PathSet & _paths) /* Acquire an exclusive lock. */ lockFile(fd, ltWrite, true); + debug(format("lock acquired on `%1%'") % lockPath); + lockedPaths.insert(lockPath); } } @@ -88,7 +105,7 @@ PathLocks::PathLocks(const PathSet & _paths) PathLocks::~PathLocks() { for (list<int>::iterator i = fds.begin(); i != fds.end(); i++) - close(*i); + if (close(*i) != 0) throw SysError("closing fd"); for (Paths::iterator i = paths.begin(); i != paths.end(); i++) { checkInterrupt(); @@ -99,6 +116,7 @@ PathLocks::~PathLocks() the lock file is an optimisation, not a necessity. */ } lockedPaths.erase(*i); + debug(format("lock released on `%1%'") % *i); } } |