| 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, ¤t->m_Buffer, &result); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | HQueue CreateQueue(dmResource::HFactory factory) |
| 132 | { |
nothing calls this directly
no test coverage detected