main.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, 1000);
  8. worker->setJobTimeout(milliseconds(1000));
  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(50));
  47. connectionManager.start();
  48. int workNum = 100;
  49. while(workNum > 0 || connectionManager.getWorkerCount() > 0) {
  50. connectionManager.removeFinishedWorkers();
  51. while(workNum > 0 && connectionManager.getWorkerCount() < 8) {
  52. workNum--;
  53. work();
  54. }
  55. printf("work: %2d worker: %2lu\n", workNum, connectionManager.getWorkerCount());
  56. std::this_thread::sleep_for(milliseconds(300));
  57. }
  58. std::unique_lock<std::mutex> lk(statsLk);
  59. printf("failed: %lu, successful: %lu, retries: %lu\n", f, s, r);
  60. return 0;
  61. }