worker.hpp 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef myWORKER_H
  2. #define myWORKER_H
  3. #include <vector>
  4. #include <condition_variable>
  5. #include <mutex>
  6. #include <future>
  7. #include "jobList.hpp"
  8. #include "commFPGA.hpp"
  9. class Worker {
  10. public:
  11. Worker(std::vector<std::unique_ptr<commFPGA>> *fpgas, Module mod, size_t numberOfJobs);
  12. ~Worker();
  13. void startAsync();
  14. void startSync();
  15. JobListContainer getJobList();
  16. void setJobTimeout(microseconds us) {jobTimeout = us;}
  17. void setRetryCount(size_t n) {retryCount = n;}
  18. void setDoneCallback(DoneCallback cb);
  19. void waitUntilDone();
  20. bool isRunning() const {return running;}
  21. private:
  22. std::pair<std::mutex, std::shared_ptr<JobList>> jobList;
  23. std::vector<std::unique_ptr<commFPGA>> *fpgaVector;
  24. commFPGA* findAvailableFPGA();
  25. std::future<int> result;
  26. int threadMain();
  27. microseconds jobTimeout = microseconds(1000);
  28. size_t retryCount = 10;
  29. DoneCallback doneCb = NULL;
  30. bool running = true;
  31. };
  32. #endif