summaryrefslogtreecommitdiff
path: root/cpp/lib/common/sys
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-03-27 15:36:39 +0000
committerAlan Conway <aconway@apache.org>2007-03-27 15:36:39 +0000
commit847ee577e23fbdd2175709a08a7160e8b2c1f464 (patch)
treee4962c5246c91a08ef635f2c68e06b82cfb100ee /cpp/lib/common/sys
parentfb14a2042dd5bdae5a5c79b8cd4f1ad87e59bee1 (diff)
downloadqpid-python-847ee577e23fbdd2175709a08a7160e8b2c1f464.tar.gz
Refactored client::Message to be independent of all Basic class concepts
and client::IncomingMessage to handle 0-9 style references and appends. * cpp/lib/client/ClientMessage.cpp: Made independent of Basic class. * cpp/lib/client/IncomingMessage.cpp: Refactored to handle references/appends. * cpp/lib/client/BasicMessageChannel.cpp: Refactored to use new IncomingMessage Thread safety fixes: * cpp/lib/client/ResponseHandler.h: Remove stateful functions. * cpp/lib/client/ClientChannel.cpp: use new ResponseHandler interface. Minor cleanup: * cpp/lib/common/framing/BasicHeaderProperties.cpp: use DeliveryMode enum. * cpp/tests/HeaderTest.cpp: use DeliveryMode enum. * cpp/tests/MessageTest.cpp: use DeliveryMode enum. * cpp/lib/common/shared_ptr.h: #include <boost/cast.hpp> for convenience. * cpp/lib/common/sys/ThreadSafeQueue.h: Changed "stop" "shutdown" * cpp/lib/common/sys/ProducerConsumer.h: Changed "stop" "shutdown" * cpp/tests/ClientChannelTest.cpp (TestCase): Removed debug couts. * cpp/tests/setup: valgrind --demangle=yes by default. * cpp/tests/topictest: sleep to hack around startup race. * cpp/lib/broker/BrokerQueue.cpp (configure): Fixed memory leak. Removed/updated FIXME comments in: * cpp/lib/broker/BrokerMessage.cpp: * cpp/lib/broker/BrokerMessageBase.h: * cpp/lib/broker/InMemoryContent.cpp: * cpp/lib/common/framing/MethodContext.h: git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@522956 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/lib/common/sys')
-rw-r--r--cpp/lib/common/sys/ProducerConsumer.cpp20
-rw-r--r--cpp/lib/common/sys/ProducerConsumer.h20
-rw-r--r--cpp/lib/common/sys/ThreadSafeQueue.h8
3 files changed, 24 insertions, 24 deletions
diff --git a/cpp/lib/common/sys/ProducerConsumer.cpp b/cpp/lib/common/sys/ProducerConsumer.cpp
index 3f6156f230..7a0249f666 100644
--- a/cpp/lib/common/sys/ProducerConsumer.cpp
+++ b/cpp/lib/common/sys/ProducerConsumer.cpp
@@ -27,12 +27,12 @@ namespace sys {
// // ================ ProducerConsumer
ProducerConsumer::ProducerConsumer(size_t init_items)
- : items(init_items), waiters(0), stopped(false)
+ : items(init_items), waiters(0), shutdownFlag(false)
{}
-void ProducerConsumer::stop() {
+void ProducerConsumer::shutdown() {
Mutex::ScopedLock l(monitor);
- stopped = true;
+ shutdownFlag = true;
monitor.notifyAll();
// Wait for waiting consumers to wake up.
while (waiters > 0)
@@ -55,16 +55,16 @@ ProducerConsumer::Lock::Lock(ProducerConsumer& p)
: pc(p), lock(p.monitor), status(INCOMPLETE) {}
bool ProducerConsumer::Lock::isOk() const {
- return !pc.isStopped() && status==INCOMPLETE;
+ return !pc.isShutdown() && status==INCOMPLETE;
}
void ProducerConsumer::Lock::checkOk() const {
- assert(!pc.isStopped());
+ assert(!pc.isShutdown());
assert(status == INCOMPLETE);
}
ProducerConsumer::Lock::~Lock() {
- assert(status != INCOMPLETE || pc.isStopped());
+ assert(status != INCOMPLETE || pc.isShutdown());
}
void ProducerConsumer::Lock::confirm() {
@@ -96,7 +96,7 @@ ProducerConsumer::ConsumerLock::ConsumerLock(ProducerConsumer& p) : Lock(p)
{
if (isOk()) {
ScopedIncrement<size_t> inc(pc.waiters);
- while (pc.items == 0 && !pc.stopped) {
+ while (pc.items == 0 && !pc.shutdownFlag) {
pc.monitor.wait();
}
}
@@ -115,7 +115,7 @@ ProducerConsumer::ConsumerLock::ConsumerLock(
else {
Time deadline = now() + timeout;
ScopedIncrement<size_t> inc(pc.waiters);
- while (pc.items == 0 && !pc.stopped) {
+ while (pc.items == 0 && !pc.shutdownFlag) {
if (!pc.monitor.wait(deadline)) {
status = TIMEOUT;
return;
@@ -126,9 +126,9 @@ ProducerConsumer::ConsumerLock::ConsumerLock(
}
ProducerConsumer::ConsumerLock::~ConsumerLock() {
- if (pc.isStopped()) {
+ if (pc.isShutdown()) {
if (pc.waiters == 0)
- pc.monitor.notifyAll(); // All waiters woken, notify stop thread(s)
+ pc.monitor.notifyAll(); // Notify shutdown thread(s)
}
else if (status==CONFIRMED) {
pc.items--;
diff --git a/cpp/lib/common/sys/ProducerConsumer.h b/cpp/lib/common/sys/ProducerConsumer.h
index 742639323b..c7f42f266d 100644
--- a/cpp/lib/common/sys/ProducerConsumer.h
+++ b/cpp/lib/common/sys/ProducerConsumer.h
@@ -30,7 +30,7 @@ namespace sys {
*
* Producers increase the number of available items, consumers reduce it.
* Consumers wait till an item is available. Waiting threads can be
- * woken for shutdown using stop().
+ * woken for shutdown using shutdown().
*
* Note: Currently implements unbounded producer-consumer, i.e. no limit
* to available items, producers never block. Can be extended to support
@@ -43,16 +43,16 @@ class ProducerConsumer
public:
ProducerConsumer(size_t init_items=0);
- ~ProducerConsumer() { stop(); }
+ ~ProducerConsumer() { shutdown(); }
/**
* Wake any threads waiting for ProducerLock or ConsumerLock.
*@post No threads are waiting in Producer or Consumer locks.
*/
- void stop();
+ void shutdown();
- /** True if queue is stopped */
- bool isStopped() { return stopped; }
+ /** True if queue is shutdown */
+ bool isShutdown() { return shutdownFlag; }
/** Number of items available for consumers */
size_t available() const;
@@ -76,7 +76,7 @@ class ProducerConsumer
*confirm() or cancel() before the lock goes out of scope.
*
* false means the lock failed - timed out or the
- * ProducerConsumer is stopped. You should not do anything in
+ * ProducerConsumer is shutdown. You should not do anything in
* the scope of the lock.
*/
bool isOk() const;
@@ -98,8 +98,8 @@ class ProducerConsumer
/** True if this lock experienced a timeout */
bool isTimedOut() const { return status == TIMEOUT; }
- /** True if we have been stopped */
- bool isStopped() const { return pc.isStopped(); }
+ /** True if we have been shutdown */
+ bool isShutdown() const { return pc.isShutdown(); }
ProducerConsumer& pc;
@@ -141,7 +141,7 @@ class ProducerConsumer
* Wait up to timeout to acquire lock.
*@post If isOk() caller has a producer lock.
* If isTimedOut() there was a timeout.
- * If neither then we were stopped.
+ * If neither then we were shutdown.
*/
ConsumerLock(ProducerConsumer& p, const Time& timeout);
@@ -153,7 +153,7 @@ class ProducerConsumer
mutable Monitor monitor;
size_t items;
size_t waiters;
- bool stopped;
+ bool shutdownFlag;
friend class Lock;
friend class ProducerLock;
diff --git a/cpp/lib/common/sys/ThreadSafeQueue.h b/cpp/lib/common/sys/ThreadSafeQueue.h
index ff949a3e16..80ea92da0e 100644
--- a/cpp/lib/common/sys/ThreadSafeQueue.h
+++ b/cpp/lib/common/sys/ThreadSafeQueue.h
@@ -46,7 +46,7 @@ class ThreadSafeQueue
}
/** Pop a value from the front of the queue. Waits till value is available.
- *@throw ShutdownException if queue is stopped while waiting.
+ *@throw ShutdownException if queue is shutdown while waiting.
*/
T pop() {
ProducerConsumer::ConsumerLock consumer(pc);
@@ -75,10 +75,10 @@ class ThreadSafeQueue
}
/** Interrupt threads waiting in pop() */
- void stop() { pc.stop(); }
+ void shutdown() { pc.shutdown(); }
- /** True if queue is stopped */
- bool isStopped() { return pc.isStopped(); }
+ /** True if queue is shutdown */
+ bool isShutdown() { return pc.isShutdown(); }
/** Size of the queue */
size_t size() { ProducerConsumer::Lock l(pc); return container.size(); }