34 m_run_on_destruction(false)
36 if( m_this ==
nullptr )
42 if( m_run_on_destruction )
60 m_list.push_back( &t ) ;
65 const List::iterator end = m_list.end() ;
66 List::iterator p = std::find( m_list.begin() , end , &timer ) ;
70 if( m_soonest == &timer )
72 m_soonest = findSoonest() ;
79 if( !timer.
active() && m_soonest != &timer )
83 else if( timer.
active() && m_soonest !=
nullptr && timer.t() > m_soonest->t() )
90 m_soonest = (timer.
active() && timer.
immediate()) ? &timer : findSoonest() ;
91 if( soonestTime() != old_soonest )
98 return m_soonest ==
nullptr ?
G::EpochTime(0) : m_soonest->t() ;
104 TimerBase * result = nullptr ;
105 const List::const_iterator end = m_list.end() ;
106 for( List::const_iterator p = m_list.begin() ; p != end ; ++p )
108 if( *p !=
nullptr && (*p)->active() && ( result ==
nullptr || (*p)->t() < result->t() ) )
116 if( m_soonest ==
nullptr )
121 else if( m_soonest->immediate() )
142 if( m_this ==
nullptr )
151 for( List::iterator p = m_list.begin() ; p != m_list.end() ; ++p )
153 if( *p !=
nullptr && (*p)->active() && (*p)->expired(now) )
159 m_soonest = findSoonest() ;
163 void GNet::TimerList::setTimeout()
169 void GNet::TimerList::collectGarbage()
171 for( List::iterator p = m_list.begin() ; p != m_list.end() ; )
174 p = m_list.erase( p ) ;
182 std::ostringstream ss ;
183 ss << m_list.size() ;
A subsecond-resolution timestamp based on a time_t.
virtual void setTimeout(G::EpochTime t)=0
Used by GNet::TimerList.
bool active() const
Returns true if the timer is started and not cancelled.
TimerList()
Default constructor.
Overload discriminator class for TimerList.
A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their be...
static EpochTime now()
Returns the current epoch time.
static TimerList & instance()
Singleton access. Throws an exception if none.
G::EpochTime interval(bool &infinite) const
Returns the interval to the first timer expiry.
void add(TimerBase &)
Adds a timer.
void doTimeouts()
Triggers the timeout callbacks of any expired timers.
~TimerList()
Destructor. Any expired timers have their timeouts called.
void update(TimerBase &)
Called when a timer changes its value.
An interface used by GNet::TimerList to keep track of pending timeouts and to deliver timeout events...
bool immediate() const
Returns true if the timer is active() and zero-length.
static bool exists()
Returns true if an instance exists.
void remove(TimerBase &)
Removes a timer from the list.
std::string report() const
Returns a line of text reporting the status of the timer list.
static EventLoop & instance()
Returns a reference to an instance of the class, if any.