Finer locking granularity in BitmapTextureCache
@@ -11,27 +11,25 @@ namespace carto {
std::size_t BitmapTextureCache::getCapacity() const {
std::lock_guard<std::mutex> lock(_mutex);
-
return _cache.capacity();
}
void BitmapTextureCache::setCapacity(std::size_t capacityInBytes) {
std::lock_guard<std::mutex> lock(_mutex);
-
_cache.resize(capacityInBytes);
}
void BitmapTextureCache::clear() {
std::lock_guard<std::mutex> lock(_mutex);
-
_cache.clear();
}
std::shared_ptr<Texture> BitmapTextureCache::get(const std::shared_ptr<Bitmap>& bitmap) const {
- std::lock_guard<std::mutex> lock(_mutex);
-
std::shared_ptr<Texture> texture;
+ {
+ std::lock_guard<std::mutex> lock(_mutex);
_cache.read(bitmap, texture);
+ }
return (texture && texture->isValid() ? texture : std::shared_ptr<Texture>());
}
@@ -43,11 +41,11 @@ namespace carto {
}
std::shared_ptr<Texture> BitmapTextureCache::create(const std::shared_ptr<Bitmap>& bitmap, bool genMipmaps, bool repeat) {
- std::lock_guard<std::mutex> lock(_mutex);
-
std::shared_ptr<Texture> texture;
if (std::shared_ptr<GLResourceManager> manager = _manager.lock()) {
texture = manager->create<Texture>(bitmap, genMipmaps, repeat);
+
+ std::lock_guard<std::mutex> lock(_mutex);
if (texture->getSize() > _cache.capacity()) {
_cache.resize(texture->getSize());
}
@@ -59,18 +57,16 @@ namespace carto {
}
void BitmapTextureCache::create() const {
- std::lock_guard<std::mutex> lock(_mutex);
-
Log::Debug("BitmapTextureCache::create: Clearing cache");
+ std::lock_guard<std::mutex> lock(_mutex);
_cache.clear();
}
void BitmapTextureCache::destroy() const {
- std::lock_guard<std::mutex> lock(_mutex);
-
Log::Debug("BitmapTextureCache::destroy: Clearing cache");
+ std::lock_guard<std::mutex> lock(_mutex);
_cache.clear();
}
