summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-11-13 13:53:01 +0000
committerAlan Conway <aconway@apache.org>2007-11-13 13:53:01 +0000
commit0b19752d58ea90089468c9674bfe61ce71b9ccfb (patch)
tree6c8764b7608a3e21aeb9237d5d72227fc00f263c /cpp/src
parent04552a4d093f61f74cb9f2d58e26c9bf64e49a36 (diff)
downloadqpid-python-0b19752d58ea90089468c9674bfe61ce71b9ccfb.tar.gz
Moved Serializer notifyWorker inside the mutex.
Removed user-definable notify function, we want to get rid of Serializer, not reuse it. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@594537 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/sys/Serializer.cpp9
-rw-r--r--cpp/src/qpid/sys/Serializer.h45
2 files changed, 20 insertions, 34 deletions
diff --git a/cpp/src/qpid/sys/Serializer.cpp b/cpp/src/qpid/sys/Serializer.cpp
index 6d6caff5a1..f02e51ddb4 100644
--- a/cpp/src/qpid/sys/Serializer.cpp
+++ b/cpp/src/qpid/sys/Serializer.cpp
@@ -29,12 +29,8 @@
namespace qpid {
namespace sys {
-SerializerBase::SerializerBase(bool allowImmediate, VoidFn0 notifyDispatchFn)
- : state(IDLE), immediate(allowImmediate), notifyDispatch(notifyDispatchFn)
-{
- if (notifyDispatch.empty())
- notifyDispatch = boost::bind(&SerializerBase::notifyWorker, this);
-}
+SerializerBase::SerializerBase(bool allowImmediate)
+ : state(IDLE), immediate(allowImmediate) {}
void SerializerBase::shutdown() {
{
@@ -48,6 +44,7 @@ void SerializerBase::shutdown() {
}
void SerializerBase::notifyWorker() {
+ // Call with lock held.
if (!worker.id())
worker = Thread(*this);
else
diff --git a/cpp/src/qpid/sys/Serializer.h b/cpp/src/qpid/sys/Serializer.h
index 9d4f13eb9b..d0d34c26eb 100644
--- a/cpp/src/qpid/sys/Serializer.h
+++ b/cpp/src/qpid/sys/Serializer.h
@@ -44,7 +44,7 @@ class SerializerBase : private boost::noncopyable, private Runnable
struct ShutdownException : public Exception {};
/** @see Serializer::Serializer */
- SerializerBase(bool immediate=true, VoidFn0 notifyDispatch=VoidFn0());
+ SerializerBase(bool immediate=true);
virtual ~SerializerBase() { shutdown(); }
@@ -66,7 +66,6 @@ class SerializerBase : private boost::noncopyable, private Runnable
State state;
bool immediate;
Thread worker;
- boost::function<void()> notifyDispatch;
};
@@ -92,16 +91,11 @@ class Serializer : public SerializerBase {
public:
/** Start a serializer.
*
- * @param notifyDispatch Called when work is pending and there is no
- * active dispatch thread. Must arrange for dispatch() to be called
- * in some thread other than the calling thread and return.
- * By default the Serailizer supplies its own dispatch thread.
- *
* @param immediate Allow execute() to execute a task immediatly
* in the current thread.
*/
- Serializer(bool immediate=true, VoidFn0 notifyDispatch=VoidFn0())
- : SerializerBase(immediate, notifyDispatch) {}
+ Serializer(bool immediate=true)
+ : SerializerBase(immediate) {}
~Serializer() { shutdown(); }
/**
@@ -124,27 +118,22 @@ class Serializer : public SerializerBase {
template <class Task>
void Serializer<Task>::execute(Task& task) {
- bool needNotify = false;
- {
- Mutex::ScopedLock l(lock);
- assert(state != SHUTDOWN);
- if (immediate && state == IDLE) {
- state = EXECUTING;
- dispatch(task);
- if (state != SHUTDOWN) {
- assert(state == EXECUTING);
- state = IDLE;
- }
- }
- else
- queue.push_back(task);
- if (!queue.empty() && state == IDLE) {
- state = DISPATCHING;
- needNotify = true;
+ Mutex::ScopedLock l(lock);
+ assert(state != SHUTDOWN);
+ if (immediate && state == IDLE) {
+ state = EXECUTING;
+ dispatch(task);
+ if (state != SHUTDOWN) {
+ assert(state == EXECUTING);
+ state = IDLE;
}
}
- if (needNotify)
- notifyDispatch(); // Not my function, call outside lock.
+ else
+ queue.push_back(task);
+ if (!queue.empty() && state == IDLE) {
+ state = DISPATCHING;
+ notifyWorker();
+ }
}
template <class Task>