Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
|
- #pragma once
-
- #include <atomic>
- #include <vector>
-
- #include <ecs/config.h>
- #include <ecs/core/utils/thread_pool/worker.h>
- #include <ecs/core/utils/thread_pool/task_queue.h>
-
- namespace ecs {
- namespace core {
- namespace utils {
-
- /**
- * this class implements a thread pool
- */
- struct thread_pool
- {
- private:
- using worker_ptr_u = std::unique_ptr<thread_pool_worker>;
- using worker_vector = std::vector<worker_ptr_u>;
- using atomic_size_t = std::atomic<size_t>;
-
- private:
- concurrent_task_queue _tasks; //!< queue to store tasks to execute
- worker_vector _workers; //!< vector of worker threads
- atomic_size_t _outstanding_inits; //!< number of outstanding worker initializations
-
- /**
- * check if all workers are finished or not
- *
- * @retval TRUE if all workers are finished
- * @retval FALSE if at least one worker is running
- */
- auto all_workers_finished() const noexcept;
-
- /**
- * initialize worker threads
- *
- * @param count number of workers to create
- */
- void initialize_workers(size_t count);
-
- public:
- /**
- * constructor
- *
- * @param count number of workers to create
- */
- thread_pool(size_t count);
-
- /**
- * destructor
- */
- ~thread_pool();
-
- /**
- * enqueue a new task inside the thread pool
- *
- * @tparam T_task type of the task
- *
- * @param task task to execute
- * @param worker_id id of the worker to enqueue task at (-1 = any; n = worker tasks)
- */
- template<typename T_task>
- inline void post(T_task&& task, ssize_t worker_id = -1);
- };
-
- } } }
|