Fixed crash in TaskScheduler Windows implementation

Also replaced CreateEventA calls by CreateEventW calls to avoid one
level of function call.
Thanks to bacelar


Former-commit-id: 4612e3fb0af8eef9ffd947d8edf55e4f2fa27c9b
This commit is contained in:
Lynix 2014-06-25 15:23:31 +02:00
parent b70f693b8c
commit cc01216e1c
1 changed files with 4 additions and 5 deletions

View File

@ -34,11 +34,11 @@ bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount)
{
Worker& worker = s_workers[i];
InitializeCriticalSection(&worker.queueMutex);
worker.wakeEvent = CreateEventA(nullptr, false, false, nullptr);
worker.wakeEvent = CreateEventW(nullptr, false, false, nullptr);
worker.running = true;
worker.workCount = 0;
s_doneEvents[i] = CreateEventA(nullptr, true, false, nullptr);
s_doneEvents[i] = CreateEventW(nullptr, true, false, nullptr);
workerIDs[i] = i;
s_workerThreads[i] = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, &WorkerProc, &workerIDs[i], 0, nullptr));
@ -149,7 +149,8 @@ NzFunctor* NzTaskSchedulerImpl::StealTask(unsigned int workerID)
if (worker.workCount > 0)
{
NzFunctor* task;
NzFunctor* task = nullptr;
if (TryEnterCriticalSection(&worker.queueMutex))
{
if (!worker.queue.empty())
@ -158,8 +159,6 @@ NzFunctor* NzTaskSchedulerImpl::StealTask(unsigned int workerID)
worker.queue.pop();
worker.workCount = worker.queue.size();
}
else
task = nullptr;
LeaveCriticalSection(&worker.queueMutex);
}