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

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

Inheritance diagram for modm::fiber::Task:
modm::Fiber< MODM_PROTOTHREAD_STACK_SIZE > modm::Fiber< StackSize > modm::pt::Protothread modm::ds1631< I2cMaster > modm::Tmp102< I2cMaster > modm::Tmp175< I2cMaster >

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 stack_watermark ()
 
size_t stack_usage () 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.
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().
void modm::fiber::Task::stack_watermark ( )
inline

Watermarks the stack to measure stack_usage() later.

See also
modm_context_stack_watermark().
bool modm::fiber::Task::start ( )

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

Returns
if the fiber has been scheduled.

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