Enhancement - file locking

- While waiting for a lock, display a message to that effect,
  otherwise it looks like task is hung (thanks to John Florian).
This commit is contained in:
Paul Beckingham 2009-07-02 21:16:24 -04:00
parent 73378dd67e
commit 5a1191300c

View file

@ -655,8 +655,12 @@ FILE* TDB::openAndLock (const std::string& file)
// Lock if desired. Try three times before failing.
int retry = 0;
if (mLock)
while (flock (fileno (in), LOCK_NB | LOCK_EX) && ++retry <= 3)
{
std::cout << "Waiting for file lock..." << std::endl;
while (flock (fileno (in), LOCK_EX) && ++retry <= 3)
delay (0.1);
delay (0.2);
}
if (retry > 3)
throw std::string ("Could not lock '") + file + "'.";