From 5a1191300ccd289813a4b71d504ebdb495e7132c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 2 Jul 2009 21:16:24 -0400 Subject: [PATCH] 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). --- src/TDB.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TDB.cpp b/src/TDB.cpp index e4fd78dbb..06977aa1c 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -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_EX) && ++retry <= 3) - delay (0.1); + 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.2); + } if (retry > 3) throw std::string ("Could not lock '") + file + "'.";