MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / worker

Class worker

examples/server/httplib.h:628–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626
627private:
628 struct worker {
629 explicit worker(ThreadPool &pool) : pool_(pool) {}
630
631 void operator()() {
632 for (;;) {
633 std::function<void()> fn;
634 {
635 std::unique_lock<std::mutex> lock(pool_.mutex_);
636
637 pool_.cond_.wait(
638 lock, [&] { return !pool_.jobs_.empty() || pool_.shutdown_; });
639
640 if (pool_.shutdown_ && pool_.jobs_.empty()) { break; }
641
642 fn = std::move(pool_.jobs_.front());
643 pool_.jobs_.pop_front();
644 }
645
646 assert(true == static_cast<bool>(fn));
647 fn();
648 }
649 }
650
651 ThreadPool &pool_;
652 };
653 friend struct worker;
654
655 std::vector<std::thread> threads_;

Callers 1

ThreadPoolMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected