| 202 | } |
| 203 | |
| 204 | void FreeLoad(HQueue queue, HRequest request) |
| 205 | { |
| 206 | dmMutex::ScopedLock lk(queue->m_Mutex); |
| 207 | |
| 208 | uint32_t old_bytes_waiting = queue->m_BytesWaiting; |
| 209 | |
| 210 | uint32_t buffer_capacity = request->m_Buffer.Capacity(); |
| 211 | queue->m_BytesWaiting -= buffer_capacity; |
| 212 | |
| 213 | if (request->m_Result.m_IsBufferOwnershipTransferred) |
| 214 | { |
| 215 | // we reset the dmArray (size = 0, capacity = 0) |
| 216 | memset((void*)&request->m_Buffer, 0, sizeof(request->m_Buffer)); |
| 217 | } |
| 218 | |
| 219 | // Make sure we don't copy any data if we reallocate the buffer |
| 220 | request->m_Buffer.SetSize(0); |
| 221 | |
| 222 | // If we either have blocked further processing by exceeding MAX_PENDING_DATA or |
| 223 | // the buffer has a non-default capacity, we want to wake up the worker |
| 224 | if (buffer_capacity != DEFAULT_CAPACITY || (old_bytes_waiting >= MAX_PENDING_DATA && queue->m_BytesWaiting < MAX_PENDING_DATA)) |
| 225 | { |
| 226 | // Wake up thread, we can now fit a new request |
| 227 | dmConditionVariable::Signal(queue->m_WakeupCond); |
| 228 | } |
| 229 | |
| 230 | // Clean up picked up requests |
| 231 | request->m_Name = 0x0; |
| 232 | request->m_CanonicalPath = 0x0; |
| 233 | |
| 234 | while (queue->m_Back != queue->m_Loaded && queue->m_Request[queue->m_Back % QUEUE_SLOTS].m_Name == 0x0) |
| 235 | { |
| 236 | queue->m_Back++; |
| 237 | } |
| 238 | } |
| 239 | } // namespace dmLoadQueue |