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

Class SimpleThread

tests/common/simplethread.h:62–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 15

run_testFunction · 0.85
producer_reuseMethod · 0.85
block_recyclingMethod · 0.85
try_dequeue_threadedMethod · 0.85
exceptionsMethod · 0.85
test_threaded_bulkMethod · 0.85
blocking_wrappersMethod · 0.85
acquire_and_signalMethod · 0.85

Calls

no outgoing calls

Tested by 15

run_testFunction · 0.68
producer_reuseMethod · 0.68
block_recyclingMethod · 0.68
try_dequeue_threadedMethod · 0.68
exceptionsMethod · 0.68
test_threaded_bulkMethod · 0.68
blocking_wrappersMethod · 0.68
acquire_and_signalMethod · 0.68