Created
December 6, 2014 12:10
-
-
Save BenDol/9964ba39a2eb0cda624f to your computer and use it in GitHub Desktop.
Enable VLD with Dispatch Thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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