You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/11/13 14:53:02 UTC
svn commit: r594537 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/sys:
Serializer.cpp Serializer.h
Author: aconway
Date: Tue Nov 13 05:53:01 2007
New Revision: 594537
URL: http://svn.apache.org/viewvc?rev=594537&view=rev
Log:
Moved Serializer notifyWorker inside the mutex.
Removed user-definable notify function, we want to get rid of Serializer,
not reuse it.
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.h
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.cpp?rev=594537&r1=594536&r2=594537&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.cpp Tue Nov 13 05:53:01 2007
@@ -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::notifyWorker() {
+ // Call with lock held.
if (!worker.id())
worker = Thread(*this);
else
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.h?rev=594537&r1=594536&r2=594537&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Serializer.h Tue Nov 13 05:53:01 2007
@@ -44,7 +44,7 @@
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 @@
State state;
bool immediate;
Thread worker;
- boost::function<void()> notifyDispatch;
};
@@ -92,16 +91,11 @@
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 @@
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>