From fb6ea21ca86dd5de549e207bfd64699da28cb777 Mon Sep 17 00:00:00 2001 From: vision Date: Fri, 23 May 2014 17:49:25 +0800 Subject: [PATCH] assure threading safety --- cocos/renderer/CCTextureCache.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index a528c101db..5758b6cecd 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -143,27 +143,27 @@ void TextureCache::addImageAsync(const std::string &path, const std::functionempty()) { + _imageInfoMutex.lock(); 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; }); if (found != _imageInfoQueue->end()) { (*found)->asyncStruct->callback = nullptr; } + _imageInfoMutex.unlock(); } - _imageInfoMutex.unlock(); } void TextureCache::unbindAllImageAsync() { - _imageInfoMutex.lock(); if (_imageInfoQueue && !_imageInfoQueue->empty()) { + _imageInfoMutex.lock(); std::for_each(_imageInfoQueue->begin(), _imageInfoQueue->end(), [](ImageInfo* ptr) { ptr->asyncStruct->callback = nullptr; }); + _imageInfoMutex.unlock(); } - _imageInfoMutex.unlock(); }