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
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:
commit
a711d6bfb4
@ -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<void()> &&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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user