diff options
author | Marc Laukien <marc@zeroc.com> | 2002-04-20 14:45:21 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-04-20 14:45:21 +0000 |
commit | 40ae8dd1db6df5efd908e7a40e33cca0ea42d9cf (patch) | |
tree | c745857a4dc22808006e1aca3f01c27090ad88ac /cpp/src | |
parent | Added preliminary implementation of timed read/write trylock for (diff) | |
download | ice-40ae8dd1db6df5efd908e7a40e33cca0ea42d9cf.tar.bz2 ice-40ae8dd1db6df5efd908e7a40e33cca0ea42d9cf.tar.xz ice-40ae8dd1db6df5efd908e7a40e33cca0ea42d9cf.zip |
BusyException; naming fixes
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Outgoing.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 11 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.cpp | 140 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.h | 1 | ||||
-rw-r--r-- | cpp/src/IcePatch/Server.cpp | 8 | ||||
-rw-r--r-- | cpp/src/IceStorm/Flusher.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/Cond.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IceUtil/RWRecMutex.cpp | 14 |
8 files changed, 114 insertions, 68 deletions
diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp index e5f4c9bd672..19582b3d361 100644 --- a/cpp/src/Ice/Outgoing.cpp +++ b/cpp/src/Ice/Outgoing.cpp @@ -113,7 +113,7 @@ IceInternal::Outgoing::invoke() { if (timeout >= 0) { - timedwait(timeout); + timedWait(timeout); if (_state == StateInProgress) { timedOut = true; diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index ce6828f8150..d29aabe2da2 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -194,6 +194,7 @@ IcePatch::Client::run(int argc, char* argv[]) } catch (const FileAccessException& ex) { + cout << endl; // There might still be a non-terminated line on cout. cerr << appName() << ": " << ex << ":\n" << ex.reason << endl; if (router) { @@ -201,6 +202,16 @@ IcePatch::Client::run(int argc, char* argv[]) } return EXIT_FAILURE; } + catch (const BusyException& ex) + { + cout << endl; // There might still be a non-terminated line on cout. + cerr << appName() << ": patching service busy, try again later" << endl; + if (router) + { + router->shutdown(); + } + return EXIT_FAILURE; + } if (router) { diff --git a/cpp/src/IcePatch/IcePatchI.cpp b/cpp/src/IcePatch/IcePatchI.cpp index 126ffd0d72e..f193ffffcf6 100644 --- a/cpp/src/IcePatch/IcePatchI.cpp +++ b/cpp/src/IcePatch/IcePatchI.cpp @@ -21,7 +21,9 @@ IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) : _adapter(adapter), _logger(adapter->getCommunicator()->getLogger()) { - _traceLevel = adapter->getCommunicator()->getProperties()->getPropertyAsInt("IcePatch.Trace.Files"); + PropertiesPtr properties = adapter->getCommunicator()->getProperties(); + _traceLevel = properties->getPropertyAsInt("IcePatch.Trace.Files"); + _busyTimeout = properties->getPropertyAsIntWithDefault("IcePatch.BusyTimeout", 10); } IcePatch::DirectoryI::DirectoryI(const ObjectAdapterPtr& adapter) : @@ -44,8 +46,9 @@ IcePatch::DirectoryI::getContents(const Ice::Current& current) { StringSeq filteredPaths; + try { - IceUtil::RWRecMutex::RLock sync(_globalMutex); + IceUtil::RWRecMutex::TryRLock sync(_globalMutex, _busyTimeout * 1000); string path = identityToPath(current.identity); StringSeq paths = readDirectory(path); filteredPaths.reserve(paths.size() / 3); @@ -57,7 +60,7 @@ IcePatch::DirectoryI::getContents(const Ice::Current& current) equal_range(paths.begin(), paths.end(), removeSuffix(*p)); if (r.first == r.second) { - sync.upgrade(); + sync.timedUpgrade(_busyTimeout * 1000); StringSeq paths2 = readDirectory(path); pair<StringSeq::const_iterator, StringSeq::const_iterator> r2 = equal_range(paths2.begin(), paths2.end(), removeSuffix(*p)); @@ -79,6 +82,10 @@ IcePatch::DirectoryI::getContents(const Ice::Current& current) } } } + catch (const IceUtil::LockedException&) + { + throw BusyException(); + } // // Call describe() outside the thread synchronization, to avoid @@ -112,88 +119,109 @@ IcePatch::RegularI::RegularI(const ObjectAdapterPtr& adapter) : FileDescPtr IcePatch::RegularI::describe(const Ice::Current& current) { - IceUtil::RWRecMutex::RLock sync(_globalMutex); - string path = identityToPath(current.identity); - - FileInfo info = getFileInfo(path, true); - FileInfo infoMD5 = getFileInfo(path + ".md5", false); - if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) + try { - sync.upgrade(); - infoMD5 = getFileInfo(path + ".md5", false); + IceUtil::RWRecMutex::TryRLock sync(_globalMutex, _busyTimeout * 1000); + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoMD5 = getFileInfo(path + ".md5", false); if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) { - createMD5(path); - - if (_traceLevel > 0) + sync.timedUpgrade(_busyTimeout * 1000); + infoMD5 = getFileInfo(path + ".md5", false); + if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) { - Trace out(_logger, "IcePatch"); - out << "created .md5 file for `" << path << "'"; + createMD5(path); + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .md5 file for `" << path << "'"; + } } } + + RegularDescPtr desc = new RegularDesc; + desc->regular = RegularPrx::uncheckedCast(_adapter->createProxy(current.identity)); + desc->md5 = getMD5(path); + return desc; + } + catch (const IceUtil::LockedException&) + { + throw BusyException(); } - - RegularDescPtr desc = new RegularDesc; - desc->regular = RegularPrx::uncheckedCast(_adapter->createProxy(current.identity)); - desc->md5 = getMD5(path); - return desc; } Int IcePatch::RegularI::getBZ2Size(const Ice::Current& current) { - IceUtil::RWRecMutex::RLock sync(_globalMutex); - string path = identityToPath(current.identity); - - FileInfo info = getFileInfo(path, true); - FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); - if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + try { - sync.upgrade(); - infoBZ2 = getFileInfo(path + ".bz2", false); + IceUtil::RWRecMutex::TryRLock sync(_globalMutex, _busyTimeout * 1000); + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - createBZ2(path); - - if (_traceLevel > 0) + sync.timedUpgrade(_busyTimeout * 1000); + infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - Trace out(_logger, "IcePatch"); - out << "created .bz2 file for `" << path << "'"; + createBZ2(path); + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .bz2 file for `" << path << "'"; + } + + // Get the .bz2 file info again, so that we can return the + // size below. This time the .bz2 file must exist, + // otherwise an exception is raised. + infoBZ2 = getFileInfo(path + ".bz2", true); } - - // Get the .bz2 file info again, so that we can return the - // size below. This time the .bz2 file must exist, - // otherwise an exception is raised. - infoBZ2 = getFileInfo(path + ".bz2", true); } + + return infoBZ2.size; + } + catch (const IceUtil::LockedException&) + { + throw BusyException(); } - - return infoBZ2.size; } ByteSeq IcePatch::RegularI::getBZ2(Ice::Int pos, Ice::Int num, const Ice::Current& current) { - IceUtil::RWRecMutex::RLock sync(_globalMutex); - string path = identityToPath(current.identity); - - FileInfo info = getFileInfo(path, true); - FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); - if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + try { - sync.upgrade(); - infoBZ2 = getFileInfo(path + ".bz2", false); + IceUtil::RWRecMutex::TryRLock sync(_globalMutex, _busyTimeout * 1000); + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - createBZ2(path); - - if (_traceLevel > 0) + sync.timedUpgrade(_busyTimeout * 1000); + infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - Trace out(_logger, "IcePatch"); - out << "created .bz2 file for `" << path << "'"; + createBZ2(path); + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .bz2 file for `" << path << "'"; + } } } + + return IcePatch::getBZ2(path, pos, num); + } + catch (const IceUtil::LockedException&) + { + throw BusyException(); } - - return IcePatch::getBZ2(path, pos, num); } diff --git a/cpp/src/IcePatch/IcePatchI.h b/cpp/src/IcePatch/IcePatchI.h index 9b98b614e15..57fd280f749 100644 --- a/cpp/src/IcePatch/IcePatchI.h +++ b/cpp/src/IcePatch/IcePatchI.h @@ -29,6 +29,7 @@ protected: Ice::ObjectAdapterPtr _adapter; Ice::LoggerPtr _logger; Ice::Int _traceLevel; + Ice::Int _busyTimeout; static IceUtil::RWRecMutex _globalMutex; }; diff --git a/cpp/src/IcePatch/Server.cpp b/cpp/src/IcePatch/Server.cpp index c35ffcd4ac7..2b1644eba48 100644 --- a/cpp/src/IcePatch/Server.cpp +++ b/cpp/src/IcePatch/Server.cpp @@ -181,6 +181,12 @@ IcePatch::Updater::run() Error out(_adapter->getCommunicator()->getLogger()); out << "exception during update:\n" << ex << ":\n" << ex.reason; } + catch (const BusyException&) + { + // + // Just loop if we're busy. + // + } catch (const ConnectFailedException&) { // @@ -201,7 +207,7 @@ IcePatch::Updater::run() break; } - timedwait(updatePeriod * 1000); + timedWait(updatePeriod * 1000); } } diff --git a/cpp/src/IceStorm/Flusher.cpp b/cpp/src/IceStorm/Flusher.cpp index 38c6e88f1b6..55931322071 100644 --- a/cpp/src/IceStorm/Flusher.cpp +++ b/cpp/src/IceStorm/Flusher.cpp @@ -61,7 +61,7 @@ public: } else { - timedwait(tout); + timedWait(tout); } if (_destroy) { diff --git a/cpp/src/IceUtil/Cond.cpp b/cpp/src/IceUtil/Cond.cpp index 476e936295e..c08559d8d28 100644 --- a/cpp/src/IceUtil/Cond.cpp +++ b/cpp/src/IceUtil/Cond.cpp @@ -122,7 +122,7 @@ IceUtil::Cond::preWait() const } void -IceUtil::Cond::postWait(bool timedout) const +IceUtil::Cond::postWait(bool timedOut) const { _internal.lock(); _unblocked++; @@ -132,7 +132,7 @@ IceUtil::Cond::postWait(bool timedout) const bool last = --_toUnblock == 0; _internal.unlock(); - if (timedout) + if (timedOut) { _queue.wait(); } diff --git a/cpp/src/IceUtil/RWRecMutex.cpp b/cpp/src/IceUtil/RWRecMutex.cpp index 61fdcf5d731..44942c2cd9e 100644 --- a/cpp/src/IceUtil/RWRecMutex.cpp +++ b/cpp/src/IceUtil/RWRecMutex.cpp @@ -68,7 +68,7 @@ IceUtil::RWRecMutex::timedTryReadlock(int timeout) const // while (_count < 0 || _waitingWriters != 0) { - if (!_readers.timedwait(lock, timeout)) + if (!_readers.timedWait(lock, timeout)) { throw LockedException(__FILE__, __LINE__); } @@ -170,10 +170,10 @@ IceUtil::RWRecMutex::timedTryWritelock(int timeout) const if (_count != 0) { _waitingWriters++; - bool timedout; + bool timedOut; try { - timedout = !_writers.timedwait(lock, timeout); + timedOut = !_writers.timedWait(lock, timeout); } catch(...) { @@ -185,7 +185,7 @@ IceUtil::RWRecMutex::timedTryWritelock(int timeout) const // // If a timeout occurred then the lock wasn't acquired. // - if (timedout) + if (timedOut) { throw LockedException(__FILE__, __LINE__); } @@ -321,10 +321,10 @@ IceUtil::RWRecMutex::timedUpgrade(int timeout) const while (_count != 0) { _waitingWriters++; - bool timedout; + bool timedOut; try { - timedout = !_writers.timedwait(lock, timeout); + timedOut = !_writers.timedWait(lock, timeout); } catch(...) { @@ -337,7 +337,7 @@ IceUtil::RWRecMutex::timedUpgrade(int timeout) const // If a timeout occurred then the lock wasn't acquired. Ensure // that the _count is increased again before returning. // - if (timedout) + if (timedOut) { ++_count; throw LockedException(__FILE__, __LINE__); |