| 52 | } |
| 53 | |
| 54 | ThreadPool::ThreadPool(int num_threads): |
| 55 | m_num_threads(0), m_num_busy_threads(0), m_exit_cond(&m_exit_lock), m_exit(false) { |
| 56 | if (num_threads < 0) |
| 57 | m_num_threads = GetLogicalCpuNumber(); |
| 58 | else if (num_threads == 0) |
| 59 | m_num_threads = 1; |
| 60 | else |
| 61 | m_num_threads = num_threads; |
| 62 | |
| 63 | m_thread_contexts = new ThreadContext[m_num_threads]; |
| 64 | ThreadAttributes attr; |
| 65 | for (size_t i = 0; i < m_num_threads; ++i) { |
| 66 | attr.SetName(StringConcat("threadpool/", i)); |
| 67 | m_thread_contexts[i].thread.reset( |
| 68 | new Thread(attr, std::bind(&ThreadPool::WorkRoutine, this, &m_thread_contexts[i]))); |
| 69 | } |
| 70 | m_num_busy_threads = m_num_threads; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | ThreadPool::~ThreadPool() { |
nothing calls this directly
no test coverage detected