pthread_work_fifo.hpp

00001 #line 1352 "./lpsrc/flx_pthread.pak"
00002 #ifndef __FLX_PTHREAD_WORKER_FIFO_H__
00003 #define __FLX_PTHREAD_WORKER_FIFO_H__
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 /// Job scheduler, executes jobs in turn from queue
00026 class PTHREAD_EXTERN worker_fifo
00027 {
00028   flx_mutex_t nlock;
00029   int nthreads;                 /// scheduled number of threads
00030   sleep_queue_t fifo;
00031 
00032   static void thread_start(void*); // thread entry point, passed this
00033   bool thread_loop_body();      // returns keep going flag
00034   void stop_worker_thread();
00035   void start_worker_thread();
00036 
00037 public:
00038   worker_fifo(int n, int m);   /// n: Q bound, m: # of threads
00039   ~worker_fifo();
00040   void add_worker_task(worker_task* task);
00041   int get_nthreads();
00042   void set_nthreads(int);
00043 };
00044 
00045 }} // namespace pthread, flx
00046 #endif  // __WORKER_FIFO__
00047 

Generated on Mon Dec 24 07:59:57 2007 for Felix by  doxygen 1.5.4