33GNet::TimerList::Value::Value()
36GNet::TimerList::Value::Value( TimerBase * t , ExceptionSink es ) :
42inline bool GNet::TimerList::Value::operator==(
const Value & v )
const noexcept
44 return m_timer == v.m_timer ;
47inline void GNet::TimerList::Value::resetIf( TimerBase * p )
noexcept
53void GNet::TimerList::Value::disarmIf( ExceptionHandler * eh )
noexcept
61GNet::TimerList::Lock::Lock( TimerList & timer_list ) :
62 m_timer_list(timer_list)
67GNet::TimerList::Lock::~Lock()
69 m_timer_list.unlock() ;
78 if( m_this ==
nullptr )
90 (m_locked?m_list_added:m_list).push_back( Value(&t,es) ) ;
96 removeFrom( m_list , &timer ) ;
97 removeFrom( m_list_added , &timer ) ;
98 if( m_soonest == &timer ) m_soonest = nullptr ;
101void GNet::TimerList::removeFrom( List & list ,
TimerBase * timer_p )
noexcept
103 for(
auto & value : list)
104 value.resetIf( timer_p ) ;
109 disarmIn( m_list , eh ) ;
110 disarmIn( m_list_added , eh ) ;
113void GNet::TimerList::disarmIn( List & list ,
ExceptionHandler * eh )
noexcept
115 for(
auto & value : list )
116 value.disarmIf( eh ) ;
122 timer.
adjust( m_adjust++ ) ;
124 if( m_soonest == &timer )
125 m_soonest = nullptr ;
127 if( m_soonest !=
nullptr && timer.
t() < m_soonest->t() )
133 if( m_soonest == &timer )
134 m_soonest = nullptr ;
139 G_ASSERT( !m_locked ) ;
141 for(
const auto & t : m_list )
143 if( t.m_timer !=
nullptr && t.m_timer->active() && ( result ==
nullptr || t.m_timer->t() < result->
t() ) )
151 if( m_soonest ==
nullptr )
152 m_soonest = findSoonest() ;
154 if( m_soonest ==
nullptr )
158 else if( m_soonest->immediate() )
177 return m_this != nullptr ;
182 if( m_this ==
nullptr )
187void GNet::TimerList::lock()
192void GNet::TimerList::unlock()
202void GNet::TimerList::mergeAdded()
204 if( !m_list_added.empty() )
206 m_list.reserve( m_list.size() + m_list_added.size() ) ;
207 m_list.insert( m_list.end() , m_list_added.begin() , m_list_added.end() ) ;
208 m_list_added.clear() ;
212void GNet::TimerList::purgeRemoved()
217 m_list.erase( std::remove( m_list.begin() , m_list.end() , Value(
nullptr,ExceptionSink()) ) , m_list.end() ) ;
223 G_ASSERT( m_list_added.empty() ) ;
227 for(
auto & value : m_list )
229 if( value.m_timer !=
nullptr && value.m_timer->active() && value.m_timer->expired(now) )
234 if( value.m_timer == m_soonest ) m_soonest = nullptr ;
235 value.m_timer->doTimeout() ;
239 if( value.m_es.set() )
240 value.m_es.call( e ,
true ) ;
244 catch( std::exception & e )
246 if( value.m_es.set() )
247 value.m_es.call( e ,
false ) ;
258 std::ostringstream ss ;
259 ss << m_list.size() ;
An exception class that is detected by GNet::EventHandlerList and results in onException() being call...
A class that sets the G::LogOuput::context() while in scope.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
An interface used by GNet::TimerList to keep track of pending timeouts and to deliver timeout events.
bool immediate() const
Used by TimerList.
G::TimerTime t() const
Used by TimerList to get the expiry epoch time.
void adjust(unsigned int us)
Used by TimerList to set the fractional part of the expiry time of immediate() timers so that t() is ...
A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their be...
std::pair< G::TimeInterval, bool > interval() const
Returns the interval to the first timer expiry.
void remove(TimerBase &) noexcept
Removes a timer from the list.
void doTimeouts()
Triggers the timeout callbacks of any expired timers.
static bool exists()
Returns true if instance() exists.
void disarm(ExceptionHandler *) noexcept
Resets any matching ExceptionHandler pointers.
void updateOnStart(TimerBase &)
Called by Timer when a timer is started.
static TimerList & instance()
Singleton access. Throws an exception if none.
static TimerList * ptr() noexcept
Singleton access. Returns nullptr if none.
TimerList()
Default constructor.
void updateOnCancel(TimerBase &)
Called by Timer when a timer is cancelled.
void add(TimerBase &, ExceptionSink)
Adds a timer. Called from the Timer constructor.
std::string report() const
Returns a line of text reporting the status of the timer list.
An interval between two G::SystemTime values or two G::TimerTime values.
A monotonically increasing subsecond-resolution timestamp, notionally unrelated to time_t.
static TimerTime now()
Factory function for the current steady-clock time.
static TimerTime zero()
Factory function for the start of the epoch.