pthread_work_fifo.hpp

00001 #line 1326 "./lpsrc/flx_pthread.pak"
00002 #ifndef __WORKER_FIFO__
00003 #define __WORKER_FIFO__
00004 #include <flx_pthread_config.hpp>
00005 #include "pthread_thread.hpp"
00006 #include "pthread_mutex.hpp"
00007 #include "pthread_sleep_queue.hpp"
00008 
00009 namespace flx { namespace pthread {
00010 
00011 /// Class of jobs to be queued in fifo for execution.
00012 class PTHREAD_EXTERN worker_task
00013 {
00014 public:
00015   virtual ~worker_task() {}   // c++ should do this automatically
00016 
00017   /// function called by worker thread to carry out user job
00018   virtual void doit() = 0;
00019 
00020   /// function called by worker thread after doit() is completed
00021   /// used to notify job completion
00022   virtual void finished() = 0; // finished hook (mi serve start gancia?)
00023 };
00024 
00025 /// Linear job scheduler, executes jobs in turn from queue
00026 class PTHREAD_EXTERN worker_fifo
00027 {
00028   sleep_queue_t fifo;
00029   int nthreads;                 /// scheduled number of threads
00030 
00031   static void* thread_start(void*); // thread entry point, passed this
00032   bool thread_loop_body();      // returns keep going flag
00033   void stop_worker_thread();
00034   void start_worker_thread();
00035 
00036 public:
00037   worker_fifo(int n, int m);   /// n: Q bound, m: # of threads
00038   ~worker_fifo();
00039   void add_worker_task(worker_task* task);
00040   int get_nthreads()const;
00041   void set_nthreads(int);
00042 };
00043 
00044 }} // namespace pthread, flx
00045 #endif  // __WORKER_FIFO__
00046 

Generated on Mon Dec 11 18:08:29 2006 for Felix by  doxygen 1.5.1