Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::detail Namespace Reference

Classes

class  callable_eraser
 Type eraser for heterogeneous callable storage. More...
 
struct  compile_string
 Compile-time string for template error messages. More...
 
class  concurrent_queue
 Thread-safe MPMC queue with blocking wait support (Internal implementation) More...
 
struct  conditional_feature
 Template for conditional compilation based on feature flags. More...
 
struct  constexpr_string
 Constexpr string utilities for compile-time job naming. More...
 
struct  function_traits
 Type trait for function signature analysis. More...
 
struct  function_traits< R(*)(Args...) noexcept >
 
struct  function_traits< R(*)(Args...)>
 
struct  function_traits< R(C::*)(Args...) const >
 
struct  function_traits< R(C::*)(Args...)>
 
struct  future_value_type
 Helper to get the value type from a future. More...
 
class  global_reclamation_manager
 Global manager for orphaned nodes from terminated threads. More...
 
struct  has_bound_policy_tag
 Detect if type has bound_policy_tag. More...
 
struct  has_bound_policy_tag< T, std::void_t< typename T::policy_tag > >
 
struct  has_bound_policy_type
 Detect if type has bound_policy_type member. More...
 
struct  has_bound_policy_type< T, std::void_t< typename T::bound_policy_type > >
 
struct  has_do_work_method
 SFINAE helper to detect if a type has a do_work method. More...
 
struct  has_do_work_method< T, std::void_t< decltype(std::declval< T >().do_work())> >
 
struct  has_get_method
 SFINAE helper to detect if a type has a specific member. More...
 
struct  has_get_method< T, std::void_t< decltype(std::declval< T >().get())> >
 
struct  has_overflow_policy_tag
 Detect if type has overflow_policy_tag. More...
 
struct  has_overflow_policy_tag< T, std::void_t< typename T::policy_tag > >
 
struct  has_overflow_policy_type
 Detect if type has overflow_policy_type member. More...
 
struct  has_overflow_policy_type< T, std::void_t< typename T::overflow_policy_type > >
 
struct  has_priority_method
 SFINAE helper to detect if a type has a specific member function. More...
 
struct  has_priority_method< T, std::void_t< decltype(std::declval< T >().priority())> >
 
struct  has_sync_policy_tag
 Detect if type has sync_policy_tag. More...
 
struct  has_sync_policy_tag< T, std::void_t< typename T::policy_tag > >
 
struct  has_sync_policy_type
 Detect if type has sync_policy_type member. More...
 
struct  has_sync_policy_type< T, std::void_t< typename T::sync_policy_type > >
 
class  hazard_pointer_registry
 Global hazard pointer registry Manages all thread-local hazard lists. More...
 
struct  is_compatible_job
 Compile-time job validation. More...
 
struct  is_compatible_job< Job, ExpectedJobType >
 
struct  is_policy_queue_impl
 Primary template: not a policy_queue. More...
 
struct  is_policy_queue_impl< policy_queue< SyncPolicy, BoundPolicy, OverflowPolicy > >
 Specialization for policy_queue template. More...
 
class  job_eraser
 Type erasure helper for heterogeneous job storage. More...
 
struct  job_type_extractor
 Template to extract job type from job classes. More...
 
struct  job_type_extractor< T >
 
struct  job_type_list
 Variadic template helper for job type lists. More...
 
struct  job_type_traits
 Type traits for job types. More...
 
struct  job_validator
 Compile-time job validation with detailed error messages. More...
 
class  lockfree_job_queue
 Lock-free Multi-Producer Multi-Consumer (MPMC) job queue (Internal implementation) More...
 
struct  priority_comparator
 Priority comparison helper with custom comparison functions. More...
 
struct  retire_node
 Retire node for pending deletion. More...
 
struct  thread_hazard_list
 Thread-local hazard pointer list Each thread maintains a small array of hazard pointers. More...
 
class  thread_impl
 Thread implementation abstraction that handles differences between std::jthread and std::thread. More...
 
struct  validate_thread_count
 Compile-time validation for thread pool configuration. More...
 

Typedefs

template<typename F >
using function_return_t = typename function_traits<F>::return_type
 Helper to get function traits.
 
template<typename F >
using function_args_t = typename function_traits<F>::argument_types
 
template<typename Job >
using job_type_t = typename job_type_extractor<Job>::type
 
template<typename T , typename = std::enable_if_t<JobType<T>>>
using job_underlying_t = typename job_type_traits<T, void>::underlying_type
 Type alias for job type conversion.
 
template<typename Future >
using future_value_type_t = typename future_value_type<Future>::type
 

Functions

template<typename T >
constexpr auto forward_if_callable (T &&t) -> std::enable_if_t< Callable< T >, T && >
 Template helper for perfect forwarding with type constraints.
 
template<typename T >
constexpr auto get_type_name ()
 Template for generating descriptive error messages.
 
template<typename F >
constexpr auto generate_job_name ()
 Template for automatic job naming based on function signature.
 
template<typename JobType , typename... Args>
constexpr auto make_job_args (Args &&... args)
 Perfect forwarding helper for job construction.
 
template<typename T >
constexpr bool can_compare_priority ()
 Helper to determine if a type can be used as a job priority.
 
template<typename T , typename = std::enable_if_t<JobType<T>>>
constexpr bool higher_priority (T lhs, T rhs) noexcept
 Compile-time priority comparison.
 
template<typename Container , typename Operation >
auto batch_apply (Container &&items, Operation &&op)
 Apply an operation to each item in a collection, returning results.
 
template<typename T >
auto collect_all (std::vector< std::future< T > > &futures) -> std::vector< T >
 Collect all results from a vector of futures.
 
void collect_all (std::vector< std::future< void > > &futures)
 Specialization of collect_all for void futures.
 
template<std::size_t... Is, typename Tuple , typename ResultTuple >
void get_all_impl (std::index_sequence< Is... >, Tuple &futures, ResultTuple &results)
 Index sequence helper for when_all implementation.
 

Variables

template<typename F >
constexpr bool Callable = concepts::Callable<F>
 
template<typename F >
constexpr bool VoidCallable = concepts::VoidCallable<F>
 
template<typename F >
constexpr bool ReturningCallable = concepts::ReturningCallable<F>
 
template<typename F , typename... Args>
constexpr bool CallableWith = concepts::CallableWith<F, Args...>
 
template<typename T >
constexpr bool Duration = concepts::Duration<T>
 
template<typename T >
constexpr bool FutureLike = concepts::FutureLike<T>
 
template<typename T >
constexpr bool JobType = concepts::JobType<T>
 
template<typename F >
constexpr bool JobCallable = concepts::JobCallable<F>
 
template<typename Job >
constexpr bool PoolJob = concepts::PoolJob<Job>
 
template<typename F >
constexpr size_t function_arity_v = function_traits<F>::arity
 
template<typename T >
constexpr bool has_get_method_v = has_get_method<T>::value
 
template<typename T >
constexpr bool has_priority_method_v = has_priority_method<T>::value
 
template<typename T >
constexpr bool has_do_work_method_v = has_do_work_method<T>::value
 
template<typename Job , typename ExpectedJobType >
constexpr bool is_compatible_job_v = is_compatible_job<Job, ExpectedJobType>::value
 

Typedef Documentation

◆ function_args_t

template<typename F >
using kcenon::thread::detail::function_args_t = typename function_traits<F>::argument_types

Definition at line 83 of file pool_traits.h.

◆ function_return_t

template<typename F >
using kcenon::thread::detail::function_return_t = typename function_traits<F>::return_type

Helper to get function traits.

Definition at line 80 of file pool_traits.h.

◆ future_value_type_t

template<typename Future >
using kcenon::thread::detail::future_value_type_t = typename future_value_type<Future>::type

Definition at line 37 of file when_helpers.h.

◆ job_type_t

template<typename Job >
using kcenon::thread::detail::job_type_t = typename job_type_extractor<Job>::type

Definition at line 68 of file template_helpers.h.

◆ job_underlying_t

template<typename T , typename = std::enable_if_t<JobType<T>>>
using kcenon::thread::detail::job_underlying_t = typename job_type_traits<T, void>::underlying_type

Type alias for job type conversion.

Definition at line 105 of file type_traits.h.

Function Documentation

◆ batch_apply()

template<typename Container , typename Operation >
auto kcenon::thread::detail::batch_apply ( Container && items,
Operation && op )

Apply an operation to each item in a collection, returning results.

Template Parameters
ContainerThe input container type (must support range-based for)
OperationCallable that takes Container::value_type and returns ResultType
Parameters
itemsCollection of items to process
opOperation to apply to each item
Returns
std::vector of results from applying op to each item

Usage Example

std::vector<int> numbers = {1, 2, 3};
auto doubled = batch_apply(std::move(numbers), [](int n) { return n * 2; });
// doubled = {2, 4, 6}
auto batch_apply(Container &&items, Operation &&op)
Apply an operation to each item in a collection, returning results.

Definition at line 45 of file batch_operations.h.

46{
47 using ResultType = decltype(op(std::move(*std::begin(items))));
48 std::vector<ResultType> results;
49 results.reserve(items.size());
50
51 for (auto&& item : items) {
52 results.push_back(op(std::move(item)));
53 }
54
55 return results;
56}

Referenced by kcenon::thread::thread_pool::submit().

Here is the caller graph for this function:

◆ can_compare_priority()

template<typename T >
bool kcenon::thread::detail::can_compare_priority ( )
constexpr

Helper to determine if a type can be used as a job priority.

Definition at line 74 of file type_traits.h.

74 {
75 if constexpr (JobType<T>) {
76 using traits = job_type_traits<T>;
77 return traits::has_ordering;
78 }
79 return false;
80 }
Type traits for job types.
Definition type_traits.h:36

References JobType.

◆ collect_all() [1/2]

template<typename T >
auto kcenon::thread::detail::collect_all ( std::vector< std::future< T > > & futures) -> std::vector<T>

Collect all results from a vector of futures.

Template Parameters
TThe value type of the futures
Parameters
futuresVector of futures to collect from
Returns
std::vector<T> containing all results

Blocks until all futures complete, collecting results in order.

Thread Safety

  • Safe to call from any thread
  • Each future.get() is called sequentially

Exception Handling

  • If any future throws, the exception propagates immediately
  • Remaining futures are not waited upon

Usage Example

std::vector<std::future<int>> futures;
// ... populate futures ...
auto results = collect_all(futures);
auto collect_all(std::vector< std::future< T > > &futures) -> std::vector< T >
Collect all results from a vector of futures.

Definition at line 83 of file batch_operations.h.

84{
85 std::vector<T> results;
86 results.reserve(futures.size());
87
88 for (auto& future : futures) {
89 results.push_back(future.get());
90 }
91
92 return results;
93}

Referenced by kcenon::thread::thread_pool::submit_wait_all().

Here is the caller graph for this function:

◆ collect_all() [2/2]

void kcenon::thread::detail::collect_all ( std::vector< std::future< void > > & futures)
inline

Specialization of collect_all for void futures.

Parameters
futuresVector of void futures to wait on

Blocks until all futures complete. Since void futures don't return values, this simply waits for completion.

Definition at line 103 of file batch_operations.h.

104{
105 for (auto& future : futures) {
106 future.get();
107 }
108}

◆ forward_if_callable()

template<typename T >
auto kcenon::thread::detail::forward_if_callable ( T && t) -> std::enable_if_t<Callable<T>, T&&>
constexpr

Template helper for perfect forwarding with type constraints.

Definition at line 109 of file pool_traits.h.

109 {
110 return std::forward<T>(t);
111 }

◆ generate_job_name()

template<typename F >
auto kcenon::thread::detail::generate_job_name ( )
constexpr

Template for automatic job naming based on function signature.

Definition at line 144 of file template_helpers.h.

144 {
145 // This would ideally use compile-time type name extraction
146 // For now, return a generic name
147 return "generated_job";
148 }

◆ get_all_impl()

template<std::size_t... Is, typename Tuple , typename ResultTuple >
void kcenon::thread::detail::get_all_impl ( std::index_sequence< Is... > ,
Tuple & futures,
ResultTuple & results )

Index sequence helper for when_all implementation.

Definition at line 43 of file when_helpers.h.

43 {
44 ((std::get<Is>(results) = std::get<Is>(futures).get()), ...);
45}

Referenced by kcenon::thread::when_all().

Here is the caller graph for this function:

◆ get_type_name()

template<typename T >
auto kcenon::thread::detail::get_type_name ( )
constexpr

Template for generating descriptive error messages.

Definition at line 195 of file pool_traits.h.

195 {
196 // This would ideally use std::source_location or compiler intrinsics
197 // For now, return a generic message
198 return "unknown_type";
199 }

◆ higher_priority()

template<typename T , typename = std::enable_if_t<JobType<T>>>
bool kcenon::thread::detail::higher_priority ( T lhs,
T rhs )
constexprnoexcept

Compile-time priority comparison.

Definition at line 90 of file type_traits.h.

90 {
91 using traits = job_type_traits<T>;
92
93 // Assume lower numerical values = higher priority
94 return traits::to_underlying(lhs) < traits::to_underlying(rhs);
95 }

Referenced by kcenon::thread::typed_job_interface< job_type >::has_higher_priority().

Here is the caller graph for this function:

◆ make_job_args()

template<typename JobType , typename... Args>
auto kcenon::thread::detail::make_job_args ( Args &&... args)
constexpr

Perfect forwarding helper for job construction.

Definition at line 225 of file template_helpers.h.

225 {
226 return std::forward_as_tuple(std::forward<Args>(args)...);
227 }

Variable Documentation

◆ Callable

template<typename F >
bool kcenon::thread::detail::Callable = concepts::Callable<F>
inlineconstexpr

Definition at line 309 of file thread_concepts.h.

◆ CallableWith

template<typename F , typename... Args>
bool kcenon::thread::detail::CallableWith = concepts::CallableWith<F, Args...>
inlineconstexpr

Definition at line 318 of file thread_concepts.h.

◆ Duration

template<typename T >
bool kcenon::thread::detail::Duration = concepts::Duration<T>
inlineconstexpr

Definition at line 321 of file thread_concepts.h.

◆ function_arity_v

template<typename F >
size_t kcenon::thread::detail::function_arity_v = function_traits<F>::arity
constexpr

Definition at line 86 of file pool_traits.h.

◆ FutureLike

template<typename T >
bool kcenon::thread::detail::FutureLike = concepts::FutureLike<T>
inlineconstexpr

Definition at line 324 of file thread_concepts.h.

◆ has_do_work_method_v

template<typename T >
bool kcenon::thread::detail::has_do_work_method_v = has_do_work_method<T>::value
constexpr

Definition at line 47 of file template_helpers.h.

◆ has_get_method_v

template<typename T >
bool kcenon::thread::detail::has_get_method_v = has_get_method<T>::value
constexpr

Definition at line 212 of file pool_traits.h.

◆ has_priority_method_v

template<typename T >
bool kcenon::thread::detail::has_priority_method_v = has_priority_method<T>::value
constexpr

Definition at line 34 of file template_helpers.h.

◆ is_compatible_job_v

template<typename Job , typename ExpectedJobType >
bool kcenon::thread::detail::is_compatible_job_v = is_compatible_job<Job, ExpectedJobType>::value
constexpr

Definition at line 85 of file template_helpers.h.

◆ JobCallable

template<typename F >
bool kcenon::thread::detail::JobCallable = concepts::JobCallable<F>
inlineconstexpr

Definition at line 330 of file thread_concepts.h.

◆ JobType

template<typename T >
bool kcenon::thread::detail::JobType = concepts::JobType<T>
inlineconstexpr

Definition at line 327 of file thread_concepts.h.

Referenced by can_compare_priority().

◆ PoolJob

template<typename Job >
bool kcenon::thread::detail::PoolJob = concepts::PoolJob<Job>
inlineconstexpr

Definition at line 333 of file thread_concepts.h.

◆ ReturningCallable

template<typename F >
bool kcenon::thread::detail::ReturningCallable = concepts::ReturningCallable<F>
inlineconstexpr

Definition at line 315 of file thread_concepts.h.

◆ VoidCallable

template<typename F >
bool kcenon::thread::detail::VoidCallable = concepts::VoidCallable<F>
inlineconstexpr

Definition at line 312 of file thread_concepts.h.