|
| | ThreadPool (size_t n, size_t mqr=0) |
|
| ThreadPool (const ThreadPool &)=delete |
| bool | enqueue (std::function< void()> fn) override |
| void | shutdown () override |
| virtual void | on_idle () |
|
|
std::vector< std::thread > | threads_ |
|
std::list< std::function< void()> > | jobs_ |
|
bool | shutdown_ |
|
size_t | max_queued_requests_ = 0 |
|
std::condition_variable | cond_ |
|
std::mutex | mutex_ |
◆ ThreadPool()
| CPPHTTPLIB_NAMESPACE::ThreadPool::ThreadPool |
( |
size_t | n, |
|
|
size_t | mqr = 0 ) |
|
inlineexplicit |
282382 : shutdown_(false), max_queued_requests_(mqr) {
282383 while (n) {
282384 threads_.emplace_back(worker(*this));
282385 n--;
282386 }
282387 }
◆ enqueue()
| bool CPPHTTPLIB_NAMESPACE::ThreadPool::enqueue |
( |
std::function< void()> | fn | ) |
|
|
inlineoverridevirtual |
Implements CPPHTTPLIB_NAMESPACE::TaskQueue.
282392 {
282393 {
282394 duckdb::unique_lock<std::mutex> lock(mutex_);
282395 if (max_queued_requests_ > 0 && jobs_.size() >= max_queued_requests_) {
282396 return false;
282397 }
282398 jobs_.push_back(std::move(fn));
282399 }
282400
282401 cond_.notify_one();
282402 return true;
282403 }
◆ shutdown()
| void CPPHTTPLIB_NAMESPACE::ThreadPool::shutdown |
( |
| ) |
|
|
inlineoverridevirtual |
Implements CPPHTTPLIB_NAMESPACE::TaskQueue.
282405 {
282406
282407 {
282408 duckdb::unique_lock<std::mutex> lock(mutex_);
282409 shutdown_ = true;
282410 }
282411
282412 cond_.notify_all();
282413
282414
282415 for (auto &t : threads_) {
282416 t.join();
282417 }
282418 }
The documentation for this class was generated from the following file: