ThreadSchedule 2.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::detail::SboCallable< TaskSize > Class Template Reference

Type-erased, move-only callable with configurable inline storage. More...

#include <thread_pool.hpp>

Public Member Functions

 SboCallable ()=default
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SboCallable>>>
 SboCallable (F &&f)
 SboCallable (SboCallable &&other) noexcept
auto operator= (SboCallable &&other) noexcept -> SboCallable &
 SboCallable (SboCallable const &)=delete
auto operator= (SboCallable const &) -> SboCallable &=delete
 ~SboCallable ()
 operator bool () const noexcept
void operator() ()

Detailed Description

template<size_t TaskSize = 64>
class threadschedule::detail::SboCallable< TaskSize >

Type-erased, move-only callable with configurable inline storage.

Designed as a lightweight replacement for std::function when heap allocations are undesirable. Callables whose size and alignment fit within the inline buffer are stored in-place (Small Buffer Optimization); larger callables fall back to a heap allocation transparently.

Storage layout
|<---------- TaskSize bytes ---------->|
[ VTable* (8 B) | inline buffer ]
The usable inline buffer is TaskSize - sizeof(void*) bytes (56 bytes on 64-bit platforms with the default TaskSize of 64).
Inline eligibility
A callable F is stored inline when all of the following hold:
  • sizeof(F) <= kBufferSize
  • alignof(F) <= alignof(std::max_align_t)
  • std::is_nothrow_move_constructible_v<F>
Move semantics
Move-only. Invoking operator() consumes the callable (invoke + destroy), leaving the object in an empty state. This single-shot design avoids the overhead of reference counting or shared ownership.
Thread safety
Not thread-safe. Intended to be used as a queue element inside a mutex-protected task queue.
Template Parameters
TaskSizeTotal object size in bytes (default 64, one x86 cache line).

Definition at line 178 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ SboCallable() [1/4]

template<size_t TaskSize = 64>
threadschedule::detail::SboCallable< TaskSize >::SboCallable ( )
default

◆ SboCallable() [2/4]

template<size_t TaskSize = 64>
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SboCallable>>>
threadschedule::detail::SboCallable< TaskSize >::SboCallable ( F && f)
inline

Definition at line 224 of file thread_pool.hpp.

◆ SboCallable() [3/4]

template<size_t TaskSize = 64>
threadschedule::detail::SboCallable< TaskSize >::SboCallable ( SboCallable< TaskSize > && other)
inlinenoexcept

Definition at line 234 of file thread_pool.hpp.

References SboCallable().

◆ SboCallable() [4/4]

template<size_t TaskSize = 64>
threadschedule::detail::SboCallable< TaskSize >::SboCallable ( SboCallable< TaskSize > const & )
delete

References SboCallable().

◆ ~SboCallable()

template<size_t TaskSize = 64>
threadschedule::detail::SboCallable< TaskSize >::~SboCallable ( )
inline

Definition at line 262 of file thread_pool.hpp.

Member Function Documentation

◆ operator bool()

template<size_t TaskSize = 64>
threadschedule::detail::SboCallable< TaskSize >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 268 of file thread_pool.hpp.

◆ operator()()

template<size_t TaskSize = 64>
void threadschedule::detail::SboCallable< TaskSize >::operator() ( )
inline

Definition at line 273 of file thread_pool.hpp.

◆ operator=() [1/2]

template<size_t TaskSize = 64>
auto threadschedule::detail::SboCallable< TaskSize >::operator= ( SboCallable< TaskSize > && other) -> SboCallable&
inlinenoexcept

Definition at line 243 of file thread_pool.hpp.

References SboCallable().

◆ operator=() [2/2]

template<size_t TaskSize = 64>
auto threadschedule::detail::SboCallable< TaskSize >::operator= ( SboCallable< TaskSize > const & ) -> SboCallable &=delete
delete

References SboCallable().


The documentation for this class was generated from the following file: