Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ThreadPool::_processBackgroundThreadWorkers()
- {
- for (;;)
- {
- WorkItem* workItem = nullptr;
- {
- int result = SDL_TryLockMutex(mMutex);
- if (mIsStopped || mWorkItems.empty())
- {
- SDL_CondWait(mCondition, mMutex);
- }
- if (mIsStopped && mWorkItems.empty())
- {
- Con::printf("Thread worker terminated");
- SDL_UnlockMutex(mMutex);
- return;
- }
- workItem = mWorkItems.front();
- mWorkItems.pop();
- mBackgroundWorkItemCount.store(mWorkItems.size(), std::memory_order_relaxed);
- SDL_UnlockMutex(mMutex);
- }
- if (workItem != nullptr)
- {
- mNumberOfActiveWorkThreads++;
- workItem->process();
- workItem->release();
- mNumberOfActiveWorkThreads--;
- SDL_CondSignal(mWorkerThreadCondition);
- }
- }
- }
- void ThreadPool::_processBackgroundThreadWorkers()
- {
- for (;;)
- {
- WorkItem* workItem = nullptr;
- int locked = SDL_TryLockMutex(mMutex);
- if (locked == 0)
- {
- if (mIsStopped || mWorkItems.empty())
- {
- SDL_CondWait(mCondition, mMutex);
- }
- if (mIsStopped && mWorkItems.empty())
- {
- Con::printf("Thread worker terminated");
- SDL_UnlockMutex(mMutex);
- return;
- }
- workItem = mWorkItems.front();
- mWorkItems.pop();
- mBackgroundWorkItemCount.store(mWorkItems.size(), std::memory_order_relaxed);
- SDL_UnlockMutex(mMutex);
- }
- if (workItem != nullptr)
- {
- mNumberOfActiveWorkThreads++;
- workItem->process();
- workItem->release();
- mNumberOfActiveWorkThreads--;
- SDL_CondSignal(mWorkerThreadCondition);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement