jobList.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef myJOBLIST_H
  2. #define myJOBLIST_H
  3. #include <functional>
  4. #include <vector>
  5. #include "job.hpp"
  6. #include "modules.hpp"
  7. //entity to track an array of similar jobs
  8. class JobList {
  9. public:
  10. JobList(Module mod, size_t numberOfJobs);
  11. void waitAll();
  12. void waitOne(microseconds us);
  13. void finishJob();
  14. size_t getPendingJobCount() const {return pendingJobCount;}
  15. JobContainer getJob(size_t i);
  16. JobContainer getNextJob();
  17. size_t getJobCount() const {return jobCount;}
  18. std::mutex jobListLock;
  19. private:
  20. std::vector<std::shared_ptr<Job>> jobs;
  21. size_t jobCount;
  22. size_t pendingJobCount;
  23. std::condition_variable jobListDone;
  24. std::mutex pendingJobCount_m;
  25. size_t nextJobIndex = 0;
  26. };
  27. class JobListContainer {
  28. public:
  29. JobListContainer(std::pair<std::mutex, std::shared_ptr<JobList>> &p) : jobList(p.second), lock(p.first) {
  30. };
  31. JobList * operator->()const { return jobList.get(); }
  32. JobList & operator*() const { return *jobList; }
  33. std::shared_ptr<JobList>& sharedPtr() {return jobList;}
  34. private:
  35. std::shared_ptr<JobList> jobList;
  36. std::unique_lock<std::mutex> lock;
  37. };
  38. #endif