modm API documentation
modm::fiber::Task Class Reference

#include <modm/processing/fiber/task.hpp>

Inheritance diagram for modm::fiber::Task:
modm::Fiber< StackSize >

Public Member Functions

template<size_t Size, class Callable >
 Task (Stack< Size > &stack, Callable &&closure, Start start=Start::Now)
 
modm::fiber::id get_id () const
 
bool joinable () const
 Checks if the Task object identifies an active fiber of execution.
 
void join ()
 
stop_source get_stop_source ()
 
stop_token get_stop_token ()
 
bool request_stop ()
 
void watermark_stack ()
 
size_t stack_usage () const
 
bool stack_overflow () const
 
bool start ()
 
bool isRunning () const
 

Static Public Member Functions

static constexpr unsigned int hardware_concurrency ()
 Returns the number of concurrent threads supported by the implementation.
 

Friends

class Scheduler
 

Detailed Description

The fiber task connects the callable fiber object with the fiber context and scheduler. It constructs the fiber function on the stack if necessary, and adds the contexts to the scheduler. If the fiber function returns, the task is removed from the scheduler. Tasks can then be restarted, which will call the fiber function from the beginning again

Note that a task contains no stack, only the control structures necessary for managing a fiber. You may therefore place objects of this class in fast core-local memory, while the stack must remain in DMA-able memory!

See also
https://en.cppreference.com/w/cpp/thread/jthread
Author
Erik Henriksson
Niklas Hauser

Constructor & Destructor Documentation

template<size_t Size, class Callable >
modm::fiber::Task::Task ( Stack< Size > &  stack,
Callable &&  closure,
Start  start = Start::Now 
)
Parameters
stackA stack object that is NOT shared with other tasks.
closureA callable object of signature void().
startWhen to start this task.

Member Function Documentation

modm::fiber::id modm::fiber::Task::get_id ( ) const
nodiscardinline

Returns a value of std::thread::id identifying the thread associated with *this.

Note
This function can be called from an interrupt.
bool modm::fiber::Task::isRunning ( ) const
nodiscardinline
Returns
if the fiber is attached to a scheduler.
void modm::fiber::Task::join ( )
inline

Blocks the current fiber until the fiber identified by *this finishes its execution. Returns immediately if the thread is not joinable.

bool modm::fiber::Task::request_stop ( )
inline
Note
This function can be called from an interrupt.
bool modm::fiber::Task::stack_overflow ( ) const
nodiscardinline
Returns
if the bottom word on the stack has been overwritten.
See also
modm_context_stack_overflow().
size_t modm::fiber::Task::stack_usage ( ) const
nodiscardinline
Returns
the stack usage as measured by a watermark level.
See also
modm_context_stack_usage().
bool modm::fiber::Task::start ( )

Adds the task to the currently active scheduler, if not already running.

Returns
if the fiber has been scheduled.
void modm::fiber::Task::watermark_stack ( )
inline

Watermarks the stack to measure stack_usage() later.

See also
modm_context_watermark().

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