MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / WorkerFunction

Method WorkerFunction

Sources/nCine/Threading/ThreadPool.cpp:48–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 }
47
48 void ThreadPool::WorkerFunction(void* arg)
49 {
50 ThreadStruct* threadStruct = static_cast<ThreadStruct*>(arg);
51
52 LOGD("Worker thread {} is starting", Thread::GetCurrentId());
53
54 while (true) {
55 threadStruct->queueMutex->Lock();
56 while (threadStruct->queue->empty() && !threadStruct->shouldQuit) {
57 threadStruct->queueCV->Wait(*(threadStruct->queueMutex));
58 }
59
60 if (threadStruct->shouldQuit) {
61 threadStruct->queueMutex->Unlock();
62 break;
63 }
64
65 std::unique_ptr<IThreadCommand> threadCommand = std::move(threadStruct->queue->front());
66 threadStruct->queue->pop_front();
67 threadStruct->queueMutex->Unlock();
68
69 LOGD("Worker thread {} is executing its command", Thread::GetCurrentId());
70 threadCommand->Execute();
71 }
72
73 LOGD("Worker thread {} is exiting", Thread::GetCurrentId());
74 }
75
76}
77

Callers

nothing calls this directly

Calls 7

pop_frontMethod · 0.80
ExecuteMethod · 0.80
LockMethod · 0.45
emptyMethod · 0.45
WaitMethod · 0.45
UnlockMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected