|
| | task (const config &cfg, std::move_only_function< void(self &)> task_func) |
| | Creates a task with a std::move_only_function callback.
|
| |
| | task (const config &cfg, void(*task_func)(self &, void *), void *arg) |
| | Creates a task with a raw function pointer callback.
|
| |
| | ~task () |
| | Destroys the task, requesting stop and blocking until the task function completes.
|
| |
| | task (const task &)=delete |
| |
| task & | operator= (const task &)=delete |
| |
| | task (task &&)=delete |
| |
| task & | operator= (task &&)=delete |
| |
| TaskHandle_t | idf_handle () const noexcept |
| | Returns the underlying FreeRTOS task handle.
|
| |
| const std::string & | name () const noexcept |
| | Returns the task name.
|
| |
| unsigned int | priority () const noexcept |
| | Returns the current task priority.
|
| |
| size_t | stack_high_water_mark () const noexcept |
| | Returns the minimum free stack space (in bytes) since the task started.
|
| |
| bool | is_completed () const noexcept |
| | Checks if the task function has returned.
|
| |
| bool | joinable () const noexcept |
| | Checks if this task object owns the task.
|
| |
| bool | request_stop () noexcept |
| | Requests the task to stop.
|
| |
| bool | stop_requested () const noexcept |
| | Checks if a stop has been requested for this task.
|
| |
| void | suspend () |
| | Suspends the task.
|
| |
| void | resume () |
| | Resumes a suspended task.
|
| |
| result< void > | try_suspend () |
| | Suspends the task.
|
| |
| result< void > | try_resume () |
| | Resumes a suspended task.
|
| |
| bool | resume_from_isr () noexcept |
| | Resumes a suspended task from ISR context.
|
| |
| void | notify () |
| | Sends a notification to the task.
|
| |
| result< void > | try_notify () |
| | Sends a notification to the task.
|
| |
| bool | notify_from_isr () noexcept |
| | Sends a notification to the task from ISR context.
|
| |
| void | set_priority (unsigned int new_priority) |
| | Changes the task priority.
|
| |
| result< void > | try_set_priority (unsigned int new_priority) |
| | Changes the task priority.
|
| |
| void | detach () |
| | Releases ownership of the task.
|
| |
| result< void > | try_detach () |
| | Releases ownership of the task.
|
| |
| void | kill () |
| | Immediately terminates the task without waiting for completion.
|
| |
| result< void > | try_kill () |
| | Immediately terminates the task without waiting for completion.
|
| |
| void | join () |
| | Blocks until the task function completes.
|
| |
| template<typename Rep , typename Period > |
| void | join (const std::chrono::duration< Rep, Period > &timeout) |
| | Blocks until the task function completes or the timeout expires.
|
| |
| template<typename Clock , typename Duration > |
| void | join_until (const std::chrono::time_point< Clock, Duration > &deadline) |
| | Blocks until the task function completes or the deadline is reached.
|
| |
| result< void > | try_join () |
| | Blocks until the task function completes.
|
| |
| template<typename Rep , typename Period > |
| result< void > | try_join (const std::chrono::duration< Rep, Period > &timeout) |
| | Blocks until the task function completes or the timeout expires.
|
| |
| template<typename Clock , typename Duration > |
| result< void > | try_join_until (const std::chrono::time_point< Clock, Duration > &deadline) |
| | Blocks until the task function completes or the deadline is reached.
|
| |
|
| static result< std::unique_ptr< task > > | make (config cfg, std::move_only_function< void(self &)> task_func) |
| | Creates a task with a std::move_only_function callback.
|
| |
| static result< std::unique_ptr< task > > | make (config cfg, void(*task_func)(self &, void *), void *arg) |
| | Creates a task with a raw function pointer callback.
|
| |
| static void | spawn (config cfg, std::move_only_function< void(self &)> task_func) |
| | Creates a fire-and-forget task with a std::move_only_function callback.
|
| |
| static void | spawn (config cfg, void(*task_func)(self &, void *), void *arg) |
| | Creates a fire-and-forget task with a raw function pointer callback.
|
| |
| static result< void > | try_spawn (config cfg, std::move_only_function< void(self &)> task_func) |
| | Creates a fire-and-forget task with a std::move_only_function callback.
|
| |
| static result< void > | try_spawn (config cfg, void(*task_func)(self &, void *), void *arg) |
| | Creates a fire-and-forget task with a raw function pointer callback.
|
| |
| static TaskHandle_t | current_handle () noexcept |
| | Returns the handle of the currently executing task.
|
| |
| static std::string | current_name () |
| | Returns the name of the currently executing task.
|
| |
Task lifecycle management.
Manages a task with automatic cleanup on destruction.
Tasks are non-copyable and non-movable. Use the factory method make() for result-based construction or the throwing constructor when exceptions are enabled.
- Note
- The task function runs in the created task's context, not the caller's context.
Definition at line 47 of file task.hpp.
| void idfxx::task::kill |
( |
| ) |
|
|
inline |
Immediately terminates the task without waiting for completion.
Immediately terminates the task. After killing, the task becomes non-joinable.
- Warning
- This is a dangerous operation that should only be used as a last resort. The task is terminated abruptly at whatever point it is executing:
- C++ destructors for stack-allocated objects will not run
- Mutexes and locks held by the task will not be released
- Dynamic memory allocated by the task will not be freed
- Any invariants the task was maintaining may be left in an inconsistent state
These consequences can lead to resource leaks, deadlocks, and undefined behavior in the rest of the system. Prefer using request_stop() and join() to allow the task to complete gracefully, or allow the destructor to block.
If the task function has already returned by the time this method is called, this method simply cleans up resources.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | if the task has been detached, already joined, or if called from within the task itself. |
Definition at line 646 of file task.hpp.
References try_kill(), and idfxx::unwrap().
| void idfxx::task::notify |
( |
| ) |
|
|
inline |
Sends a notification to the task.
Increments the task's notification value, waking the task if it is blocked in wait() or take(). Can be called multiple times before the task receives — each call increments the notification count.
Uses notification index 0, which is reserved for this purpose.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | if the task has been detached or completed. |
Definition at line 533 of file task.hpp.
References try_notify(), and idfxx::unwrap().
template<typename Rep , typename Period >
| result< void > idfxx::task::try_join |
( |
const std::chrono::duration< Rep, Period > & |
timeout | ) |
|
|
inline |
Blocks until the task function completes or the timeout expires.
After a successful join, the task becomes non-joinable.
- Template Parameters
-
| Rep | The representation type of the duration. |
| Period | The period type of the duration. |
- Parameters
-
| timeout | Maximum time to wait for the task to complete. |
- Returns
- Success, or an error.
- Return values
-
| invalid_state | The task has been detached or already joined. |
| std::errc::resource_deadlock_would_occur | Called from within the task itself. |
| timeout | The task did not complete within the specified duration. The task remains joinable and can be joined again. |
Definition at line 752 of file task.hpp.
References idfxx::chrono::ticks(), and idfxx::timeout.
template<typename Clock , typename Duration >
| result< void > idfxx::task::try_join_until |
( |
const std::chrono::time_point< Clock, Duration > & |
deadline | ) |
|
|
inline |
Blocks until the task function completes or the deadline is reached.
After a successful join, the task becomes non-joinable.
- Template Parameters
-
| Clock | The clock type. |
| Duration | The duration type of the time point. |
- Parameters
-
| deadline | The time point at which to stop waiting. |
- Returns
- Success, or an error.
- Return values
-
| invalid_state | The task has been detached or already joined. |
| std::errc::resource_deadlock_would_occur | Called from within the task itself. |
| timeout | The task did not complete before the deadline. The task remains joinable and can be joined again. |
Definition at line 771 of file task.hpp.
References idfxx::chrono::ticks().
Referenced by join_until().
| result< void > idfxx::task::try_kill |
( |
| ) |
|
Immediately terminates the task without waiting for completion.
Immediately terminates the task. After killing, the task becomes non-joinable.
- Warning
- This is a dangerous operation that should only be used as a last resort. The task is terminated abruptly at whatever point it is executing:
- C++ destructors for stack-allocated objects will not run
- Mutexes and locks held by the task will not be released
- Dynamic memory allocated by the task will not be freed
- Any invariants the task was maintaining may be left in an inconsistent state
These consequences can lead to resource leaks, deadlocks, and undefined behavior in the rest of the system. Prefer using request_stop() and try_join() to allow the task to complete gracefully, or allow the destructor to block.
If the task function has already returned by the time this method is called, this method simply cleans up resources.
- Returns
- Success, or an error.
- Return values
-
| invalid_state | The task has been detached, already joined, or called from within the task itself. |
Referenced by kill().