summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-07-08 21:01:36 +0000
committerAlan Conway <aconway@apache.org>2008-07-08 21:01:36 +0000
commitf3267b5baf39396891a772a63d32d780a7ed5297 (patch)
treefa05251dcae47e5fa5982ba7bdef4d2be1a86b1c /cpp/src
parent22bb25f4784dc3e66a3d444ed63e6ee47be6b19d (diff)
downloadqpid-python-f3267b5baf39396891a772a63d32d780a7ed5297.tar.gz
Remove unused Serializer code.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@674955 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Makefile.am3
-rw-r--r--cpp/src/qpid/broker/Queue.h1
-rw-r--r--cpp/src/qpid/framing/SerializeHandler.h49
-rw-r--r--cpp/src/qpid/sys/Serializer.cpp71
-rw-r--r--cpp/src/qpid/sys/Serializer.h181
-rw-r--r--cpp/src/tests/Serializer.cpp157
6 files changed, 0 insertions, 462 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am
index fb57a9fe47..6d281e14ae 100644
--- a/cpp/src/Makefile.am
+++ b/cpp/src/Makefile.am
@@ -226,7 +226,6 @@ libqpidcommon_la_SOURCES = \
qpid/sys/Dispatcher.cpp \
qpid/sys/Runnable.cpp \
qpid/sys/SystemInfo.cpp \
- qpid/sys/Serializer.cpp \
qpid/sys/Shlib.cpp \
qpid/DataDir.cpp \
qpid/Options.cpp \
@@ -507,7 +506,6 @@ nobase_include_HEADERS = \
qpid/framing/SequenceNumber.h \
qpid/framing/SequenceSet.h \
qpid/framing/SequenceNumberSet.h \
- qpid/framing/SerializeHandler.h \
qpid/framing/StructHelper.h \
qpid/framing/TransferContent.h \
qpid/framing/TypeFilter.h \
@@ -557,7 +555,6 @@ nobase_include_HEADERS = \
qpid/sys/LockFile.h \
qpid/sys/ScopedIncrement.h \
qpid/sys/Semaphore.h \
- qpid/sys/Serializer.h \
qpid/sys/SystemInfo.h \
qpid/sys/Shlib.h \
qpid/sys/ShutdownHandler.h \
diff --git a/cpp/src/qpid/broker/Queue.h b/cpp/src/qpid/broker/Queue.h
index 29c6005d60..2907ca81cd 100644
--- a/cpp/src/qpid/broker/Queue.h
+++ b/cpp/src/qpid/broker/Queue.h
@@ -29,7 +29,6 @@
#include "QueueBindings.h"
#include "qpid/framing/FieldTable.h"
-#include "qpid/sys/Serializer.h"
#include "qpid/sys/Monitor.h"
#include "qpid/management/Manageable.h"
#include "qpid/management/Queue.h"
diff --git a/cpp/src/qpid/framing/SerializeHandler.h b/cpp/src/qpid/framing/SerializeHandler.h
deleted file mode 100644
index 55bd7da08c..0000000000
--- a/cpp/src/qpid/framing/SerializeHandler.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef QPID_FRAMING_SERIALIZEHANDLER_H
-#define QPID_FRAMING_SERIALIZEHANDLER_H
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-#include "qpid/sys/Serializer.h"
-#include "qpid/framing/Handler.h"
-
-#include <boost/bind.hpp>
-
-namespace qpid {
-namespace framing {
-
-
-/** Serializer that can be inserted into a Handler chain */
-template <class T>
-struct SerializeHandler : public framing::Handler<T>, public sys::Serializer {
- SerializeHandler(typename framing::Handler<T>::Chain next)
- : framing::Handler<T>(next) {}
- void handle(T value) {
- execute(boost::bind(&framing::Handler<T>::handle, this->next.get(), value));
- }
-};
-
-}} // namespace qpid::framing
-
-
-
-
-
-#endif /*!QPID_FRAMING_SERIALIZEHANDLER_H*/
diff --git a/cpp/src/qpid/sys/Serializer.cpp b/cpp/src/qpid/sys/Serializer.cpp
deleted file mode 100644
index 86f901aa78..0000000000
--- a/cpp/src/qpid/sys/Serializer.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "qpid/sys/Serializer.h"
-#include "qpid/log/Statement.h"
-
-#include <boost/bind.hpp>
-
-#include <assert.h>
-
-namespace qpid {
-namespace sys {
-
-SerializerBase::SerializerBase(bool allowImmediate)
- : state(IDLE), immediate(allowImmediate) {}
-
-void SerializerBase::shutdown() {
- {
- Mutex::ScopedLock l(lock);
- if (state == SHUTDOWN) return;
- state = SHUTDOWN;
- lock.notify();
- }
- if (worker.id() != 0)
- worker.join();
-}
-
-void SerializerBase::notifyWorker() {
- // Call with lock held.
- if (!worker.id())
- worker = Thread(*this);
- else
- lock.notify();
-}
-
-bool SerializerBase::running() {
- Mutex::ScopedLock l(lock);
- return state != SHUTDOWN;
-}
-
-void SerializerBase::wait() {
- Mutex::ScopedLock l(lock);
- if (state == IDLE) lock.wait();
-}
-
-void SerializerBase::run() {
- while (running()) {
- dispatch();
- wait();
- }
-}
-
-}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/Serializer.h b/cpp/src/qpid/sys/Serializer.h
deleted file mode 100644
index fe4afc85cb..0000000000
--- a/cpp/src/qpid/sys/Serializer.h
+++ /dev/null
@@ -1,181 +0,0 @@
-#ifndef SERIALIZER_H
-#define SERIALIZER_H
-
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "qpid/Exception.h"
-#include "qpid/sys/Runnable.h"
-#include "qpid/sys/Monitor.h"
-#include "qpid/sys/Thread.h"
-
-#include <boost/function.hpp>
-#include <boost/noncopyable.hpp>
-
-#include <deque>
-
-namespace qpid {
-namespace sys {
-
-/** Abstract base class for Serializer below. */
-class SerializerBase : private boost::noncopyable, private Runnable
-{
- public:
- typedef boost::function<void()> VoidFn0;
- struct ShutdownException : public Exception {};
-
- /** @see Serializer::Serializer */
- SerializerBase(bool immediate=true);
-
- virtual ~SerializerBase() { shutdown(); }
-
- virtual void dispatch() = 0;
- protected:
- enum State {
- IDLE, ///< No threads are active.
- EXECUTING, ///< execute() is executing a single task.
- DISPATCHING, ///< dispatch() is draining the queue.
- SHUTDOWN ///< SerailizerBase is being destroyed.
- };
-
- void shutdown();
- void notifyWorker();
- void run();
- virtual bool empty() = 0;
- bool running();
- void wait();
-
- Monitor lock;
- State state;
- bool immediate;
- Thread worker;
-};
-
-
-/**
- * Execute tasks sequentially, queuing tasks when necessary to
- * ensure only one thread at a time executes a task and tasks
- * are executed in order.
- *
- * Task is a void returning 0-arg functor. It must not throw exceptions.
- *
- * Note we deliberately do not use boost::function as the task type
- * because copying a boost::functor allocates the target object on the
- * heap.
- */
-template <class Task>
-class Serializer : public SerializerBase {
-
- std::deque<Task> queue;
-
- bool empty() { return queue.empty(); }
- void dispatch(Task& task);
-
- public:
- /** Start a serializer.
- *
- * @param immediate Allow execute() to execute a task immediatly
- * in the current thread.
- */
- Serializer(bool immediate=true)
- : SerializerBase(immediate) {}
-
- ~Serializer() { shutdown(); }
- /**
- * Task may be executed immediately in the calling thread if there
- * are no other tasks pending or executing and the "immediate"
- * paramater to the constructor was true. Otherwise task will be
- * enqueued for execution by a dispatch thread.
- */
- void execute(Task& task);
-
-
- /** Execute pending tasks sequentially in calling thread.
- * Drains the task queue and returns, does not block for more tasks.
- *
- * @exception ShutdownException if the serializer is being destroyed.
- */
- void dispatch();
- };
-
-
-template <class Task>
-void Serializer<Task>::execute(Task& task) {
- 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;
- notifyWorker();
- }
-}
-
-template <class Task>
-void Serializer<Task>::dispatch() {
- Mutex::ScopedLock l(lock);
- // TODO aconway 2007-07-16: This loop could be unbounded
- // if other threads add work while we're in dispatch(Task&).
- // If we need to bound it we could dispatch just the elements
- // that were enqueued when dispatch() was first called - save
- // begin() iterator and pop only up to that.
- while (!queue.empty() && state != SHUTDOWN) {
- assert(state == DISPATCHING);
- dispatch(queue.front());
- queue.pop_front();
- }
- if (state != SHUTDOWN) {
- assert(state == DISPATCHING);
- state = IDLE;
- }
-}
-
-template <class Task>
-void Serializer<Task>::dispatch(Task& task) {
- // Preconditions: lock is held, state is EXECUTING or DISPATCHING
- assert(state != IDLE);
- assert(state != SHUTDOWN);
- assert(state == EXECUTING || state == DISPATCHING);
- Mutex::ScopedUnlock u(lock);
- // No exceptions allowed in task.
- notifyWorker();
- try { task(); } catch (...) { assert(0); }
-}
-
-
-
-
-}} // namespace qpid::sys
-
-
-
-
-
-#endif /*!SERIALIZER_H*/
diff --git a/cpp/src/tests/Serializer.cpp b/cpp/src/tests/Serializer.cpp
deleted file mode 100644
index 5caf2ea096..0000000000
--- a/cpp/src/tests/Serializer.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "qpid/sys/Runnable.h"
-#include "qpid/sys/Thread.h"
-#include "qpid/sys/Mutex.h"
-#include "qpid/sys/Serializer.h"
-
-#include <boost/bind.hpp>
-#include <boost/utility/value_init.hpp>
-#include "unit_test.h"
-
-#include <set>
-
-#include <unistd.h>
-
-QPID_AUTO_TEST_SUITE(SerializerTestSuite)
-
-
-using namespace qpid;
-using namespace qpid::sys;
-using namespace qpid::framing;
-using namespace std;
-
-typedef Serializer<boost::function<void()> > BoostFunctionSerializer;
-
-/** Test for concurrent calls */
-struct Tester {
- Monitor lock;
- size_t count;
- size_t collisions;
- set<long> threads;
-
- Tester() : count(0), collisions(0) {}
-
- void test() {
- if (lock.trylock()) { // Check for concurrent calls.
- ++count;
- threads.insert(Thread::logId()); // Record thread.
- usleep(1000); // Encourage overlap.
- lock.notify();
- lock.unlock();
- }
- else
- ++collisions;
- }
-};
-
-void execute(BoostFunctionSerializer& s, boost::function<void()> t)
-{
- s.execute(t);
-}
-
-QPID_AUTO_TEST_CASE(testSingleThread) {
- // Verify that we call in the same thread by default.
- Tester tester;
- BoostFunctionSerializer s;
- for (int i = 0; i < 100; ++i)
- execute(s, boost::bind(&Tester::test, &tester));
- // All should be executed in this thread.
- BOOST_CHECK_EQUAL(0u, tester.collisions);
- BOOST_CHECK_EQUAL(100u, tester.count);
- BOOST_REQUIRE_EQUAL(1u, tester.threads.size());
- BOOST_CHECK_EQUAL(Thread::logId(), *tester.threads.begin());
-}
-
-
-QPID_AUTO_TEST_CASE(testSingleThreadNoImmediate) {
- // Verify that we call in different thread if immediate=false.
- Tester tester;
- BoostFunctionSerializer s(false);
- for (int i = 0; i < 100; ++i)
- execute(s, boost::bind(&Tester::test, &tester));
- {
- // Wait for dispatch thread to complete.
- Mutex::ScopedLock l(tester.lock);
- while (tester.count != 100)
- tester.lock.wait();
- }
- BOOST_CHECK_EQUAL(0u, tester.collisions);
- BOOST_CHECK_EQUAL(100u, tester.count);
- BOOST_REQUIRE_EQUAL(1u, tester.threads.size());
- BOOST_CHECK(Thread::logId() != *tester.threads.begin());
-}
-
-struct Caller : public Runnable, public Tester {
- Caller(BoostFunctionSerializer& s) : serializer(s) {}
- void run() { execute(serializer, boost::bind(&Tester::test, this)); }
- BoostFunctionSerializer& serializer;
-};
-
-QPID_AUTO_TEST_CASE(testDispatchThread) {
- BoostFunctionSerializer s;
- Caller caller(s);
- Thread threads[100];
- // Concurrent calls.
- for (size_t i = 0; i < 100; ++i)
- threads[i] = Thread(caller);
- for (size_t i = 0; i < 100; ++i)
- threads[i].join();
-
- // At least one task should have been queued.
- BOOST_CHECK_EQUAL(0u, caller.collisions);
- BOOST_CHECK(caller.threads.size() > 2u);
- BOOST_CHECK(caller.threads.size() < 100u);
-}
-
-
-std::auto_ptr<BoostFunctionSerializer> serializer;
-
-struct CallDispatch : public Runnable {
- void run() {
- serializer->dispatch();
- }
-};
-
-void notifyDispatch() {
- static CallDispatch cd;
- Thread t(cd);
-}
-
-// Use externally created threads.
-QPID_AUTO_TEST_CASE(testExternalDispatch) {
- serializer.reset(new BoostFunctionSerializer(false, &notifyDispatch));
- Tester tester;
- for (int i = 0; i < 100; ++i)
- execute(*serializer, boost::bind(&Tester::test, &tester));
- {
- // Wait for dispatch thread to complete.
- Mutex::ScopedLock l(tester.lock);
- while (tester.count != 100)
- tester.lock.wait();
- }
- BOOST_CHECK_EQUAL(0u, tester.collisions);
- BOOST_CHECK_EQUAL(100u, tester.count);
- BOOST_CHECK(Thread::logId() != *tester.threads.begin());
-}
-
-QPID_AUTO_TEST_SUITE_END()