ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
registered_threads.hpp
1#pragma once
2
3#include "pthread_wrapper.hpp"
4#include "thread_registry.hpp"
5#include "thread_wrapper.hpp"
6#include <string>
7#include <utility>
8
9namespace threadschedule
10{
11
12//
13
14// Registered std::thread wrapper (opt-in)
15class ThreadWrapperReg : public ThreadWrapper
16{
17 public:
18 ThreadWrapperReg() = default;
19
20 template <typename F, typename... Args>
21 explicit ThreadWrapperReg(std::string name, std::string componentTag, F&& f, Args&&... args)
22 : ThreadWrapper(
23 [n = std::move(name), c = std::move(componentTag), func = std::forward<F>(f)](auto&&... inner) {
24 AutoRegisterCurrentThread guard(n, c);
25 func(std::forward<decltype(inner)>(inner)...);
26 },
27 std::forward<Args>(args)...)
28 {
29 }
30
31 // No generic constructor without name/tag to avoid accidental misuse
32};
33
34#if __cplusplus >= 202002L
35class JThreadWrapperReg : public JThreadWrapper
36{
37 public:
38 JThreadWrapperReg() = default;
39
40 template <typename F, typename... Args>
41 explicit JThreadWrapperReg(std::string name, std::string componentTag, F&& f, Args&&... args)
42 : JThreadWrapper(
43 [n = std::move(name), c = std::move(componentTag), func = std::forward<F>(f)](auto&&... inner) {
44 AutoRegisterCurrentThread guard(n, c);
45 func(std::forward<decltype(inner)>(inner)...);
46 },
47 std::forward<Args>(args)...)
48 {
49 }
50
51 // No generic constructor without name/tag to avoid accidental misuse
52};
53#endif
54
55#ifndef _WIN32
56class PThreadWrapperReg : public PThreadWrapper
57{
58 public:
59 PThreadWrapperReg() = default;
60
61 template <typename F, typename... Args>
62 explicit PThreadWrapperReg(std::string name, std::string componentTag, F&& f, Args&&... args)
63 : PThreadWrapper(
64 [n = std::move(name), c = std::move(componentTag), func = std::forward<F>(f)](auto&&... inner) {
65 AutoRegisterCurrentThread guard(n, c);
66 func(std::forward<decltype(inner)>(inner)...);
67 },
68 std::forward<Args>(args)...)
69 {
70 }
71
72 // No generic constructor without name/tag to avoid accidental misuse
73};
74#endif
75
76} // namespace threadschedule