carb::tasking::PinGuard
Defined in carb/tasking/ITasking.h
-
class PinGuard
Causes the currently executing TaskContext to be “pinned” to the thread it is currently running on until PinGuard is destroyed.
Appropriately handles recursive pinning. This class causes the current thread to be the only task thread that can run the current task. This is necessary in some cases where thread specificity is required (those these situations are NOT recommended for tasks): holding a mutex, or using thread-specific data, etc. Thread pinning is not efficient (the pinned thread could be running a different task causing delays for the current task to be resumed, and wakeTask() must wait to return until the pinned thread has been notified) and should therefore be avoided.
Note
It is assumed that the task is allowed to move to another thread during the pinning process, though this may not always be the case. Only after the PinGuard is constructed will a task be pinned. Therefore, make sure to construct PinGuard before any operation that requires pinning.