/home/aconway/svn/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.h

00001 #ifndef _posix_EventChannelThreads_h
00002 #define _sys_EventChannelThreads_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 #include <vector>
00022 
00023 #include "qpid/Exception.h"
00024 #include "qpid/sys/Time.h"
00025 #include "qpid/sys/Monitor.h"
00026 #include "qpid/sys/Thread.h"
00027 #include "qpid/sys/AtomicCount.h"
00028 #include "EventChannel.h"
00029 
00030 namespace qpid {
00031 namespace sys {
00032 
00039 class EventChannelThreads :
00040         public qpid::SharedObject<EventChannelThreads>,
00041         public sys::Monitor, private sys::Runnable
00042 {
00043   public:
00045     static EventChannelThreads::shared_ptr create(
00046         EventChannel::shared_ptr channel
00047     );
00048 
00049     ~EventChannelThreads();
00050 
00052     void postEvent(Event& event) { channel->postEvent(event); }
00053 
00055     void postEvent(Event* event) { channel->postEvent(event); }
00056 
00063     void shutdown();
00064     
00066     void join();
00067 
00068   private:
00069     typedef std::vector<sys::Thread> Threads;
00070     typedef enum {
00071         RUNNING, TERMINATE_SENT, JOINING, SHUTDOWN
00072     } State;
00073 
00074     EventChannelThreads(EventChannel::shared_ptr underlyingChannel);
00075     void addThread();
00076 
00077     void run();
00078     bool keepRunning();
00079     void adjustThreads();
00080 
00081     EventChannel::shared_ptr channel;
00082     Threads workers;
00083     sys::AtomicCount nWaiting;
00084     State state;
00085     Event terminate;
00086 };
00087 
00088 
00089 }}
00090 
00091 
00092 #endif  

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7