olp-cpp-sdk  1.21.0
Public Types | Public Member Functions | Protected Member Functions | List of all members
olp::thread::TaskScheduler Class Referenceabstract

An abstract interface that is used as a base for the custom thread scheduling strategy. More...

#include <TaskScheduler.h>

Inheritance diagram for olp::thread::TaskScheduler:
Inheritance graph
[legend]

Public Types

using CallFuncType = std::function< void()>
 An alias for the abstract interface input.
 

Public Member Functions

void ScheduleTask (CallFuncType &&func)
 Schedules the asynchronous task. More...
 
void ScheduleTask (CallFuncType &&func, uint32_t priority)
 Schedules the asynchronous task. More...
 
template<class Function , typename std::enable_if<!std::is_convertible< decltype(std::declval< Function >()), CallFuncType >::value , ::type * = nullptr>
client::CancellationContext ScheduleTask (Function &&func)
 Schedules the asynchronous cancellable task. More...
 

Protected Member Functions

virtual void EnqueueTask (CallFuncType &&)=0
 The abstract enqueue task interface that is implemented by the subclass. More...
 
virtual void EnqueueTask (CallFuncType &&func, uint32_t priority)
 The enqueue task with priority interface that is implemented by the subclass. More...
 

Detailed Description

An abstract interface that is used as a base for the custom thread scheduling strategy.

Subclasses should inherit from this class and implement virtual EnqueueTask that takes any callable target (lambda expression, bind expression, or any other function object) as input and adds it to the execution pipeline.

Member Function Documentation

◆ EnqueueTask() [1/2]

virtual void olp::thread::TaskScheduler::EnqueueTask ( CallFuncType &&  )
protectedpure virtual

The abstract enqueue task interface that is implemented by the subclass.

Implement this method in the subclass that takes TaskScheduler as a base and provides a custom algorithm for scheduling tasks enqueued by the SDK.

Note
Tasks added trough this method should be scheduled with Priority::NORMAL priority.

Implemented in olp::thread::ThreadPoolTaskScheduler.

◆ EnqueueTask() [2/2]

virtual void olp::thread::TaskScheduler::EnqueueTask ( CallFuncType &&  func,
uint32_t  priority 
)
inlineprotectedvirtual

The enqueue task with priority interface that is implemented by the subclass.

Implement this method in the subclass that takes TaskScheduler as a base and provides a custom algorithm for scheduling tasks enqueued by the SDK. The method priorities tasks, so tasks with higher priority executed earlier. Tasks within the same priority group should keep the order.

Parameters
[in]funcThe rvalue reference of the task that should be enqueued. Move this task into your queue. No internal references are kept. Once this method is called, you own the task.
[in]priorityThe priority of the task. Tasks with higher priority executes earlier.

Reimplemented in olp::thread::ThreadPoolTaskScheduler.

◆ ScheduleTask() [1/3]

void olp::thread::TaskScheduler::ScheduleTask ( CallFuncType &&  func)
inline

Schedules the asynchronous task.

Note
Tasks added with this method has Priority::NORMAL priority.
Parameters
[in]funcThe callable target that should be added to the scheduling pipeline.

◆ ScheduleTask() [2/3]

void olp::thread::TaskScheduler::ScheduleTask ( CallFuncType &&  func,
uint32_t  priority 
)
inline

Schedules the asynchronous task.

Parameters
[in]funcThe callable target that should be added to the scheduling pipeline.
[in]priorityThe priority of the task. Tasks with higher priority executes earlier.

◆ ScheduleTask() [3/3]

template<class Function , typename std::enable_if<!std::is_convertible< decltype(std::declval< Function >()), CallFuncType >::value , ::type * = nullptr>
client::CancellationContext olp::thread::TaskScheduler::ScheduleTask ( Function &&  func)
inline

Schedules the asynchronous cancellable task.

Parameters
[in]funcThe callable target that should be added to the scheduling pipeline. As CancellationContext is created internally, it is passed as input, so the callable function should have the following signature:
void func(CancellationContext& context);
Returns
Returns the CancellationContext copy to the caller. The copy can be used to cancel the enqueued tasks. Tasks can only be canceled before or during execution if the task itself is designed to support this. Tasks are also able to cancel the operation themselves as they get a non-const reference to the CancellationContext class.

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