MCPcopy Create free account
hub / github.com/baidu/babylon / start

Method start

src/babylon/executor.cpp:92–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92int ThreadPoolExecutor::start() noexcept {
93 if (_running.load(::std::memory_order_acquire)) {
94 return -1;
95 }
96 _running.store(true, ::std::memory_order_release);
97 _global_task_queue.reserve_and_clear(_global_capacity * 2);
98 _local_task_queues.set_constructor(
99 [this](ConcurrentBoundedQueue<Task>* queue) {
100 new (queue) ConcurrentBoundedQueue<Task>;
101 queue->reserve_and_clear(_local_capacity * 2);
102 });
103 _threads.reserve(_worker_number);
104 for (size_t i = 0; i < _worker_number; ++i) {
105 _threads.emplace_back(&ThreadPoolExecutor::keep_execute, this);
106 }
107 if (_balance_interval.count() >= 0) {
108 _balance_thread = ::std::thread(&ThreadPoolExecutor::keep_balance, this);
109 }
110 return 0;
111}
112
113void ThreadPoolExecutor::wakeup_one_worker() noexcept {
114 _global_task_queue.push<true, false, true>(

Callers

nothing calls this directly

Calls 6

loadMethod · 0.80
emplace_backMethod · 0.80
reserve_and_clearMethod · 0.45
set_constructorMethod · 0.45
reserveMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected