Leosac  0.8.0
Open Source Access Control
Leosac::Scheduler Class Reference

This is a scheduler that is used internally to schedule asynchronous / long running tasks. More...

#include <Scheduler.hpp>

+ Collaboration diagram for Leosac::Scheduler:

Public Member Functions

 Scheduler (Kernel *kptr)
 Construct a scheduler object (generally 1 per application). More...
 
 Scheduler (const Scheduler &)=delete
 
 Scheduler (Scheduler &&)=delete
 
Scheduleroperator= (const Scheduler &)=delete
 
Scheduleroperator= (Scheduler &&)=delete
 
template<typename Callable >
std::enable_if< !std::is_convertible< Callable, std::shared_ptr< Tasks::Task > >::value, void >::type enqueue (const Callable &call, TargetThread policy)
 
void enqueue (Tasks::TaskPtr t, TargetThread policy)
 Enqueue a task, a schedule to run on thread policy. More...
 
void update (TargetThread me) noexcept
 This will run queued tasks that are scheduled to run on thread me. More...
 
void register_thread (TargetThread me)
 This is currently useless. More...
 
Kernelkernel ()
 Retrieve the kernel reference associated with the scheduler. More...
 

Private Types

using TaskQueue = std::queue< Tasks::TaskPtr >
 
using TaskQueueMap = std::map< TargetThread, TaskQueue >
 

Private Attributes

TaskQueueMap queues_
 The internal queues of tasks. More...
 
Kernelkptr_
 
std::mutex mutex_
 

Detailed Description

This is a scheduler that is used internally to schedule asynchronous / long running tasks.

It currently support running a task on the main thread, or in some random thread.

The scheduler is fully thread-safe.

Definition at line 47 of file Scheduler.hpp.

Member Typedef Documentation

◆ TaskQueue

using Leosac::Scheduler::TaskQueue = std::queue<Tasks::TaskPtr>
private

Definition at line 98 of file Scheduler.hpp.

◆ TaskQueueMap

Definition at line 99 of file Scheduler.hpp.

Constructor & Destructor Documentation

◆ Scheduler() [1/3]

Scheduler::Scheduler ( Kernel kptr)

Construct a scheduler object (generally 1 per application).

The kptr pointer should never be null, except when writing test cases.

Note
We use a pointer here to ease testing

Definition at line 67 of file Scheduler.cpp.

◆ Scheduler() [2/3]

Leosac::Scheduler::Scheduler ( const Scheduler )
delete

◆ Scheduler() [3/3]

Leosac::Scheduler::Scheduler ( Scheduler &&  )
delete

Member Function Documentation

◆ enqueue() [1/2]

template<typename Callable >
std::enable_if< !std::is_convertible<Callable, std::shared_ptr<Tasks::Task> >::value, void>::type Leosac::Scheduler::enqueue ( const Callable &  call,
TargetThread  policy 
)
inline

Definition at line 67 of file Scheduler.hpp.

◆ enqueue() [2/2]

void Scheduler::enqueue ( Tasks::TaskPtr  t,
TargetThread  policy 
)

Enqueue a task, a schedule to run on thread policy.

Definition at line 29 of file Scheduler.cpp.

◆ kernel()

Kernel & Scheduler::kernel ( )

Retrieve the kernel reference associated with the scheduler.

This function will crash the application if the kernel pointer is null.

Definition at line 72 of file Scheduler.cpp.

◆ operator=() [1/2]

Scheduler& Leosac::Scheduler::operator= ( const Scheduler )
delete

◆ operator=() [2/2]

Scheduler& Leosac::Scheduler::operator= ( Scheduler &&  )
delete

◆ register_thread()

void Scheduler::register_thread ( TargetThread  me)

This is currently useless.

Definition at line 60 of file Scheduler.cpp.

◆ update()

void Scheduler::update ( TargetThread  me)
noexcept

This will run queued tasks that are scheduled to run on thread me.

Warning
It is important to call this function with the correct parameter.

Definition at line 42 of file Scheduler.cpp.

Member Data Documentation

◆ kptr_

Kernel* Leosac::Scheduler::kptr_
private

Definition at line 110 of file Scheduler.hpp.

◆ mutex_

std::mutex Leosac::Scheduler::mutex_
mutableprivate

Definition at line 111 of file Scheduler.hpp.

◆ queues_

TaskQueueMap Leosac::Scheduler::queues_
private

The internal queues of tasks.

Each target thread has its own queue. Tasks scheduled to run on POOL are not queued here, since they run on some detached thread we don't care about.

Definition at line 108 of file Scheduler.hpp.


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