namespace exec
{
-Worker::~Worker()
+WorkQueue::~WorkQueue()
{
{
std::unique_lock<std::mutex> lock(_mu);
_cv.notify_all();
}
-void Worker::operator()()
+void WorkQueue::operator()()
{
while (true)
{
}
}
-void Worker::enqueue(std::unique_ptr<IFunction> &&fn)
+void WorkQueue::enqueue(std::unique_ptr<IFunction> &&fn)
{
{
std::unique_lock<std::mutex> lock{_mu};
_cv.notify_one();
}
-void Worker::terminate()
+void WorkQueue::terminate()
{
{
std::unique_lock<std::mutex> lock{_mu};
_cv.notify_all();
}
-void Worker::finish()
+void WorkQueue::finish()
{
{
std::unique_lock<std::mutex> lock{_mu};
_cv.notify_all();
}
-uint32_t Worker::numJobsInQueue()
+uint32_t WorkQueue::numJobsInQueue()
{
std::unique_lock<std::mutex> lock{_mu};
return _functions.size();
{
// TODO Extract this class to a separate file
-class Worker
+class WorkQueue
{
public:
enum class State
public:
/**
- * @brief Create Worker object
+ * @brief Create WorkQueue object
*/
- Worker() = default;
+ WorkQueue() = default;
/**
- * @brief Destroy Worker object
+ * @brief Destroy WorkQueue object
*/
- ~Worker();
+ ~WorkQueue();
/**
* @brief Thread entry function
*/
*/
void finish();
/**
- * @brief Check if it has pending jobs. Even if this returns fals, Worker threads may be still
+ * @brief Check if it has pending jobs. Even if this returns fals, WorkQueue threads may be still
* running
*
* @return true if the job queue not empty otherwise false
void join();
private:
- Worker _worker;
+ WorkQueue _worker;
std::vector<std::thread> _threads;
};