lzham_null_threading.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // File: lzham_task_pool_null.h
  2. // See Copyright Notice and license at the end of include/lzham.h
  3. #pragma once
  4. namespace lzham
  5. {
  6. class semaphore
  7. {
  8. LZHAM_NO_COPY_OR_ASSIGNMENT_OP(semaphore);
  9. public:
  10. inline semaphore(long initialCount = 0, long maximumCount = 1, const char* pName = NULL)
  11. {
  12. (void)initialCount, (void)maximumCount, (void)pName;
  13. }
  14. inline ~semaphore()
  15. {
  16. }
  17. inline void release(long releaseCount = 1, long *pPreviousCount = NULL)
  18. {
  19. (void)releaseCount, (void)pPreviousCount;
  20. }
  21. inline bool wait(uint32 milliseconds = UINT32_MAX)
  22. {
  23. (void)milliseconds;
  24. return true;
  25. }
  26. };
  27. class task_pool
  28. {
  29. public:
  30. inline task_pool() { }
  31. inline task_pool(uint num_threads) { (void)num_threads; }
  32. inline ~task_pool() { }
  33. inline bool init(uint num_threads) { (void)num_threads; return true; }
  34. inline void deinit();
  35. inline uint get_num_threads() const { return 0; }
  36. inline uint get_num_outstanding_tasks() const { return 0; }
  37. // C-style task callback
  38. typedef void (*task_callback_func)(uint64 data, void* pData_ptr);
  39. inline bool queue_task(task_callback_func pFunc, uint64 data = 0, void* pData_ptr = NULL)
  40. {
  41. pFunc(data, pData_ptr);
  42. return true;
  43. }
  44. class executable_task
  45. {
  46. public:
  47. virtual void execute_task(uint64 data, void* pData_ptr) = 0;
  48. };
  49. // It's the caller's responsibility to delete pObj within the execute_task() method, if needed!
  50. inline bool queue_task(executable_task* pObj, uint64 data = 0, void* pData_ptr = NULL)
  51. {
  52. pObj->execute_task(data, pData_ptr);
  53. return true;
  54. }
  55. template<typename S, typename T>
  56. inline bool queue_object_task(S* pObject, T pObject_method, uint64 data = 0, void* pData_ptr = NULL)
  57. {
  58. (pObject->*pObject_method)(data, pData_ptr);
  59. return true;
  60. }
  61. template<typename S, typename T>
  62. inline bool queue_multiple_object_tasks(S* pObject, T pObject_method, uint64 first_data, uint num_tasks, void* pData_ptr = NULL)
  63. {
  64. for (uint i = 0; i < num_tasks; i++)
  65. {
  66. (pObject->*pObject_method)(first_data + i, pData_ptr);
  67. }
  68. return true;
  69. }
  70. void join() { }
  71. };
  72. inline void lzham_sleep(unsigned int milliseconds)
  73. {
  74. (void)milliseconds;
  75. }
  76. inline uint lzham_get_max_helper_threads()
  77. {
  78. return 0;
  79. }
  80. } // namespace lzham