Mercury Currency Engine
Classes | Typedefs | Enumerations | Functions
timer.hpp File Reference
#include <chrono>
#include <condition_variable>
#include <functional>
#include <memory>
#include <thread>
#include <utility>
#include <list>
#include "function_utility.hpp"
#include "atomic.hpp"
#include "scheduler.hpp"
Include dependency graph for timer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mce::timer_service
 
struct  mce::timer_service::timer_id
 
struct  mce::detail::timeout_handler_wrapper
 

Typedefs

typedef std::chrono::steady_clock::time_point mce::time_point
 
typedef std::chrono::steady_clock::duration mce::duration
 
typedef timer_service::timer_id mce::timer_id
 define mce::timer_id
 

Enumerations

enum  time_unit {
  hour , minute , second , millisecond ,
  microsecond , nanosecond
}
 

Functions

mce::duration mce::get_duration (mce::time_unit u, size_t count)
 Return duration for count units of the given time unit.
 
size_t mce::get_time_point_difference (mce::time_unit u, mce::time_point p0, mce::time_point p1)
 Return the difference in time units between two time points.
 
mce::time_point mce::current_time ()
 Return the current time. All mce timer time operations are calculated using this function.
 
timer_service & mce::default_timer_service ()
 Access to default mce::timer_service object.
 
template<typename Callable , typename... As>
timer_id mce::timer (time_unit u, size_t count, Callable &&cb, As &&... as)
 launch a timer with a Callable to be called on timeout More...
 
template<typename Callable , typename... As>
timer_id mce::timer (const mce::time_point &timeout, Callable &&cb, As &&... as)
 launch a timer with a Callable to be called on timeout More...
 
template<typename Callable , typename... As>
timer_id mce::timer (const mce::duration &timeout, Callable &&cb, As &&... as)
 launch a timer with a Callable to be called on timeout More...
 
bool mce::remove_timer (timer_id id)
 remove a running timer, return true if successful, else false
 
size_t mce::count_timers ()
 return a count of running timers
 
bool mce::sleep (mce::duration d)
 Put coroutine or thread to sleep in a blocking fashion. More...
 
bool mce::sleep (time_unit u, size_t count)
 Put coroutine or thread to sleep in a blocking fashion. More...
 

Detailed Description

time based operations api

Function Documentation

◆ sleep() [1/2]

bool mce::sleep ( mce::duration  d)
inline

Put coroutine or thread to sleep in a blocking fashion.

Parameters
da duration until the coroutine should resume
Returns
false if the coroutine was awoken early due to timer being cleared, else true

◆ sleep() [2/2]

bool mce::sleep ( time_unit  u,
size_t  count 
)
inline

Put coroutine or thread to sleep in a blocking fashion.

Parameters
utime_unit used
countcount of time_units representing time until timeout
Returns
false if the coroutine was awoken early due to timer being cleared, else true

◆ timer() [1/3]

template<typename Callable , typename... As>
timer_id mce::timer ( const mce::duration &  timeout,
Callable &&  cb,
As &&...  as 
)

launch a timer with a Callable to be called on timeout

Parameters
timeouta duration until the timer will timeout
cba Callable (function, Functor, lambda) to execute on timeout
as...optional arguments to cb
Returns
a timer_id associated with the launched timer

◆ timer() [2/3]

template<typename Callable , typename... As>
timer_id mce::timer ( const mce::time_point &  timeout,
Callable &&  cb,
As &&...  as 
)

launch a timer with a Callable to be called on timeout

Parameters
timeouta time_point when the timer will timeout
cba Callable (function, Functor, lambda) to execute on timeout
as...optional arguments to cb
Returns
a timer_id associated with the launched timer

◆ timer() [3/3]

template<typename Callable , typename... As>
timer_id mce::timer ( time_unit  u,
size_t  count,
Callable &&  cb,
As &&...  as 
)

launch a timer with a Callable to be called on timeout

Parameters
utime_unit used
countcount of time_units representing time until timeout
cba Callable (function, Functor, lambda) to execute on timeout
as...optional arguments to cb
Returns
a timer_id associated with the launched timer