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
00022
00023
00024 #include <vector>
00025
00026 #include <Exception.h>
00027 #include <sys/Time.h>
00028 #include <sys/Monitor.h>
00029 #include <sys/Thread.h>
00030 #include <sys/AtomicCount.h>
00031 #include "EventChannel.h"
00032
00033 namespace qpid {
00034 namespace sys {
00035
00042 class EventChannelThreads :
00043 public qpid::SharedObject<EventChannelThreads>,
00044 public sys::Monitor, private sys::Runnable
00045 {
00046 public:
00048 static EventChannelThreads::shared_ptr create(
00049 EventChannel::shared_ptr channel
00050 );
00051
00052 ~EventChannelThreads();
00053
00055 void postEvent(Event& event) { channel->postEvent(event); }
00056
00058 void postEvent(Event* event) { channel->postEvent(event); }
00059
00066 void shutdown();
00067
00069 void join();
00070
00071 private:
00072 typedef std::vector<sys::Thread> Threads;
00073 typedef enum {
00074 RUNNING, TERMINATE_SENT, JOINING, SHUTDOWN
00075 } State;
00076
00077 EventChannelThreads(EventChannel::shared_ptr underlyingChannel);
00078 void addThread();
00079
00080 void run();
00081 bool keepRunning();
00082 void adjustThreads();
00083
00084 EventChannel::shared_ptr channel;
00085 Threads workers;
00086 sys::AtomicCount nWaiting;
00087 State state;
00088 Event terminate;
00089 };
00090
00091
00092 }}
00093
00094
00095 #endif