----------------------------------------------------------------------------- Thread for timer based actions -----------------------------------------------------------------------------
| 88 | // Thread for timer based actions |
| 89 | //----------------------------------------------------------------------------- |
| 90 | void TimerThread::TimerThreadProc |
| 91 | ( |
| 92 | Event* _exitEvent |
| 93 | ) |
| 94 | { |
| 95 | Log::Write( LogLevel_Info, "Timer: thread starting" ); |
| 96 | |
| 97 | Wait* waitObjects[2]; |
| 98 | waitObjects[0] = _exitEvent; |
| 99 | waitObjects[1] = m_timerEvent; |
| 100 | uint32 count = 2; |
| 101 | |
| 102 | // Initially no timer events so infinite timeout. |
| 103 | m_timerTimeout = Wait::Timeout_Infinite; |
| 104 | |
| 105 | while( 1 ) |
| 106 | { |
| 107 | Log::Write( LogLevel_Detail, "Timer: waiting with timeout %d ms", m_timerTimeout ); |
| 108 | int32 res = Wait::Multiple( waitObjects, count, m_timerTimeout ); |
| 109 | |
| 110 | if (res == 0) |
| 111 | { |
| 112 | // Exit has been signalled |
| 113 | return; |
| 114 | |
| 115 | } else { |
| 116 | // Timeout or new entry to timer list. |
| 117 | m_timerTimeout = Wait::Timeout_Infinite; |
| 118 | |
| 119 | // Go through all waiting actions, and see if any need to be performed. |
| 120 | LockGuard LG(m_timerMutex); |
| 121 | list<TimerEventEntry *>::iterator it = m_timerEventList.begin(); |
| 122 | while( it != m_timerEventList.end() ) { |
| 123 | int32 tr = (*it)->timestamp.TimeRemaining(); |
| 124 | if (tr <= 0) { |
| 125 | // Expired so perform action and remove from list. |
| 126 | Log::Write( LogLevel_Info, "Timer: delayed event" ); |
| 127 | TimerEventEntry *te = *(it++); |
| 128 | te->instance->TimerFireEvent(te); |
| 129 | } else { |
| 130 | // Time remaining. |
| 131 | m_timerTimeout = (m_timerTimeout == Wait::Timeout_Infinite) ? tr : std::min(m_timerTimeout, tr); |
| 132 | ++it; |
| 133 | } |
| 134 | } |
| 135 | m_timerEvent->Reset(); |
| 136 | } |
| 137 | } // while( 1 ) |
| 138 | } |
| 139 | |
| 140 | //----------------------------------------------------------------------------- |
| 141 | // <TimerThread::TimerSetEvent> |
no test coverage detected