#pragma once ///////////////////////////////////////////////////////////////////// // Task.h - Enqueue work item to run on a threadpool thread // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2016 // ///////////////////////////////////////////////////////////////////// /* * Threadpool makes copy of each work item on the heap in case it * changes before executing. Copy is deleted after execution. * * This means that work items have to be copyable. */ #include #include #include "../ThreadPool/ThreadPool.h" class Task { public: using CallObj = std::function; Task() {} Task(const Task&) = delete; Task& operator=(const Task&) = delete; void workItem(CallObj* pCo); void wait(); std::mutex& mutex(); static ThreadPool& threadPool() { return trpl_; } private: static ThreadPool trpl_; }; inline std::mutex& Task::mutex() { return trpl_.mutex(); }