8#ifndef META_OCEAN_TRACKING_SLAM_BACKGROUND_TASK_H
9#define META_OCEAN_TRACKING_SLAM_BACKGROUND_TASK_H
13#include <condition_variable>
67 using Task = std::function<void()>;
172 bool taskExecute_ =
false;
178 bool taskProcessed_ =
true;
187 bool released_ =
true;
This class implements a task which runs in the background while the caller is able to wait for the ta...
Definition BackgroundTask.h:48
std::condition_variable taskExecuteCondition_
The condition variable to signal task execution.
Definition BackgroundTask.h:175
BackgroundTask(const BackgroundTask &backgroundTask)=delete
Disabled copy constructor.
WaitResult wait()
Waits until the previous task execution has been processed.
bool execute()
Executes the task in the background.
BackgroundTask(BackgroundTask &&backgroundTask)=delete
Disabled move constructor.
BackgroundTask & operator=(BackgroundTask &&backgroundTask)=delete
Disabled move assignment operator.
Task task_
The background task to execute.
Definition BackgroundTask.h:166
~BackgroundTask()
Destructs the background task object.
std::jthread thread_
The background thread.
Definition BackgroundTask.h:169
void release()
Explicitly releases the background task and stops the background thread.
void threadRun(std::stop_token stopToken)
The internal thread run function.
bool setTask(Task &&task)
Sets the task to be executed in the background.
BackgroundTask()=default
Creates a new background task object without a task.
WaitResult
Definition of individual wait result states.
Definition BackgroundTask.h:55
@ WR_RELEASED
The task was released before completion.
Definition BackgroundTask.h:59
std::function< void()> Task
Definition of a task function to be executed in the background.
Definition BackgroundTask.h:67
BackgroundTask & operator=(const BackgroundTask &backgroundTask)=delete
Disabled copy assignment operator.
BackgroundTask(Task &&task)
Creates a new background task object with a given task.
std::mutex mutex_
The mutex protecting the internal state.
Definition BackgroundTask.h:184
std::condition_variable taskProcessedCondition_
The condition variable to signal task completion.
Definition BackgroundTask.h:181
The namespace covering the entire Ocean framework.
Definition Accessor.h:15