assure threading safety

This commit is contained in:
vision 2014-05-23 17:49:25 +08:00
parent e3a365ad60
commit fb6ea21ca8
1 changed files with 4 additions and 4 deletions

View File

@ -143,27 +143,27 @@ void TextureCache::addImageAsync(const std::string &path, const std::function<vo
void TextureCache::unbindImageAsync(const std::string& filename) void TextureCache::unbindImageAsync(const std::string& filename)
{ {
_imageInfoMutex.lock();
if (_imageInfoQueue && !_imageInfoQueue->empty()) if (_imageInfoQueue && !_imageInfoQueue->empty())
{ {
_imageInfoMutex.lock();
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename); std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename);
auto found = std::find_if(_imageInfoQueue->begin(), _imageInfoQueue->end(), [&fullpath](ImageInfo* ptr)->bool{ return ptr->asyncStruct->filename == fullpath; }); auto found = std::find_if(_imageInfoQueue->begin(), _imageInfoQueue->end(), [&fullpath](ImageInfo* ptr)->bool{ return ptr->asyncStruct->filename == fullpath; });
if (found != _imageInfoQueue->end()) if (found != _imageInfoQueue->end())
{ {
(*found)->asyncStruct->callback = nullptr; (*found)->asyncStruct->callback = nullptr;
} }
_imageInfoMutex.unlock();
} }
_imageInfoMutex.unlock();
} }
void TextureCache::unbindAllImageAsync() void TextureCache::unbindAllImageAsync()
{ {
_imageInfoMutex.lock();
if (_imageInfoQueue && !_imageInfoQueue->empty()) if (_imageInfoQueue && !_imageInfoQueue->empty())
{ {
_imageInfoMutex.lock();
std::for_each(_imageInfoQueue->begin(), _imageInfoQueue->end(), [](ImageInfo* ptr) { ptr->asyncStruct->callback = nullptr; }); std::for_each(_imageInfoQueue->begin(), _imageInfoQueue->end(), [](ImageInfo* ptr) { ptr->asyncStruct->callback = nullptr; });
_imageInfoMutex.unlock();
} }
_imageInfoMutex.unlock();
} }