00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _LFProcessor_
00022 #define _LFProcessor_
00023
00024 #include <apr_poll.h>
00025 #include <iostream>
00026 #include <vector>
00027 #include <sys/Monitor.h>
00028 #include <sys/Runnable.h>
00029 #include <sys/Thread.h>
00030
00031 namespace qpid {
00032 namespace sys {
00033
00034 class LFSessionContext;
00035
00042 class LFProcessor : private virtual qpid::sys::Runnable
00043 {
00044 typedef std::vector<LFSessionContext*>::iterator iterator;
00045
00046 const int size;
00047 const apr_interval_time_t timeout;
00048 apr_pollset_t* pollset;
00049 int signalledCount;
00050 int current;
00051 const apr_pollfd_t* signalledFDs;
00052 int count;
00053 const int workerCount;
00054 bool hasLeader;
00055 qpid::sys::Thread* workers;
00056 qpid::sys::Monitor leadLock;
00057 qpid::sys::Mutex countLock;
00058 std::vector<LFSessionContext*> sessions;
00059 volatile bool stopped;
00060 apr_pool_t* pool;
00061
00062 const apr_pollfd_t* getNextEvent();
00063 void waitToLead();
00064 void relinquishLead();
00065 void poll();
00066 virtual void run();
00067
00068 public:
00069 LFProcessor(int workers, int size, int timeout);
00074 void add(const apr_pollfd_t* const fd);
00078 void remove(const apr_pollfd_t* const fd);
00083 void update(const apr_pollfd_t* const fd);
00087 void reactivate(const apr_pollfd_t* const fd);
00092 void deactivate(const apr_pollfd_t* const fd);
00097 bool full();
00101 bool empty();
00105 void stop();
00109 void start();
00113 bool isStopped();
00114
00115 ~LFProcessor();
00116 };
00117
00118 }
00119 }
00120
00121
00122 #endif