Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::ThreadPool Class Referencefinal
Inheritance diagram for CPPHTTPLIB_NAMESPACE::ThreadPool:
Collaboration diagram for CPPHTTPLIB_NAMESPACE::ThreadPool:

Classes

struct  worker

Public Member Functions

 ThreadPool (size_t n, size_t mqr=0)
 ThreadPool (const ThreadPool &)=delete
bool enqueue (std::function< void()> fn) override
void shutdown () override
Public Member Functions inherited from CPPHTTPLIB_NAMESPACE::TaskQueue
virtual void on_idle ()

Private Attributes

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_

Friends

struct worker

Constructor & Destructor Documentation

◆ 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 }

Member Function Documentation

◆ 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 // Stop all worker threads...
282407 {
282408 duckdb::unique_lock<std::mutex> lock(mutex_);
282409 shutdown_ = true;
282410 }
282411
282412 cond_.notify_all();
282413
282414 // Join...
282415 for (auto &t : threads_) {
282416 t.join();
282417 }
282418 }

The documentation for this class was generated from the following file: