worker.hpp 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. private:
  21. std::pair<std::mutex, std::shared_ptr<JobList>> jobList;
  22. std::vector<std::unique_ptr<commFPGA>> *fpgaVector;
  23. commFPGA* findAvailableFPGA();
  24. std::future<int> result;
  25. int threadMain();
  26. microseconds jobTimeout = microseconds(1000);
  27. size_t retryCount = 10;
  28. DoneCallback doneCb = NULL;
  29. bool running = true;
  30. };
  31. #endif