Skip to content

Instantly share code, notes, and snippets.

@BenDol
Created December 6, 2014 12:10
Show Gist options
  • Save BenDol/9964ba39a2eb0cda624f to your computer and use it in GitHub Desktop.
Save BenDol/9964ba39a2eb0cda624f to your computer and use it in GitHub Desktop.
Enable VLD with Dispatch Thread
void Dispatcher::dispatcherThread()
{
VLDEnable();
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
// NOTE: second argument defer_lock is to prevent from immediate locking
std::unique_lock<std::mutex> taskLockUnique(m_taskLock, std::defer_lock);
while (m_threadState != STATE_TERMINATED) {
// check if there are tasks waiting
taskLockUnique.lock();
if (m_taskList.empty()) {
//if the list is empty wait for signal
m_taskSignal.wait(taskLockUnique);
}
if (!m_taskList.empty() && m_threadState != STATE_TERMINATED) {
// take the first task
Task* task = m_taskList.front();
m_taskList.pop_front();
taskLockUnique.unlock();
if (!task->hasExpired()) {
// execute it
outputPool->startExecutionFrame();
(*task)();
outputPool->sendAll();
g_game.clearSpectatorCache();
}
delete task;
} else {
taskLockUnique.unlock();
}
}
VLDDisable();
VLDReportLeaks();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment