fix thread pool not start
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 2m8s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m32s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m58s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m53s
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 2m8s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m32s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m58s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m53s
This commit is contained in:
parent
3c43c4ff58
commit
5f528c1a1b
@ -3,10 +3,11 @@
|
|||||||
#include "sled/task_queue/task_queue_base.h"
|
#include "sled/task_queue/task_queue_base.h"
|
||||||
|
|
||||||
namespace sled {
|
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(); }
|
if (num_threads == -1) { num_threads = std::thread::hardware_concurrency(); }
|
||||||
scheduler_ = new sled::Scheduler(sled::Scheduler::Config().setWorkerThreadCount(num_threads));
|
scheduler_ = new sled::Scheduler(sled::Scheduler::Config().setWorkerThreadCount(num_threads));
|
||||||
|
delayed_thread_->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool::~ThreadPool() { delete scheduler_; }
|
ThreadPool::~ThreadPool() { delete scheduler_; }
|
||||||
@ -27,11 +28,18 @@ ThreadPool::PostDelayedTaskImpl(std::function<void()> &&task,
|
|||||||
const PostDelayedTaskTraits &traits,
|
const PostDelayedTaskTraits &traits,
|
||||||
const Location &location)
|
const Location &location)
|
||||||
{
|
{
|
||||||
|
auto move_task_to_fiber = [task]() { task(); };
|
||||||
if (traits.high_precision) {
|
if (traits.high_precision) {
|
||||||
delayed_thread_->PostDelayedTaskWithPrecision(TaskQueueBase::DelayPrecision::kHigh, std::move(task), delay,
|
delayed_thread_->PostDelayedTaskWithPrecision(
|
||||||
|
TaskQueueBase::DelayPrecision::kHigh,
|
||||||
|
std::move(move_task_to_fiber),
|
||||||
|
delay,
|
||||||
location);
|
location);
|
||||||
} else {
|
} else {
|
||||||
delayed_thread_->PostDelayedTaskWithPrecision(TaskQueueBase::DelayPrecision::kLow, std::move(task), delay,
|
delayed_thread_->PostDelayedTaskWithPrecision(
|
||||||
|
TaskQueueBase::DelayPrecision::kLow,
|
||||||
|
std::move(move_task_to_fiber),
|
||||||
|
delay,
|
||||||
location);
|
location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user