MCPcopy Create free account
hub / github.com/chen3feng/toft / AddTaskInternal

Method AddTaskInternal

system/threading/thread_pool.cpp:78–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void ThreadPool::AddTaskInternal(
79 Closure<void()>* callback,
80 const std::function<void()>& function,
81 int dispatch_key)
82{
83 DCHECK(!m_exit);
84 ThreadContext& context = m_thread_contexts[dispatch_key % m_num_threads];
85 {
86 Task* task;
87 MutexLocker locker(&context.mutex);
88 if (!context.free_tasks.empty()) {
89 task = &context.free_tasks.front();
90 context.free_tasks.pop_front();
91 task->callback = callback;
92 task->function = function;
93 } else {
94 task = new Task(callback, function);
95 }
96
97 context.pending_tasks.push_back(task);
98 context.cond.Signal();
99 }
100}
101
102void ThreadPool::AddTask(Closure<void()>* callback) {
103 // The memory address is random enough for load balance, but need

Callers

nothing calls this directly

Calls 4

pop_frontMethod · 0.80
push_backMethod · 0.80
SignalMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected