Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::Timer Class Referencefinal

Low-Precision Timer Class. More...

#include <Timer.h>

Inheritance diagram for sese::Timer:

Public Types

using Ptr = std::shared_ptr<Timer>
 

Public Member Functions

 ~Timer () noexcept
 Timer destructor.
 
TimerTask::Ptr delay (const std::function< void()> &callback, int64_t relative_timestamp, bool is_repeat=false) noexcept
 
void shutdown () noexcept
 Shutdown the timer and terminate the timer thread.
 
 Timer ()=default
 Private constructor.
 
void loop () noexcept
 

Static Public Member Functions

static Timer::Ptr create (size_t number=TIMER_WHEEL_NUMBER) noexcept
 
static void cancelCallback (const std::weak_ptr< Timer > &weak_timer, const std::weak_ptr< TimerTask > &weak_task) noexcept
 

Public Attributes

size_t number = 0
 
std::mutex mutex {}
 
Thread::Ptr thread = nullptr
 
std::atomic_bool isShutdown = false
 
std::atomic< int64_t > currentTimestamp = 0
 
std::list< TimerTask::Ptr > * timerTasks = nullptr
 

Detailed Description

Low-Precision Timer Class.

Member Typedef Documentation

◆ Ptr

using sese::Timer::Ptr = std::shared_ptr<Timer>

Constructor & Destructor Documentation

◆ ~Timer()

Timer::~Timer ( )
noexcept

Timer destructor.

References isShutdown, shutdown(), and timerTasks.

◆ Timer()

sese::Timer::Timer ( )
default

Private constructor.

Member Function Documentation

◆ cancelCallback()

void Timer::cancelCallback ( const std::weak_ptr< Timer > & weak_timer,
const std::weak_ptr< TimerTask > & weak_task )
staticnoexcept

Referenced by delay().

◆ create()

Timer::Ptr Timer::create ( size_t number = TIMER_WHEEL_NUMBER)
staticnoexcept

Initialize a timer

Parameters
numberNumber of slots in the timer wheel

References MAKE_SHARED_PRIVATE.

◆ delay()

TimerTask::Ptr Timer::delay ( const std::function< void()> & callback,
int64_t relative_timestamp,
bool is_repeat = false )
noexcept

Set a delayed task

Parameters
callbackCallback function
relative_timestampDelay duration
is_repeatWhether to repeat
Returns
Task handle

References callback(), and cancelCallback().

◆ loop()

void Timer::loop ( )
noexcept

◆ shutdown()

void Timer::shutdown ( )
noexcept

Shutdown the timer and terminate the timer thread.

References isShutdown, sese::Thread::join(), and thread.

Referenced by ~Timer().

Member Data Documentation

◆ currentTimestamp

std::atomic<int64_t> sese::Timer::currentTimestamp = 0

Referenced by loop().

◆ isShutdown

std::atomic_bool sese::Timer::isShutdown = false

Referenced by loop(), shutdown(), and ~Timer().

◆ mutex

std::mutex sese::Timer::mutex {}

Referenced by loop().

◆ number

size_t sese::Timer::number = 0

Referenced by loop().

◆ thread

Thread::Ptr sese::Timer::thread = nullptr

Referenced by shutdown().

◆ timerTasks

std::list<TimerTask::Ptr>* sese::Timer::timerTasks = nullptr

Referenced by loop(), and ~Timer().


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