00001 #ifndef CVD_INCLUDE_RUNNABLE_BATCH_H 00002 #define CVD_INCLUDE_RUNNABLE_BATCH_H 00003 00004 #include <cvd/thread.h> 00005 #include <tr1/memory> 00006 #include <vector> 00007 namespace CVD 00008 { 00009 00010 //Forward declaration 00011 template<class C> class MessageQueue; 00012 00017 class RunnableBatch 00018 { 00019 private: 00020 bool joined; 00021 unsigned int parallelism; 00022 00023 class RunMessageInThread: public Thread 00024 { 00025 public: 00026 RunMessageInThread(MessageQueue<std::tr1::shared_ptr<Runnable> >* queue); 00027 virtual void run(); 00028 00029 private: 00030 MessageQueue<std::tr1::shared_ptr<Runnable> >* q; 00031 }; 00032 00033 std::vector<std::tr1::shared_ptr<RunMessageInThread> > threads; 00034 std::tr1::shared_ptr<MessageQueue<std::tr1::shared_ptr<Runnable> > > queue; 00035 00036 00037 public: 00045 RunnableBatch(unsigned int p); 00046 00049 void join(); 00050 00054 void schedule(std::tr1::shared_ptr<Runnable> r); 00055 00058 ~RunnableBatch(); 00059 }; 00060 00061 } 00062 #endif