Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. void ThreadPool::_processBackgroundThreadWorkers()
  3. {
  4. for (;;)
  5. {
  6. WorkItem* workItem = nullptr;
  7.  
  8. {
  9. int result = SDL_TryLockMutex(mMutex);
  10.  
  11. if (mIsStopped || mWorkItems.empty())
  12. {
  13. SDL_CondWait(mCondition, mMutex);
  14. }
  15.  
  16. if (mIsStopped && mWorkItems.empty())
  17. {
  18. Con::printf("Thread worker terminated");
  19. SDL_UnlockMutex(mMutex);
  20. return;
  21. }
  22.  
  23. workItem = mWorkItems.front();
  24. mWorkItems.pop();
  25. mBackgroundWorkItemCount.store(mWorkItems.size(), std::memory_order_relaxed);
  26.  
  27. SDL_UnlockMutex(mMutex);
  28. }
  29.  
  30. if (workItem != nullptr)
  31. {
  32. mNumberOfActiveWorkThreads++;
  33. workItem->process();
  34. workItem->release();
  35. mNumberOfActiveWorkThreads--;
  36. SDL_CondSignal(mWorkerThreadCondition);
  37. }
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. void ThreadPool::_processBackgroundThreadWorkers()
  59. {
  60. for (;;)
  61. {
  62. WorkItem* workItem = nullptr;
  63.  
  64. int locked = SDL_TryLockMutex(mMutex);
  65. if (locked == 0)
  66. {
  67. if (mIsStopped || mWorkItems.empty())
  68. {
  69. SDL_CondWait(mCondition, mMutex);
  70. }
  71.  
  72. if (mIsStopped && mWorkItems.empty())
  73. {
  74. Con::printf("Thread worker terminated");
  75. SDL_UnlockMutex(mMutex);
  76. return;
  77. }
  78.  
  79. workItem = mWorkItems.front();
  80. mWorkItems.pop();
  81. mBackgroundWorkItemCount.store(mWorkItems.size(), std::memory_order_relaxed);
  82.  
  83. SDL_UnlockMutex(mMutex);
  84. }
  85.  
  86. if (workItem != nullptr)
  87. {
  88. mNumberOfActiveWorkThreads++;
  89. workItem->process();
  90. workItem->release();
  91. mNumberOfActiveWorkThreads--;
  92. SDL_CondSignal(mWorkerThreadCondition);
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement