diff --git a/src/core/async/queued_thread_pool.cpp b/src/core/async/thread_pool.cpp similarity index 67% rename from src/core/async/queued_thread_pool.cpp rename to src/core/async/thread_pool.cpp index 999dd18..0147eed 100644 --- a/src/core/async/queued_thread_pool.cpp +++ b/src/core/async/thread_pool.cpp @@ -1,19 +1,19 @@ -#include "queued_thread_pool.h" +#include "thread_pool.h" -queued_thread_pool::queued_thread_pool(const size_t num_threads) : stop(false) { +thread_pool::thread_pool(const size_t num_threads) : stop(false) { // 创建线程 for (std::size_t i = 0; i < num_threads; ++i) { - threads.emplace_back(&queued_thread_pool::worker_thread, this); + threads.emplace_back(&thread_pool::worker_thread, this); } } -queued_thread_pool::~queued_thread_pool() { +thread_pool::~thread_pool() { stop = true; // 唤醒所有线程 task_available.broadcast_signal(); } -void queued_thread_pool::worker_thread() { +void thread_pool::worker_thread() { while (true) { // 如果线程池停止且任务队列为空,则退出 if (stop && tasks.empty()) { diff --git a/src/core/async/queued_thread_pool.h b/src/core/async/thread_pool.h similarity index 87% rename from src/core/async/queued_thread_pool.h rename to src/core/async/thread_pool.h index 11f6fd2..6a79eb0 100644 --- a/src/core/async/queued_thread_pool.h +++ b/src/core/async/thread_pool.h @@ -10,21 +10,21 @@ #include "containers/safe_queue.h" #include "containers/safe_vector.h" -class queued_thread_pool { +class thread_pool { public: /** * @brief 创建一个线程池 * @param num_threads 线程池中线程的数量, 默认为 CPU 核心数减 1, 避免主线程被占用 */ - explicit queued_thread_pool(size_t num_threads = std::thread::hardware_concurrency() - 1); - ~queued_thread_pool(); + explicit thread_pool(size_t num_threads = std::thread::hardware_concurrency() - 1); + ~thread_pool(); /** * @brief 获取全局线程池 * @return 全局线程池 */ - static queued_thread_pool& global() { - static queued_thread_pool instance; + static thread_pool& global() { + static thread_pool instance; return instance; }