Merge branch 'master' of code.uocat.com:tqcq/sled
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 2m8s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m24s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m17s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m22s

This commit is contained in:
tqcq 2024-03-31 22:07:58 +08:00
commit a711d6bfb4

View File

@ -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);
} }
} }