| 151 | } |
| 152 | |
| 153 | void TextureLoader::threadProc() |
| 154 | { |
| 155 | while (!mExit) |
| 156 | { |
| 157 | std::shared_ptr<TextureData> textureData; |
| 158 | { |
| 159 | // Wait for an event to say there is something in the queue |
| 160 | std::unique_lock<std::mutex> lock(mMutex); |
| 161 | mEvent.wait(lock); |
| 162 | if (!mTextureDataQ.empty()) |
| 163 | { |
| 164 | textureData = mTextureDataQ.front(); |
| 165 | mTextureDataQ.pop_front(); |
| 166 | mTextureDataLookup.erase(mTextureDataLookup.find(textureData.get())); |
| 167 | } |
| 168 | } |
| 169 | // Queue has been released here but we might have a texture to process |
| 170 | while (textureData) |
| 171 | { |
| 172 | textureData->load(); |
| 173 | |
| 174 | // See if there is another item in the queue |
| 175 | textureData = nullptr; |
| 176 | std::unique_lock<std::mutex> lock(mMutex); |
| 177 | if (!mTextureDataQ.empty()) |
| 178 | { |
| 179 | textureData = mTextureDataQ.front(); |
| 180 | mTextureDataQ.pop_front(); |
| 181 | mTextureDataLookup.erase(mTextureDataLookup.find(textureData.get())); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void TextureLoader::load(std::shared_ptr<TextureData> textureData) |
| 188 | { |