diff --git a/src/sled/system/thread_pool.cc b/src/sled/system/thread_pool.cc index 51773f5..cfa35f2 100644 --- a/src/sled/system/thread_pool.cc +++ b/src/sled/system/thread_pool.cc @@ -3,10 +3,11 @@ #include "sled/task_queue/task_queue_base.h" namespace sled { -ThreadPool::ThreadPool(int num_threads) +ThreadPool::ThreadPool(int num_threads) : delayed_thread_(sled::Thread::Create()) { if (num_threads == -1) { num_threads = std::thread::hardware_concurrency(); } scheduler_ = new sled::Scheduler(sled::Scheduler::Config().setWorkerThreadCount(num_threads)); + delayed_thread_->Start(); } ThreadPool::~ThreadPool() { delete scheduler_; } @@ -27,12 +28,19 @@ ThreadPool::PostDelayedTaskImpl(std::function &&task, const PostDelayedTaskTraits &traits, const Location &location) { + auto move_task_to_fiber = [task]() { task(); }; if (traits.high_precision) { - delayed_thread_->PostDelayedTaskWithPrecision(TaskQueueBase::DelayPrecision::kHigh, std::move(task), delay, - location); + delayed_thread_->PostDelayedTaskWithPrecision( + TaskQueueBase::DelayPrecision::kHigh, + std::move(move_task_to_fiber), + delay, + location); } else { - delayed_thread_->PostDelayedTaskWithPrecision(TaskQueueBase::DelayPrecision::kLow, std::move(task), delay, - location); + delayed_thread_->PostDelayedTaskWithPrecision( + TaskQueueBase::DelayPrecision::kLow, + std::move(move_task_to_fiber), + delay, + location); } }