Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SyncTimeout Class Reference

Class usable by synchronous code to utilize a timeout. More...

#include <Timer.hxx>

Inheritance diagram for SyncTimeout:
Timer Executable Notifiable QMember Destructable

Public Member Functions

 SyncTimeout (ActiveTimers *timers)
 
void wait_for_notification ()
 Blocks the current thread's execution until the timeout is expired or triggered.
 
- Public Member Functions inherited from Timer
 Timer (ActiveTimers *timers)
 Constructor.
 
 ~Timer ()
 Destructor.
 
void run () override
 Callback from the executor when this timer is scheduled.
 
long long schedule_time ()
 
void start (long long period=-1)
 Starts a timer.
 
void start_absolute (long long expiry_time_nsec)
 Starts the timer with an absolute deadline.
 
void restart ()
 Restart a timer with the existing period but from the current time.
 
void trigger ()
 This will wakeup the timer prematurely, immediately.
 
void ensure_triggered ()
 Triggers the timer if it is not expired yet.
 
void cancel ()
 Dangerous, do not call.
 
bool is_triggered ()
 
void set_triggered ()
 Sets the timer as if it was woken up by a trigger(), even if it was never started.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
void notify () override
 Crashes the program – everyone who is expecting notify calls must override this function.
 
virtual void alloc_result (QMember *item)
 Return the result of an alloc_async() from a memory Pool.
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Member Functions

long long timeout () OVERRIDE
 Clients of timer should override this function.
 

Private Attributes

SyncNotifiable n_
 Blocks the calling thread until triggered or timeout expired.
 

Additional Inherited Members

- Public Types inherited from Timer
enum  { NONE = 0 , RESTART = 1 , DELETE = -1 }
 Special return values from the timeout function. More...
 
- Protected Member Functions inherited from Timer
void update_period (long long period)
 Updates the period, to be used after the next expiration of the timer in order to restart it.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

Class usable by synchronous code to utilize a timeout.

usage: SyncTimeout t; t.start(MSEC_TO_NSEC(100)); t.wait_for_notification(); if (t.is_triggered()) { call was success – response arrived } else { failure – timeout }

Definition at line 330 of file Timer.hxx.

Constructor & Destructor Documentation

◆ SyncTimeout()

SyncTimeout::SyncTimeout ( ActiveTimers timers)
inline
Parameters
timersshould come from the executor on which we're waiting.

Definition at line 333 of file Timer.hxx.

Member Function Documentation

◆ timeout()

long long SyncTimeout::timeout ( )
inlineprivatevirtual

Clients of timer should override this function.

It will be called on the executor of the timer.

Returns
the new timer period, or one of the above special values.

Implements Timer.

Definition at line 347 of file Timer.hxx.

◆ wait_for_notification()

void SyncTimeout::wait_for_notification ( )
inline

Blocks the current thread's execution until the timeout is expired or triggered.

Definition at line 339 of file Timer.hxx.

Member Data Documentation

◆ n_

SyncNotifiable SyncTimeout::n_
private

Blocks the calling thread until triggered or timeout expired.

Definition at line 353 of file Timer.hxx.


The documentation for this class was generated from the following file: