MCPcopy Create free account
hub / github.com/defold/defold / Consumer

Function Consumer

engine/dlib/src/test/test_condition_variable.cpp:55–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55static void Consumer(void* arg)
56{
57 ThreadArg* a = (ThreadArg*) arg;
58
59 int i = 0;
60 while (i < MAX)
61 {
62 dmMutex::Lock(a->m_Mutex);
63 if (a->m_Buffer.Empty() && i < MAX) {
64 dmConditionVariable::Wait(a->m_More, a->m_Mutex);
65 }
66
67 while (!a->m_Buffer.Empty() && i < MAX) {
68 a->m_Sum += a->m_Buffer[0];
69 a->m_Buffer.EraseSwap(0);
70 i++;
71 }
72 dmConditionVariable::Signal(a->m_Less);
73 dmMutex::Unlock(a->m_Mutex);
74 }
75}
76
77TEST(dmConditionVariable, ProducerConsumer)
78{

Callers

nothing calls this directly

Calls 5

LockFunction · 0.50
WaitFunction · 0.50
SignalFunction · 0.50
UnlockFunction · 0.50
EmptyMethod · 0.45

Tested by

no test coverage detected