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

Function LoadThread

engine/resource/src/async/load_queue_threaded.cpp:80–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 }
79
80 static void LoadThread(void* arg)
81 {
82 Queue* queue = (Queue*)arg;
83 Request* current = 0;
84 LoadResult result;
85 while (true)
86 {
87 {
88 dmMutex::ScopedLock lk(queue->m_Mutex);
89 if (current != 0)
90 {
91 // Just finished one (from previous iteration)
92 queue->m_BytesWaiting += current->m_Buffer.Capacity();
93 queue->m_Loaded++;
94 current->m_Result = result;
95 current = 0;
96 }
97 if (queue->m_Shutdown)
98 {
99 return;
100 }
101
102 current = GetNextRequest(queue);
103 if (current == 0x0)
104 {
105 // Nothing to do, reset any buffers of inactive requests that are not at default capacity
106 for (uint32_t i = 0; i < QUEUE_SLOTS; ++i)
107 {
108 Request* r = &queue->m_Request[i];
109 if (r->m_Buffer.Size() == 0)
110 {
111 if (r->m_Buffer.Capacity() > DEFAULT_CAPACITY)
112 {
113 // Just free the memory here, no need to allocate while holding the mutex
114 r->m_Buffer.SetCapacity(0);
115 }
116 }
117 }
118 dmConditionVariable::Wait(queue->m_WakeupCond, queue->m_Mutex);
119 current = GetNextRequest(queue);
120 }
121 }
122
123 if (current)
124 {
125 // We use the temporary result object here to fill in the data so it can be written with the mutex held.
126 DoLoadResource(queue->m_Factory, current, &current->m_Buffer, &result);
127 }
128 }
129 }
130
131 HQueue CreateQueue(dmResource::HFactory factory)
132 {

Callers

nothing calls this directly

Calls 6

GetNextRequestFunction · 0.85
DoLoadResourceFunction · 0.85
WaitFunction · 0.50
CapacityMethod · 0.45
SizeMethod · 0.45
SetCapacityMethod · 0.45

Tested by

no test coverage detected