summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/client/Bounds.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-06-06 20:23:28 +0000
committerAlan Conway <aconway@apache.org>2008-06-06 20:23:28 +0000
commitfb1f5c770c551fe526adf5b860dd72cf5eb07311 (patch)
tree79a0d3ccb278e51b9ec5213b038b903d768c2727 /cpp/src/qpid/client/Bounds.cpp
parent76c922baf182bb367feed2ec014e7cab9db7f79d (diff)
downloadqpid-python-fb1f5c770c551fe526adf5b860dd72cf5eb07311.tar.gz
Added exceptions to sys::Waitable.
Fixed client side deadlock involving client::Bounds. Fixed incorrect exception messages during connection shutdown. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@664114 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/client/Bounds.cpp')
-rw-r--r--cpp/src/qpid/client/Bounds.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/cpp/src/qpid/client/Bounds.cpp b/cpp/src/qpid/client/Bounds.cpp
index 1df21db941..aac18022bc 100644
--- a/cpp/src/qpid/client/Bounds.cpp
+++ b/cpp/src/qpid/client/Bounds.cpp
@@ -1,49 +1,40 @@
#include "Bounds.h"
#include "qpid/log/Statement.h"
+#include "qpid/sys/Waitable.h"
namespace qpid {
namespace client {
-using sys::Monitor;
+using sys::Waitable;
Bounds::Bounds(size_t maxSize) : max(maxSize), current(0) {}
-bool Bounds::expand(size_t sizeRequired, bool block)
-{
- if (max) {
- Monitor::ScopedLock l(lock);
- current += sizeRequired;
- if (block) {
- while (current > max) {
- QPID_LOG(debug, "Waiting for bounds: " << *this);
- lock.wait();
- }
- QPID_LOG(debug, "Bounds ok: " << *this);
- }
- return current <= max;
- } else {
- return true;
+bool Bounds::expand(size_t sizeRequired, bool block) {
+ if (!max) return true;
+ Waitable::ScopedLock l(lock);
+ current += sizeRequired;
+ if (block) {
+ Waitable::ScopedWait w(lock);
+ while (current > max)
+ lock.wait();
}
+ return current <= max;
}
-void Bounds::reduce(size_t size)
-{
+void Bounds::reduce(size_t size) {
if (!max || size == 0) return;
- Monitor::ScopedLock l(lock);
+ Waitable::ScopedLock l(lock);
if (current == 0) return;
- bool needNotify = current > max;
current -= std::min(size, current);
- if (needNotify && current < max) {
- //todo: notify one at a time, but ensure that all threads are
- //eventually notified
- lock.notifyAll();
+ if (current < max && lock.hasWaiters()) {
+ assert(lock.hasWaiters() == 1);
+ lock.notify();
}
}
-size_t Bounds::getCurrentSize()
-{
- Monitor::ScopedLock l(lock);
+size_t Bounds::getCurrentSize() {
+ Waitable::ScopedLock l(lock);
return current;
}
@@ -52,4 +43,10 @@ std::ostream& operator<<(std::ostream& out, const Bounds& bounds) {
return out;
}
+void Bounds::setException(const sys::ExceptionHolder& e) {
+ Waitable::ScopedLock l(lock);
+ lock.setException(e);
+ lock.waitWaiters(); // Wait for waiting threads to exit.
+}
+
}} // namespace qpid::client