From f3267b5baf39396891a772a63d32d780a7ed5297 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 8 Jul 2008 21:01:36 +0000 Subject: Remove unused Serializer code. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@674955 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/Queue.h | 1 - cpp/src/qpid/framing/SerializeHandler.h | 49 --------- cpp/src/qpid/sys/Serializer.cpp | 71 ------------- cpp/src/qpid/sys/Serializer.h | 181 -------------------------------- 4 files changed, 302 deletions(-) delete mode 100644 cpp/src/qpid/framing/SerializeHandler.h delete mode 100644 cpp/src/qpid/sys/Serializer.cpp delete mode 100644 cpp/src/qpid/sys/Serializer.h (limited to 'cpp/src/qpid') 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 - -namespace qpid { -namespace framing { - - -/** Serializer that can be inserted into a Handler chain */ -template -struct SerializeHandler : public framing::Handler, public sys::Serializer { - SerializeHandler(typename framing::Handler::Chain next) - : framing::Handler(next) {} - void handle(T value) { - execute(boost::bind(&framing::Handler::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 - -#include - -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 -#include - -#include - -namespace qpid { -namespace sys { - -/** Abstract base class for Serializer below. */ -class SerializerBase : private boost::noncopyable, private Runnable -{ - public: - typedef boost::function 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 Serializer : public SerializerBase { - - std::deque 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 -void Serializer::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 -void Serializer::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 -void Serializer::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*/ -- cgit v1.2.1