main.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdio.h>
  2. #include "connectionManager.hpp"
  3. ConnectionManager connectionManager;
  4. size_t s=0, f=0, r=0;
  5. std::mutex statsLk;
  6. void work() {
  7. auto worker = connectionManager.createWorker(Module::dummyBigModule, 10000);
  8. worker->setJobTimeout(milliseconds(100));
  9. worker->setRetryCount(10);
  10. worker->setDoneCallback([worker](){
  11. auto jobs = worker->getJobList();
  12. std::unique_lock<std::mutex> lk(statsLk);
  13. for(size_t i=0; i<jobs->getJobCount(); i++) {
  14. auto job = jobs->getJob(i);
  15. if(job->getState() == JobState::finished) {
  16. s++;
  17. } else if(job->getState() == JobState::failed) {
  18. f++;
  19. } else {
  20. printf("job %08X: invalid state %d\n", job->getJobId(), (int)job->getState());
  21. }
  22. r += job->getSendCounter() - 1;
  23. }
  24. });
  25. {
  26. auto jobs = worker->getJobList();
  27. for(size_t i=0; i<jobs->getJobCount(); i++) {
  28. auto job = jobs->getJob(i);
  29. static int num=0;
  30. job->setPayload(0, num);
  31. job->setPayload(1, num);
  32. job->setPayload(2, num);
  33. job->setPayload(3, num++);
  34. job->setReady();
  35. }
  36. }
  37. worker->startAsync();
  38. }
  39. int main(void)
  40. {
  41. puts("This is a shared library test...");
  42. connectionManager.addFPGA("192.168.1.32", 1234);
  43. connectionManager.addFPGA("192.168.1.32", 1234);
  44. connectionManager.addFPGA("192.168.1.32", 1234);
  45. connectionManager.addFPGA("192.168.1.32", 1234);
  46. //connectionManager.setSendDelay(microseconds(0));
  47. connectionManager.start();
  48. for(int i=0; i<8; i++)
  49. work();
  50. for(size_t i=0; i<connectionManager.getWorkerCount(); i++) {
  51. connectionManager.getWorker(i)->waitUntilDone();
  52. }
  53. std::unique_lock<std::mutex> lk(statsLk);
  54. printf("failed: %lu, successful: %lu, retries: %lu\n", f, s, r);
  55. return 0;
  56. }