Shaka Player Embedded
|
#include <task_runner.h>
Public Types | |
using | RunLoop = std::function< void()> |
Public Member Functions | |
TaskRunner (std::function< void(RunLoop)> wrapper, const util::Clock *clock, bool is_worker) | |
~TaskRunner () | |
bool | is_running () const |
bool | HasPendingWork () const |
bool | BelongsToCurrentThread () const |
void | Stop () |
void | WaitUntilFinished () |
template<typename Func > | |
std::shared_future< impl::RetOf< Func > > | InvokeOrSchedule (Func &&callback) |
template<typename Func > | |
std::shared_ptr< ThreadEvent< impl::RetOf< Func > > > | AddInternalTask (TaskPriority priority, const std::string &name, Func &&callback) |
template<typename Func > | |
int | AddTimer (uint64_t delay_ms, Func &&callback) |
template<typename Func > | |
int | AddRepeatedTimer (uint64_t delay_ms, Func &&callback) |
void | CancelTimer (int id) |
Schedules and manages tasks to be run on a worker thread. This manages a background thread to run the tasks. It is safe to call all these methods from any thread.
Definition at line 154 of file task_runner.h.
using shaka::TaskRunner::RunLoop = std::function<void()> |
Definition at line 156 of file task_runner.h.
shaka::TaskRunner::TaskRunner | ( | std::function< void(RunLoop)> | wrapper, |
const util::Clock * | clock, | ||
bool | is_worker | ||
) |
Definition at line 42 of file task_runner.cc.
shaka::TaskRunner::~TaskRunner | ( | ) |
Definition at line 55 of file task_runner.cc.
|
inline |
Registers an internal task to be called on the worker thread. This callback will be given a higher priority than timers.
priority | The priority of the task. Higher priority tasks will run before lower priority tasks even if the higher task is registered later. |
name | The name of the new task, used for debugging. |
callback | The callback object. |
Definition at line 219 of file task_runner.h.
|
inline |
Calls the given callback every |delay_ms| milliseconds on the worker thread.
delay_ms | The time to wait until the callback is called (in milliseconds). |
callback | The callback object. |
Definition at line 267 of file task_runner.h.
|
inline |
Calls the given callback after the given delay on the worker thread.
delay_ms | The time to wait until the callback is called (in milliseconds). |
callback | The callback object. |
Definition at line 243 of file task_runner.h.
bool shaka::TaskRunner::BelongsToCurrentThread | ( | ) | const |
Definition at line 68 of file task_runner.cc.
void shaka::TaskRunner::CancelTimer | ( | int | id | ) |
Cancels a pending timer with the given ID.
Definition at line 94 of file task_runner.cc.
bool shaka::TaskRunner::HasPendingWork | ( | ) | const |
Definition at line 59 of file task_runner.cc.
|
inline |
If called from the thread this manages, the given callback is invoked synchronously; otherwise it is scheduled as an internal task.
callback | The callback object. |
Definition at line 192 of file task_runner.h.
|
inline |
Definition at line 163 of file task_runner.h.
void shaka::TaskRunner::Stop | ( | ) |
Stops the worker thread. Can only be called when running. Will stop any pending tasks and will block until the worker thread is stopped.
Definition at line 72 of file task_runner.cc.
void shaka::TaskRunner::WaitUntilFinished | ( | ) |
Blocks the calling thread until the worker has no more work to do.
Definition at line 87 of file task_runner.cc.