9 _workers.emplace_back([&] {
16 YACLIB_DEBUG(!_workers.empty(),
"You need explicitly join ThreadPool");
24 std::lock_guard lock{_m};
29 std::unique_lock lock{_m};
42 std::unique_lock lock{_m};
44 Stop(std::move(lock));
51 Stop(std::unique_lock{_m});
55 std::unique_lock lock{_m};
57 Stop(std::move(lock));
58 while (!
jobs.Empty()) {
59 auto& job =
jobs.PopFront();
60 static_cast<Job&
>(job).Drop();
65 for (
auto&
worker : _workers) {
71void FairThreadPool::Loop()
noexcept {
72 std::unique_lock lock{_m};
74 while (!_jobs.
Empty()) {
77 static_cast<Job&
>(job).Call();
81 if (NoJobs() && WantStop()) {
82 return Stop(std::move(lock));
92 return (_jobs_count & 1U) != 0;
96 return (_jobs_count & 2U) != 0;
100 return (_jobs_count >> 2U) == 0;
void Submit(Job &task) noexcept final
Submit given job.
bool Alive() const noexcept final
Return true if executor still alive, that means job passed to submit will be Call.
Type Tag() const noexcept final
Return type of this executor.
~FairThreadPool() noexcept override
void Wait() noexcept
TODO(kononovk) Rename to Join.
A intrusive pointer to objects with an embedded reference count.
Callable that can be executed in an IExecutor.
bool Empty() const noexcept
Node & PopFront() noexcept
#define YACLIB_DEBUG(cond, message)
IntrusivePtr< FairThreadPool > MakeFairThreadPool(std::uint64_t threads=yaclib_std::thread::hardware_concurrency())
Contract< V, E > MakeContract()
Creates related future and promise.