00001 #ifndef _posix_EventChannelThreads_h
00002 #define _sys_EventChannelThreads_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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