JobControl_s.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "ThirdPartyHeadersBegin.h"
  3. #if defined _WIN32
  4. #include <windows.h>
  5. #else
  6. #include <pthread.h>
  7. #if defined __APPLE__
  8. #include <sys/types.h>
  9. #include <sys/sysctl.h>
  10. #endif
  11. #endif
  12. #include "ThirdPartyHeadersEnd.h"
  13. #include "MASTER.h"
  14. #include "GLOBAL.h"
  15. #include "Mutex_s.h"
  16. #if defined _WIN32
  17. typedef HANDLE pthread_t;
  18. #endif
  19. struct ___2122 { ___2664 ___2494; std::vector<pthread_t> ___2648; static int ___2827(); ___2122() { ___2494 = new ___2665(); } ~___2122() { delete ___2494; } struct ThreadJobData { ___4160 m_job; ___90 m_jobData; ThreadJobData(___4160 ___2118, ___90 ___2123) : m_job(___2118) , m_jobData(___2123) {} };
  20. #if defined _WIN32
  21. static DWORD WINAPI ___4162(LPVOID data);
  22. #else
  23. static void *___4162(void* data);
  24. #endif
  25. void addJob(___4160 ___2118, ___90 ___2123); void wait(); void lock() { ___2494->lock(); } void unlock() { ___2494->unlock(); } }; inline int ___2122::___2827() { int ___2828 = 0;
  26. #if defined _WIN32
  27. SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); ___2828 = static_cast<int>(sysinfo.dwNumberOfProcessors);
  28. #elif defined __APPLE__
  29. int nm[2]; size_t len = 4; uint32_t count; nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { nm[1] = HW_NCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) count = 1; } ___2828 = static_cast<int>(count);
  30. #else
  31. ___2828 = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
  32. #endif
  33. return ___2828; }
  34. #if defined _WIN32
  35. inline DWORD WINAPI ___2122::___4162(LPVOID data)
  36. #else
  37. inline void *___2122::___4162(void* data)
  38. #endif
  39. { ThreadJobData* ___2123 = reinterpret_cast<ThreadJobData*>(data); ___2123->m_job(___2123->m_jobData); delete ___2123; return NULL; } inline void ___2122::addJob(___4160 ___2118, ___90 ___2123) { lock(); ___2122::ThreadJobData* threadJobData = new ThreadJobData(___2118, ___2123);
  40. #if defined _WIN32
  41. ___2648.push_back(CreateThread( NULL, 0, ___4162, threadJobData, 0, NULL));
  42. #else
  43. pthread_t thread; pthread_create(&thread, NULL, ___4162, (void*)threadJobData); ___2648.push_back(thread);
  44. #endif
  45. unlock(); } inline void ___2122::wait() { size_t i; for(i = 0; i < ___2648.size(); ++i) { lock(); pthread_t thr = ___2648[i]; unlock();
  46. #if defined _WIN32
  47. WaitForSingleObject(thr, INFINITE);
  48. #else
  49. pthread_join(thr, NULL);
  50. #endif
  51. } lock(); ___2648.erase(___2648.begin(), ___2648.begin() + i); unlock(); }