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 | |
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')
-rw-r--r-- | cpp/include/IceUtil/Cond.h | 20 | ||||
-rw-r--r-- | cpp/include/IceUtil/Monitor.h | 6 | ||||
-rw-r--r-- | cpp/slice/IcePatch/IcePatch.ice | 12 | ||||
-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 | ||||
-rw-r--r-- | cpp/test/Glacier/starter/CallbackI.cpp | 2 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/MonitorMutexTest.cpp | 4 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp | 4 |
14 files changed, 140 insertions, 90 deletions
diff --git a/cpp/include/IceUtil/Cond.h b/cpp/include/IceUtil/Cond.h index 010393fbf3a..9c60feafb5a 100644 --- a/cpp/include/IceUtil/Cond.h +++ b/cpp/include/IceUtil/Cond.h @@ -20,7 +20,7 @@ // # include <IceUtil/Mutex.h> // -// See member-template note for waitImpl & timedwaitImpl. +// See member-template note for waitImpl & timedWaitImpl. // # include <IceUtil/RecMutex.h> #endif @@ -109,9 +109,9 @@ public: // timeout. // template <typename Lock> inline bool - timedwait(const Lock& lock, long msec) const + timedWait(const Lock& lock, long msec) const { - return timedwaitImpl(lock._mutex, msec); + return timedWaitImpl(lock._mutex, msec); } private: @@ -120,13 +120,13 @@ private: friend class Monitor<RecMutex>; // - // The Monitor implementation uses waitImpl & timedwaitImpl. + // The Monitor implementation uses waitImpl & timedWaitImpl. // #ifdef _WIN32 // // For some reason under WIN32 with VC6 using a member-template - // for waitImpl & timedwaitImpl results in a link error for + // for waitImpl & timedWaitImpl results in a link error for // RecMutex. // /* @@ -152,7 +152,7 @@ private: } } template <typename M> bool - timedwaitImpl(const M& mutex, long msec) const + timedWaitImpl(const M& mutex, long msec) const { preWait(); @@ -225,7 +225,7 @@ private: // TODO: Should not be inlined, not performance critical. // bool - timedwaitImpl(const RecMutex& mutex, long msec) const + timedWaitImpl(const RecMutex& mutex, long msec) const { preWait(); @@ -249,7 +249,7 @@ private: // TODO: Should not be inlined, not performance critical. // bool - timedwaitImpl(const Mutex& mutex, long msec) const + timedWaitImpl(const Mutex& mutex, long msec) const { preWait(); @@ -272,7 +272,7 @@ private: #else template <typename M> void waitImpl(const M&) const; - template <typename M> bool timedwaitImpl(const M&, long) const; + template <typename M> bool timedWaitImpl(const M&, long) const; #endif @@ -312,7 +312,7 @@ Cond::waitImpl(const M& mutex) const } template <typename M> inline bool -Cond::timedwaitImpl(const M& mutex, long msec) const +Cond::timedWaitImpl(const M& mutex, long msec) const { typedef typename M::LockState LockState; diff --git a/cpp/include/IceUtil/Monitor.h b/cpp/include/IceUtil/Monitor.h index 36b14f9bb58..39b74a08aeb 100644 --- a/cpp/include/IceUtil/Monitor.h +++ b/cpp/include/IceUtil/Monitor.h @@ -43,7 +43,7 @@ public: void trylock() const; void wait() const; - bool timedwait(long) const; + bool timedWait(long) const; void notify(); void notifyAll(); @@ -150,7 +150,7 @@ IceUtil::Monitor<T>::wait() const } template <class T> inline bool -IceUtil::Monitor<T>::timedwait(long msec) const +IceUtil::Monitor<T>::timedWait(long msec) const { // // Perform any pending notifies. @@ -163,7 +163,7 @@ IceUtil::Monitor<T>::timedwait(long msec) const // try { - rc = _cond.timedwaitImpl(_mutex, msec); + rc = _cond.timedWaitImpl(_mutex, msec); // // Reset the nnotify count once wait() returns. diff --git a/cpp/slice/IcePatch/IcePatch.ice b/cpp/slice/IcePatch/IcePatch.ice index e3955eef026..e386579fc38 100644 --- a/cpp/slice/IcePatch/IcePatch.ice +++ b/cpp/slice/IcePatch/IcePatch.ice @@ -21,6 +21,10 @@ exception FileAccessException string reason; }; +exception BusyException +{ +}; + class FileDesc { }; @@ -30,13 +34,13 @@ sequence<FileDesc> FileDescSeq; interface File { FileDesc describe() - throws FileAccessException; + throws FileAccessException, BusyException; }; interface Directory extends File { FileDescSeq getContents() - throws FileAccessException; + throws FileAccessException, BusyException; }; class DirectoryDesc extends FileDesc @@ -47,10 +51,10 @@ class DirectoryDesc extends FileDesc interface Regular extends File { int getBZ2Size() - throws FileAccessException; + throws FileAccessException, BusyException; Ice::ByteSeq getBZ2(int pos, int num) - throws FileAccessException; + throws FileAccessException, BusyException; }; class RegularDesc extends FileDesc 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__); diff --git a/cpp/test/Glacier/starter/CallbackI.cpp b/cpp/test/Glacier/starter/CallbackI.cpp index 2715a09d796..cb34d2a8719 100644 --- a/cpp/test/Glacier/starter/CallbackI.cpp +++ b/cpp/test/Glacier/starter/CallbackI.cpp @@ -45,7 +45,7 @@ CallbackReceiverI::callbackOK() while (!_callback) { - if (!timedwait(5000)) + if (!timedWait(5000)) { return false; } diff --git a/cpp/test/IceUtil/thread/MonitorMutexTest.cpp b/cpp/test/IceUtil/thread/MonitorMutexTest.cpp index 415acfa0ba0..179164e4649 100644 --- a/cpp/test/IceUtil/thread/MonitorMutexTest.cpp +++ b/cpp/test/IceUtil/thread/MonitorMutexTest.cpp @@ -181,9 +181,9 @@ MonitorMutexTest::run() control.join(); control2.join(); - // TEST: timedwait + // TEST: timedWait { Monitor<Mutex>::Lock lock(monitor); - test(!monitor.timedwait(500)); + test(!monitor.timedWait(500)); } } diff --git a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp b/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp index ce9264aca63..59e64e7ca0b 100644 --- a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp +++ b/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp @@ -183,9 +183,9 @@ MonitorRecMutexTest::run() control.join(); control2.join(); - // TEST: timedwait + // TEST: timedWait { Monitor<RecMutex>::Lock lock(monitor); - test(!monitor.timedwait(500)); + test(!monitor.timedWait(500)); } } |