00001 #ifndef MultiThreadAnalogMsgDispatcher_H_ 00002 #define MultiThreadAnalogMsgDispatcher_H_ 00003 00004 #include <boost/thread/barrier.hpp> 00005 00006 #include <iostream> 00007 00008 using std::cerr; 00009 using std::endl; 00010 00011 #include "globaldefinitions.h" 00012 #include "AnalogMessageDispatcher.h" 00013 #include "SingleThreadAnalogMsgDispatcher.h" 00014 #include "MTIncomingAnalogMessageDispatcher.h" 00015 00016 // The implementation is the same as in the single thread case 00017 // New type is used to clarify that it's purpose is different 00018 typedef SingleThreadAnalogMsgDispatcher MTImmediateAnalogMsgDispatcher; 00019 00021 00025 class MultiThreadAnalogMsgDispatcher : public AnalogMessageDispatcher 00026 { 00027 public: 00028 MultiThreadAnalogMsgDispatcher(delay_t minDelay) 00029 : min_delay(minDelay) 00030 { 00031 currentStep = 0; 00032 } 00033 ; 00034 00035 virtual ~MultiThreadAnalogMsgDispatcher(); 00036 00037 virtual void dispatchAnalogMsgs(); 00038 00039 virtual void initialize(); 00040 00041 virtual void setBarrier(boost::barrier *barrier) 00042 { 00043 thr_barrier = barrier; 00044 } 00045 00046 SingleThreadAnalogMsgDispatcher & sTLocalDispatcher() 00047 { 00048 return st_analog_msgs_dispatcher; 00049 } 00050 00051 MTImmediateAnalogMsgDispatcher & mTImmediateDispatcher() 00052 { 00053 return mt_incoming_immediate_analog_msgs_dispatcher; 00054 } 00055 00056 MTIncomingAnalogMessageDispatcher &mTDelayedDispatcher() 00057 { 00058 return mt_incoming_delayed_analog_msgs_dispatcher; 00059 } 00060 00061 void setMinDelay(delay_t delay) 00062 { 00063 min_delay = delay; 00064 } 00065 00066 virtual void reset(double dt); 00067 00068 00069 protected: 00070 SingleThreadAnalogMsgDispatcher st_analog_msgs_dispatcher; 00071 00072 MTImmediateAnalogMsgDispatcher mt_incoming_immediate_analog_msgs_dispatcher; 00073 00074 MTIncomingAnalogMessageDispatcher mt_incoming_delayed_analog_msgs_dispatcher; 00075 00076 boost::barrier *thr_barrier; 00077 00078 delay_t min_delay; 00079 00080 int currentStep; 00081 }; 00082 00083 #endif /*MultiThreadAnalogMsgDispatcher_H_*/