00001 // 00002 // Copyright (c) 2005-2008 Kenichi Watanabe. 00003 // Copyright (c) 2005-2008 Yasuhiro Watari. 00004 // Copyright (c) 2005-2008 Hironori Ichibayashi. 00005 // Copyright (c) 2008-2009 Kazuo Horio. 00006 // Copyright (c) 2009-2013 Naruki Kurata. 00007 // Copyright (c) 2005-2013 Ryota Shioya. 00008 // Copyright (c) 2005-2013 Masahiro Goshima. 00009 // 00010 // This software is provided 'as-is', without any express or implied 00011 // warranty. In no event will the authors be held liable for any damages 00012 // arising from the use of this software. 00013 // 00014 // Permission is granted to anyone to use this software for any purpose, 00015 // including commercial applications, and to alter it and redistribute it 00016 // freely, subject to the following restrictions: 00017 // 00018 // 1. The origin of this software must not be misrepresented; you must not 00019 // claim that you wrote the original software. If you use this software 00020 // in a product, an acknowledgment in the product documentation would be 00021 // appreciated but is not required. 00022 // 00023 // 2. Altered source versions must be plainly marked as such, and must not be 00024 // misrepresented as being the original software. 00025 // 00026 // 3. This notice may not be removed or altered from any source 00027 // distribution. 00028 // 00029 // 00030 00031 00032 #ifndef SIM_TIME_WHEEL_TIME_WHEEL_BASE_H 00033 #define SIM_TIME_WHEEL_TIME_WHEEL_BASE_H 00034 00035 #include "Types.h" 00036 #include "Env/Param/ParamExchange.h" 00037 #include "Sim/Foundation/Event/EventList/EventList.h" 00038 #include "Sim/Foundation/Event/EventList/EventWheel.h" 00039 #include "Sim/Foundation/TimeWheel/ClockedResourceBase.h" 00040 00041 namespace Onikiri 00042 { 00043 00044 // 00045 // ^CzC[NX 00046 // Cxgo^/dg 00047 // 00048 class TimeWheelBase : 00049 public ParamExchange, 00050 public ClockedResourceBase 00051 { 00052 public: 00053 typedef EventPtr ListNode; 00054 typedef EventList ListType; 00055 00056 BEGIN_PARAM_MAP( "/Session/Simulator/TimeWheelBase/" ) 00057 PARAM_ENTRY("@Size", m_size); 00058 END_PARAM_MAP() 00059 00060 TimeWheelBase(); 00061 virtual ~TimeWheelBase(); 00062 00063 // Add events 00064 virtual void AddEvent( const ListNode& evnt, int time ); 00065 00066 // Process events. 00067 virtual void End(); 00068 00069 // Proceed a time tick. 00070 virtual void Tick(); 00071 00072 // Get time tick count. 00073 // A difference between GetCycles() and GetNow is the following: 00074 // GetCycles() returns the number of all experienced cycles, but 00075 // GetNow() returns the number of cycles that do not experience stall. 00076 // A result of GetNow() is not changed in stall cycles. 00077 s64 GetNow() const; 00078 00079 // Returns the size of the time wheel. 00080 int GetWheelSize() const 00081 { 00082 return m_size; 00083 } 00084 00085 const ListType& EventsAfterTime(int time) 00086 { 00087 return *m_eventWheel.GetEventList( IndexAfterTime(time) ); 00088 } 00089 00090 const ListType& CurrentEvents() 00091 { 00092 return *m_eventWheel.GetEventList( m_current ); 00093 } 00094 00095 protected: 00096 00097 // eTCNpCxg 00098 EventWheel m_eventWheel; 00099 00100 int IndexAfterTime( int time ) 00101 { 00102 int index = m_current + time; 00103 while( index >= m_size ){ 00104 index -= m_size; 00105 } 00106 return index; 00107 } 00108 00109 private: 00110 // m_event 00111 int m_current; 00112 00113 // mTCY 00114 int m_size; 00115 00116 // Time tick 00117 s64 m_now; 00118 00119 // Copy is forbidden 00120 TimeWheelBase( const TimeWheelBase& ref ){} 00121 TimeWheelBase& operator=( const TimeWheelBase &ref ){ return(*this); } 00122 }; 00123 00124 }; // namespace Onikiri 00125 00126 #endif // SIM_TIME_WHEEL_TIME_WHEEL_BASE_H 00127