MCPcopy Create free account
hub / github.com/cameron314/readerwriterqueue / SimpleThread

Class SimpleThread

tests/common/simplethread.h:54–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53
54class SimpleThread
55{
56private:
57 struct ThreadRef;
58
59 template<typename TCallback, typename TArgs>
60 struct CallbackWrapper
61 {
62 template<typename U>
63 CallbackWrapper(TCallback&& callback, U&& args)
64 : callback(std::forward<TCallback>(callback)), args(std::forward<U>(args))
65 {
66 }
67
68 static void callAndDelete(void* wrapper)
69 {
70 auto typedWrapper = static_cast<CallbackWrapper*>(wrapper);
71 typedWrapper->args.callCallback(std::move(typedWrapper->callback));
72 delete typedWrapper;
73 }
74
75 typename std::decay<TCallback>::type callback;
76 TArgs args;
77 };
78
79 typedef void (*CallbackFunc)(void*);
80
81 void startThread(void* callbackObj, CallbackFunc callbackFunc);
82
83
84public:
85 static const int StackSize = 4 * 1024; // bytes
86
87 SimpleThread() : thread(nullptr) { }
88
89 SimpleThread(SimpleThread&& other)
90 : thread(other.thread)
91 {
92 other.thread = nullptr;
93 }
94
95 SimpleThread& operator=(SimpleThread&& other)
96 {
97 thread = other.thread;
98 other.thread = nullptr;
99 return *this;
100 }
101
102 // Disable copying and copy-assignment
103private:
104 SimpleThread(SimpleThread const&);
105 SimpleThread& operator=(SimpleThread const&);
106public:
107
108 template<typename TCallback>
109 explicit SimpleThread(TCallback&& callback)
110 {
111 auto wrapper = new CallbackWrapper<TCallback, details::ArgWrapper<>>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected