Move-only type-erased callable owned by a job. Callables of up to InlineSize bytes are stored inline. Larger ones are allocated with mem::AllocHelper. The storage never comes from the process-wide arena allocators (mem::SmallBlockAllocator and friends), so a job callable can be destroyed on whichever thread finishes with the job.
More...
#include <jobcommon.h>
|
|
| JobCallable (const JobCallable &)=delete |
| |
|
JobCallable & | operator= (const JobCallable &)=delete |
| |
| | JobCallable (JobCallable &&other) noexcept |
| | Takes over the callable of other, leaving it empty.
|
| |
| JobCallable & | operator= (JobCallable &&other) noexcept |
| | Destroys the stored callable and takes over the callable of other, leaving it empty.
|
| |
| template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, JobCallable>>> |
| | JobCallable (F &&f) |
| | Wraps the callable f.
|
| |
| template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, JobCallable>>> |
| JobCallable & | operator= (F &&f) |
| | Destroys the stored callable and wraps the callable f.
|
| |
|
template<typename T = TArg, typename = std::enable_if_t<std::is_void_v<T>>> |
| void | exec () const |
| | Invokes the stored callable.
|
| |
| template<typename T = TArg, typename = std::enable_if_t<!std::is_void_v<T>>> |
| void | exec (const T &arg) const |
| | Invokes the stored callable with arg.
|
| |
|
template<typename T = TArg, typename = std::enable_if_t<std::is_void_v<T>>> |
| void | operator() () const |
| | Invokes the stored callable.
|
| |
| template<typename T = TArg, typename = std::enable_if_t<!std::is_void_v<T>>> |
| void | operator() (const T &arg) const |
| | Invokes the stored callable with arg.
|
| |
|
void | reset () |
| | Destroys the stored callable and everything it captured, and releases its storage.
|
| |
| void | finish () |
| | Ends the lifetime of the stored callable and everything it captured, but keeps any heap storage until reset() or the destructor releases it. A trivially destructible callable has nothing to end, so it is left untouched and this does not write to the wrapper at all.
|
| |
| | operator bool () const |
| | Checks whether the wrapper holds a callable, or the heap storage of one ended by finish().
|
| |
|
| template<typename F > |
| static GAIA_NODISCARD constexpr bool | stores_inline () |
| | Checks whether a callable of type F is stored inline, without a heap allocation.
|
| |
| template<typename F > |
| static JobCallable | create (F &&f) |
| | Creates a wrapper for the callable f.
|
| |
|
|
static constexpr uint32_t | InlineSize = 24 |
| | Size in bytes of the inline callable storage.
|
| |
template<typename TArg>
class gaia::mt::JobCallable< TArg >
Move-only type-erased callable owned by a job. Callables of up to InlineSize bytes are stored inline. Larger ones are allocated with mem::AllocHelper. The storage never comes from the process-wide arena allocators (mem::SmallBlockAllocator and friends), so a job callable can be destroyed on whichever thread finishes with the job.
- Template Parameters
-
| TArg | Type passed by const reference to the callable, or void for a callable taking no arguments. |
◆ JobCallable() [1/2]
Takes over the callable of other, leaving it empty.
- Parameters
-
| other | Wrapper to move from. |
◆ JobCallable() [2/2]
template<typename TArg >
template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, JobCallable>>>
Wraps the callable f.
- Template Parameters
-
- Parameters
-
◆ create()
template<typename TArg >
template<typename F >
Creates a wrapper for the callable f.
- Template Parameters
-
- Parameters
-
- Returns
- New wrapper.
◆ exec()
template<typename TArg >
template<typename T = TArg, typename = std::enable_if_t<!std::is_void_v<T>>>
Invokes the stored callable with arg.
- Parameters
-
| arg | Argument forwarded to the callable. |
◆ finish()
Ends the lifetime of the stored callable and everything it captured, but keeps any heap storage until reset() or the destructor releases it. A trivially destructible callable has nothing to end, so it is left untouched and this does not write to the wrapper at all.
- Warning
- The callable must not be invoked afterwards.
◆ operator bool()
Checks whether the wrapper holds a callable, or the heap storage of one ended by finish().
- Returns
- True when a callable or its storage is held.
◆ operator()()
template<typename TArg >
template<typename T = TArg, typename = std::enable_if_t<!std::is_void_v<T>>>
Invokes the stored callable with arg.
- Parameters
-
| arg | Argument forwarded to the callable. |
◆ operator=() [1/2]
template<typename TArg >
template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, JobCallable>>>
Destroys the stored callable and wraps the callable f.
- Template Parameters
-
- Parameters
-
- Returns
- This wrapper.
◆ operator=() [2/2]
Destroys the stored callable and takes over the callable of other, leaving it empty.
- Parameters
-
| other | Wrapper to move from. |
- Returns
- This wrapper.
◆ stores_inline()
template<typename TArg >
template<typename F >
Checks whether a callable of type F is stored inline, without a heap allocation.
- Template Parameters
-
- Returns
- True when F fits the inline storage.
The documentation for this class was generated from the following file:
- /home/runner/work/gaia-ecs/gaia-ecs/include/gaia/mt/jobcommon.h