mirror of https://github.com/PentHertz/srsLTE.git
thread_pool: add optional ID to thread pool
this allows to prepend an ID to each thread pool to better differentiate workers from different pools
This commit is contained in:
parent
4d9d882d75
commit
3b5344b0f7
|
@ -64,7 +64,7 @@ public:
|
|||
bool is_stopped() const;
|
||||
};
|
||||
|
||||
thread_pool(uint32_t nof_workers);
|
||||
thread_pool(uint32_t nof_workers_, std::string id_ = "");
|
||||
void init_worker(uint32_t id, worker*, uint32_t prio = 0, uint32_t mask = 255);
|
||||
void stop();
|
||||
worker* wait_worker_id(uint32_t id);
|
||||
|
@ -74,12 +74,14 @@ public:
|
|||
void start_worker(uint32_t id);
|
||||
worker* get_worker(uint32_t id);
|
||||
uint32_t get_nof_workers();
|
||||
std::string get_id();
|
||||
|
||||
private:
|
||||
bool find_finished_worker(uint32_t tti, uint32_t* id);
|
||||
|
||||
typedef enum { STOP, IDLE, START_WORK, WORKER_READY, WORKING } worker_status;
|
||||
|
||||
std::string id; // id is prepended to every worker
|
||||
std::vector<worker*> workers = {};
|
||||
uint32_t nof_workers = 0;
|
||||
uint32_t max_workers = 0;
|
||||
|
|
|
@ -41,7 +41,7 @@ void thread_pool::worker::setup(uint32_t id, thread_pool* parent, uint32_t prio,
|
|||
|
||||
void thread_pool::worker::run_thread()
|
||||
{
|
||||
set_name(std::string("WORKER") + std::to_string(my_id));
|
||||
set_name(my_parent->get_id() + std::string("WORKER") + std::to_string(my_id));
|
||||
while (running.load(std::memory_order_relaxed)) {
|
||||
wait_to_start();
|
||||
if (running.load(std::memory_order_relaxed)) {
|
||||
|
@ -61,9 +61,9 @@ uint32_t thread_pool::worker::get_id()
|
|||
return my_id;
|
||||
}
|
||||
|
||||
thread_pool::thread_pool(uint32_t max_workers_) : workers(max_workers_), status(max_workers_), cvar_worker(max_workers_)
|
||||
thread_pool::thread_pool(uint32_t max_workers_, std::string id_) :
|
||||
workers(max_workers_), max_workers(max_workers_), status(max_workers_), cvar_worker(max_workers_), id(id_)
|
||||
{
|
||||
max_workers = max_workers_;
|
||||
for (uint32_t i = 0; i < max_workers; i++) {
|
||||
workers[i] = NULL;
|
||||
status[i] = IDLE;
|
||||
|
@ -253,6 +253,11 @@ uint32_t thread_pool::get_nof_workers()
|
|||
return nof_workers;
|
||||
}
|
||||
|
||||
std::string thread_pool::get_id()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* task_thread_pool - uses a queue to enqueue callables, that start
|
||||
* once a worker is available
|
||||
|
|
Loading…
Reference in New Issue