MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / thpool_destroy

Function thpool_destroy

src/util/thpool/thpool.c:201–229  ·  view source on GitHub ↗

Destroy the threadpool */

Source from the content-addressed store, hash-verified

199
200/* Destroy the threadpool */
201void thpool_destroy(thpool_* thpool_p) {
202 /* No need to destory if it's NULL */
203 if (thpool_p == NULL) {
204 return;
205 }
206
207 const uint32_t threads_total = thpool_p->num_threads_alive;
208
209 /* Make the threads leave their main loops. */
210 threads_keepalive = 0;
211
212 // Wake up the threads so that they exit and will become ready to be
213 // destroyed.
214 while(thpool_p->num_threads_alive) {
215 bsem_post_all(thpool_p->jobqueue.has_jobs);
216 }
217
218 // Destroy the threads.
219 for (size_t i = 0; i < threads_total; ++i) {
220 ASSERT(pthread_join(thpool_p->threads[i]->pthread, NULL) == 0);
221 thread_destroy(thpool_p->threads[i]);
222 }
223 rm_free(thpool_p->threads);
224
225 /* Job queue cleanup */
226 jobqueue_destroy(&thpool_p->jobqueue);
227
228 rm_free(thpool_p);
229}
230
231/* Pause all threads in threadpool */
232void thpool_pause(thpool_* thpool_p) {

Callers 1

ThreadPools_DestroyFunction · 0.85

Calls 4

bsem_post_allFunction · 0.85
thread_destroyFunction · 0.85
rm_freeFunction · 0.85
jobqueue_destroyFunction · 0.85

Tested by

no test coverage detected