MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / destroy

Method destroy

Libraries/Threading/ThreadPool.cpp:135–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135SC::Result SC::ThreadPool::destroy()
136{
137 {
138 poolMutex.lock();
139 auto deferUnlock = MakeDeferred([this] { poolMutex.unlock(); });
140 if (numWorkerThreads == 0)
141 {
142 return Result(true); // this was already destroyed
143 }
144 // 1. Free tasks that have not been executed yet
145 while (taskHead)
146 {
147 Task* task = taskHead->next;
148 taskHead->next = nullptr;
149 taskHead->threadPool = nullptr;
150 taskHead = task;
151 }
152 taskTail = nullptr;
153
154 // 2. Request all threads to stop
155 stopRequested = true;
156 taskAvailable.broadcast();
157 }
158
159 // 3. Wait for all tasks to stop
160 Result res = waitForAllTasks();
161
162 // 4. Reset the stop flag
163 stopRequested = false;
164 return res;
165}
166
167SC::Result SC::ThreadPool::waitForAllTasks()
168{

Callers

nothing calls this directly

Calls 5

MakeDeferredFunction · 0.85
ResultClass · 0.50
lockMethod · 0.45
unlockMethod · 0.45
broadcastMethod · 0.45

Tested by

no test coverage detected