Destroy the threadpool */
| 199 | |
| 200 | /* Destroy the threadpool */ |
| 201 | void 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 */ |
| 232 | void thpool_pause(thpool_* thpool_p) { |
no test coverage detected