File include/brisk/core/Threading.hpp
¶
ExecuteImmediately
enum¶
enum class ExecuteImmediately
ExecuteImmediatelyDefines when and how a scheduled function is dispatched in a task queue.
This enum specifies the conditions under which a scheduled function should be executed in relation to the task queue and its default thread.
IfOnThread
enumerator (ExecuteImmediately::IfOnThread
)¶
Executes the scheduled function immediately if the current thread is the queue's default thread.
In this mode, the function bypasses the task queue and is invoked directly if the current thread matches the queue's default thread. Otherwise, it will be added to the queue.
IfProcessing
enumerator (ExecuteImmediately::IfProcessing
)¶
Executes the scheduled function immediately only if the task queue is currently processing tasks.
In this mode, the function is executed directly on the queue's default thread only when the queue is actively processing tasks. Otherwise, the function will be added to the queue for later execution.
Never
enumerator (ExecuteImmediately::Never
)¶
The scheduled function is never executed immediately and is always added to the queue.
In this mode, the function is guaranteed to be dispatched to the task queue, ensuring it is invoked only when the queue processes its tasks.
wakeUpMainThread
variable (Internal::wakeUpMainThread
)¶
extern VoidFunc wakeUpMainThread
Forces the main thread to wake up and process its task queue.
This function is particularly useful when the main thread is sleeping in the event loop. The function should interrupts the event loop by posting an empty message, ensuring that the main thread resumes execution and processes its pending tasks.
Set in window/WindowApplication.cpp
async
function¶
void async(function<void()> fn)
Schedules the function for execution in the thread pool
Param fn
function to call in the thread pool
Scheduler
class¶
Scheduler
Abstract base class for scheduling tasks.
This class defines the interface for a scheduler that can dispatch functions
asynchronously. Derived classes must implement the dispatch
method.
~Scheduler
function (Scheduler::~Scheduler
)¶
virtual ~Scheduler()
Virtual destructor.
dispatch
function (Scheduler::dispatch
)¶
virtual std::future<void>
dispatch(VoidFunc func,
ExecuteImmediately mode =
ExecuteImmediately::IfOnThread) noexcept = 0
Dispatches a function for execution.
This method schedules the specified function for execution. The function
may be executed immediately or added to the task queue depending on the
dispatch mode and the current thread context.
Param func
The function to be executed.
Param mode
The mode that determines when the function will be executed.
Returns A future that will be satisfied once the function has completed.
template <
typename Callable,
typename ReturnType = std::invoke_result_t<Callable>>
std::future<ReturnType>
dispatch(Callable &&func,
ExecuteImmediately mode =
ExecuteImmediately::IfOnThread)
requires(!std::is_same_v<ReturnType, void>)
Dispatches a callable and returns a future for the result.
This method allows the dispatch of any callable (function, lambda, etc.)
that returns a result, providing a future for the result.
Template param Callable
The type of the callable (e.g., function, lambda) to dispatch.
Template param Args
The types of the arguments to pass to the callable.
Param func
The callable to be dispatched.
Param mode
The mode that determines when the callable will be executed.
Param args
The arguments to pass to the callable.
Returns A future that will contain the result of the callable when it completes.
Thread safety This method is thread-safe and can be called from any thread.
waitForCompletion
function (Scheduler::waitForCompletion
)¶
void waitForCompletion()
Waits until all tasks in the queue are processed.
This method ensures that the task queue is completely processed before
returning.
Thread safety This method is thread-safe and can be called from any thread.
completionFuture
function (Scheduler::completionFuture
)¶
std::future<void> completionFuture()
Creates a future that will be satisfied when all tasks in the queue are processed.
This method returns a std::future<void\>
that can be used to wait for the completion of
all queued tasks.
Returns A future that will be satisfied once all tasks in the queue are processed.
Thread safety This method is thread-safe and can be called from any thread.
TaskQueue
class¶
TaskQueue
Class that manages a queue of tasks to be executed.
The TaskQueue class allows functions to be dispatched for immediate execution or queued for later execution, depending on the dispatch mode and the current thread context.
TaskQueue
function (TaskQueue::TaskQueue
)¶
TaskQueue()
Constructs a TaskQueue object.
Note The thread that executes this constructor becomes the queue's default thread.
dispatch
function (TaskQueue::dispatch
)¶
std::future<void> dispatch(
VoidFunc func,
ExecuteImmediately mode =
ExecuteImmediately::IfOnThread) noexcept override
Dispatches a function for execution.
This method schedules the specified function for execution. If the current thread
is the same as the queue's default thread and the dispatch mode permits immediate
execution, the function is executed immediately. Otherwise, it is added to the queue.
Param func
The function to be executed.
Param mode
The mode that determines when the function will be executed.
Returns A future that will be satisfied once the function has completed.
Thread safety This method is thread-safe and can be called from any thread.
isOnThread
function (TaskQueue::isOnThread
)¶
bool isOnThread() const noexcept
Checks if the current thread is the queue's default thread.
Returns true if the current thread is the queue's default thread, false otherwise.
Thread safety This method is thread-safe and can be called from any thread.
ensureOnThread
function (TaskQueue::ensureOnThread
)¶
void ensureOnThread() const noexcept
Asserts that the current thread is the queue's default thread.
This method checks if the calling thread is the same as the queue's default thread. If the check fails, an assertion is triggered. This ensures certain operations are performed on the correct thread.
isProcessing
function (TaskQueue::isProcessing
)¶
bool isProcessing() const noexcept
Checks if tasks are currently being processed.
Returns true if tasks are being processed, false otherwise.
Thread safety This method is thread-safe and can be called from any thread.
process
function (TaskQueue::process
)¶
void process() noexcept
Processes tasks in the queue.
This method dequeues and executes tasks on the current thread. It ensures that no other processing occurs during this operation. The method will continue executing tasks until the queue is empty.
getThreadId
function (TaskQueue::getThreadId
)¶
std::thread::id getThreadId() const noexcept
Gets the thread ID of the queue's default thread.
Returns The thread ID of the queue's default thread.
Thread safety This method is thread-safe and can be called from any thread.
enqueue
function (TaskQueue::enqueue
)¶
void enqueue(VoidFunc func) noexcept
Enqueues a function to be processed later.
Param func
The function to be enqueued.
Thread safety This method is thread-safe and can be called from any thread.
tryDequeue
function (TaskQueue::tryDequeue
)¶
bool tryDequeue(VoidFunc &func) noexcept
Attempts to dequeue a function for processing.
Param func
Reference to store the dequeued function.
Returns true if a function was dequeued, false otherwise.
Impl
class (TaskQueue::Impl
)¶
Impl
mainScheduler
variable¶
extern RC<TaskQueue> mainScheduler
Represents the task queue and scheduler for the main thread.
threadScheduler
variable¶
extern thread_local Scheduler *threadScheduler
Pointer to the scheduler associated with the current thread. If no scheduler has been assigned, this pointer may be nullptr.
DeferredCallback
class¶
template <typename... Args> DeferredCallback
DeferredCallbacks
class¶
template <typename... Args> DeferredCallbacks
setThreadName
function¶
void setThreadName(std::string_view name)
Sets the name of the current thread.
This function sets the name of the calling thread. The name is useful for debugging
and profiling tools that display thread names in their interfaces. Thread names
are typically limited to a small number of characters, depending on the platform.
Param name
A string view representing the desired name of the thread.
ThreadPriority
enum¶
enum class ThreadPriority
Defines thread priority levels.
This enumeration represents the various levels of thread priority, which can be used to influence the scheduling of threads. Higher priorities may result in the thread receiving more CPU time or being scheduled sooner.
Lowest
enumerator (ThreadPriority::Lowest
)¶
The lowest possible thread priority.
Low
enumerator (ThreadPriority::Low
)¶
A low thread priority.
Normal
enumerator (ThreadPriority::Normal
)¶
The default thread priority.
High
enumerator (ThreadPriority::High
)¶
A higher-than-normal thread priority.
Highest
enumerator (ThreadPriority::Highest
)¶
The highest possible thread priority.
setThreadPriority
function¶
void setThreadPriority(ThreadPriority priority)
Sets the priority of the current thread.
This function sets the scheduling priority of the calling thread. The effect
of this may vary depending on the operating system and platform. Higher
priority threads may receive more CPU time than lower priority ones.
Param priority
The desired thread priority level, from the ThreadPriority enumeration.
AsyncCallback
class (Internal::AsyncCallback
)¶
template <typename T> AsyncCallback
AsyncOperation
class¶
template <typename Result> AsyncOperation
AsyncValue
class¶
template <typename Result> AsyncValue
AsyncOperation
class¶
template <typename Result> AsyncOperation
Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/