QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RuntimeScheduler Class Referenceabstract

#include <RuntimeScheduler.h>

Inheritance diagram for RuntimeScheduler:
Collaboration diagram for RuntimeScheduler:

Public Types

using TaskId = quint64
using Callback = std::function<void()>

Public Member Functions

 RuntimeScheduler (QObject *parent=nullptr)
 ~RuntimeScheduler () override
virtual quint64 nowUs () const =0
qint64 nowMs () const
virtual TaskId schedule (QObject *context, std::chrono::microseconds delay, Callback callback)=0
virtual void cancel (TaskId task)=0
 Cancellation from another thread is ignored. All other access and destruction must occur on the owner thread.

Static Public Member Functions

static RuntimeScheduler * orDefault (RuntimeScheduler *scheduler, QObject *owner)
 scheduler, or a QtRuntimeScheduler owned by owner when it is null.

Static Public Attributes

static constexpr auto MAX_DELAY

Protected Member Functions

bool _canSchedule (QObject *context, std::chrono::microseconds delay, const Callback &callback) const
bool _isCurrentThread () const

Detailed Description

One-thread monotonic clock and deferred callbacks, shared by production controllers and deterministic replay. Classes that accept an injected scheduler create their own when none is supplied; an injected scheduler must share the owner's thread and outlive it.

Definition at line 11 of file RuntimeScheduler.h.

Member Typedef Documentation

◆ Callback

using RuntimeScheduler::Callback = std::function<void()>

Definition at line 16 of file RuntimeScheduler.h.

◆ TaskId

using RuntimeScheduler::TaskId = quint64

Definition at line 15 of file RuntimeScheduler.h.

Constructor & Destructor Documentation

◆ RuntimeScheduler()

RuntimeScheduler::RuntimeScheduler ( QObject * parent = nullptr)
explicit

Definition at line 15 of file RuntimeScheduler.cc.

Referenced by orDefault(), and QtRuntimeScheduler::QtRuntimeScheduler().

◆ ~RuntimeScheduler()

RuntimeScheduler::~RuntimeScheduler ( )
override

Definition at line 20 of file RuntimeScheduler.cc.

Member Function Documentation

◆ _canSchedule()

bool RuntimeScheduler::_canSchedule ( QObject * context,
std::chrono::microseconds delay,
const Callback & callback ) const
protected

Definition at line 30 of file RuntimeScheduler.cc.

References _isCurrentThread(), and MAX_DELAY.

Referenced by QtRuntimeScheduler::schedule().

◆ _isCurrentThread()

bool RuntimeScheduler::_isCurrentThread ( ) const
protected

Definition at line 25 of file RuntimeScheduler.cc.

Referenced by _canSchedule(), and QtRuntimeScheduler::cancel().

◆ cancel()

virtual void RuntimeScheduler::cancel ( TaskId task)
pure virtual

Cancellation from another thread is ignored. All other access and destruction must occur on the owner thread.

Implemented in QtRuntimeScheduler.

◆ nowMs()

qint64 RuntimeScheduler::nowMs ( ) const
inline

Definition at line 28 of file RuntimeScheduler.h.

References nowUs().

◆ nowUs()

virtual quint64 RuntimeScheduler::nowUs ( ) const
pure virtual

◆ orDefault()

RuntimeScheduler * RuntimeScheduler::orDefault ( RuntimeScheduler * scheduler,
QObject * owner )
staticnodiscard

scheduler, or a QtRuntimeScheduler owned by owner when it is null.

Definition at line 10 of file RuntimeScheduler.cc.

References orDefault(), and RuntimeScheduler().

Referenced by orDefault().

◆ schedule()

virtual TaskId RuntimeScheduler::schedule ( QObject * context,
std::chrono::microseconds delay,
Callback callback )
pure virtual

Nonpositive delays defer until the next dispatch. Context must share this object's thread. Calls from other threads and delays above MAX_DELAY are rejected with task ID zero. Destroying context suppresses its callback. No ordering is promised for equal deadlines.

Implemented in QtRuntimeScheduler.

Member Data Documentation

◆ MAX_DELAY

auto RuntimeScheduler::MAX_DELAY
staticconstexpr
Initial value:
=
std::chrono::duration_cast<std::chrono::microseconds>((std::chrono::nanoseconds::max) ())

Definition at line 17 of file RuntimeScheduler.h.

Referenced by _canSchedule().


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