|
GlitchyByte Lib
0.3.1
GlitchyByte general library to bootstrap development.
|
Public Types | |
| enum class | State : int { Created , Started , Canceled , Finished } |
Public Member Functions | |
| Task () noexcept | |
| virtual | ~Task () noexcept=default |
| State | getState () const noexcept |
| void | cancel () noexcept |
| void | awaitStop () noexcept |
| bool | isStopped () const noexcept |
Protected Member Functions | |
| virtual void | action () noexcept=0 |
| TaskRunner * | getTaskRunner () const noexcept |
| void | started () noexcept |
| bool | shouldCancel () const noexcept |
Protected Attributes | |
| std::mutex | stateLock |
Friends | |
| class | TaskRunner |
A single concurrent task that starts in a separate thread and runs until finished or the task is canceled.
|
strong |
Task states.
| Enumerator | |
|---|---|
| Created | |
| Started | |
| Canceled | |
| Finished | |
|
inlinenoexcept |
Creates a task with a unique id.
|
virtualdefaultnoexcept |
|
inlinenoexcept |
Returns the current state of the task, as of the time of calling this method.
Note that the state can change by the time you are comparing the result.
|
inlinenoexcept |
Signals the task to cancel.
It's up to the task itself to check for its cancellation and needing to exit.
|
inlinenoexcept |
Blocks the calling thread until the task stops, either by cancellation or by finishing.
|
inlinenoexcept |
Tests if the task has stopped, either by cancellation or by finishing.
Once the task enters a stopped state its state will never change again.
|
protectedpure virtualnoexcept |
Actual action that is executed on its own thread.
Implementations MUST call started(), usually after initialization, indicating the task is ready and running.
|
inlineprotectednoexcept |
Returns the task runner that is running this task.
Can be used to start other tasks with the same runner.
|
inlineprotectednoexcept |
Signals the tasks internals that the action has started and is functional.
It MUST be called within action by implementations.
|
inlineprotectednoexcept |
Tests if the task was canceled and should exit.
Long running action implementations should check this periodically and exit when requested.
|
friend |
|
protected |
Lock for any state related operation.