diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-11-23 11:25:31 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-11-23 11:25:31 +0100 |
commit | 183c7a004d0a62ddecd9eeb0bc459846d98a7614 (patch) | |
tree | 32f237ef7da3bb59647a97cc6bf036afb45266a3 /cpp/src/IceGrid/ReapThread.cpp | |
parent | Fixed couple of issues with SL distributions (diff) | |
download | ice-183c7a004d0a62ddecd9eeb0bc459846d98a7614.tar.bz2 ice-183c7a004d0a62ddecd9eeb0bc459846d98a7614.tar.xz ice-183c7a004d0a62ddecd9eeb0bc459846d98a7614.zip |
Refactored IceGrid session servant management
Diffstat (limited to 'cpp/src/IceGrid/ReapThread.cpp')
-rw-r--r-- | cpp/src/IceGrid/ReapThread.cpp | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/cpp/src/IceGrid/ReapThread.cpp b/cpp/src/IceGrid/ReapThread.cpp index 9034a6f18f8..86dbd9172b8 100644 --- a/cpp/src/IceGrid/ReapThread.cpp +++ b/cpp/src/IceGrid/ReapThread.cpp @@ -57,7 +57,12 @@ ReapThread::run() { try { - if((IceUtil::Time::now(IceUtil::Time::Monotonic) - p->item->timestamp()) > p->timeout) + if(p->timeout == IceUtil::Time()) + { + p->item->timestamp(); // This should throw if the reapable is destroyed. + ++p; + } + else if((IceUtil::Time::now(IceUtil::Time::Monotonic) - p->item->timestamp()) > p->timeout) { reap.push_back(*p); p = _sessions.erase(p); @@ -114,37 +119,46 @@ ReapThread::add(const ReapablePtr& reapable, int timeout) } // + // NOTE: registering a reapable with a null timeout is allowed. The reapable is reaped + // only when the reaper thread is shutdown. + // + + // // 10 seconds is the minimum permissable timeout. // - if(timeout < 10) + if(timeout > 0 && timeout < 10) { timeout = 10; } ReapableItem item; item.item = reapable; - item.timeout = IceUtil::Time::seconds(timeout); + item.timeout = timeout == 0 ? IceUtil::Time() : IceUtil::Time::seconds(timeout); _sessions.push_back(item); - // - // If there is a new minimum wake interval then wake the reaping - // thread. - // - if(calcWakeInterval()) + if(timeout > 0) { - notify(); + // + // If there is a new minimum wake interval then wake the reaping + // thread. + // + if(calcWakeInterval()) + { + notify(); + } + + // + // Since we just added a new session with a non null timeout there + // must be a non-zero wakeInterval. + // + assert(_wakeInterval != IceUtil::Time()); } - - // - // Since we just added a new session there must be a non-zero - // wakeInterval. - // - assert(_wakeInterval != IceUtil::Time()); } -// Returns true iff the calculated wake interval is less than the -// current wake interval (or if the original wake interval was -// "forever"). +// +// Returns true if the calculated wake interval is less than the current wake +// interval (or if the original wake interval was "forever"). +// bool ReapThread::calcWakeInterval() { @@ -154,7 +168,7 @@ ReapThread::calcWakeInterval() bool first = true; for(list<ReapableItem>::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p) { - if(first || p->timeout < minimum) + if(p->timeout != IceUtil::Time() && (first || p->timeout < minimum)) { minimum = p->timeout; first = false; |