MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / ThreadPool

Method ThreadPool

include/RavEngine/ThreadPool.hpp:31–56  ·  view source on GitHub ↗

the constructor just launches some amount of workers

Source from the content-addressed store, hash-verified

29
30// the constructor just launches some amount of workers
31inline ThreadPool::ThreadPool(size_t threads)
32 : stop(false)
33{
34 for (size_t i = 0; i < threads; ++i)
35 workers.emplace_back(
36 [this]
37 {
38 for (;;)
39 {
40 std::packaged_task<void()> task;
41
42 {
43 std::unique_lock<std::mutex> lock(this->queue_mutex);
44 this->condition.wait(lock,
45 [this] { return this->stop || !this->tasks.empty(); });
46 if (this->stop && this->tasks.empty())
47 return;
48 task = std::move(this->tasks.front());
49 this->tasks.pop();
50 }
51
52 task();
53 }
54 }
55 );
56}
57
58// add new work item to the pool
59template<class F, class... Args>

Callers

nothing calls this directly

Calls 5

emplace_backMethod · 0.45
waitMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected