Make getLayerInfo thread safe

coverity_scan
scrawl 9 years ago
parent 8aba74e6ee
commit 98848c752a

@ -3,6 +3,8 @@
#include <set> #include <set>
#include <iostream> #include <iostream>
#include <OpenThreads/ScopedLock>
#include <osg/Image> #include <osg/Image>
#include <osg/Plane> #include <osg/Plane>
@ -498,6 +500,8 @@ namespace ESMTerrain
Terrain::LayerInfo Storage::getLayerInfo(const std::string& texture) Terrain::LayerInfo Storage::getLayerInfo(const std::string& texture)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mLayerInfoMutex);
// Already have this cached? // Already have this cached?
std::map<std::string, Terrain::LayerInfo>::iterator found = mLayerInfoMap.find(texture); std::map<std::string, Terrain::LayerInfo>::iterator found = mLayerInfoMap.find(texture);
if (found != mLayerInfoMap.end()) if (found != mLayerInfoMap.end())

@ -1,6 +1,8 @@
#ifndef COMPONENTS_ESM_TERRAIN_STORAGE_H #ifndef COMPONENTS_ESM_TERRAIN_STORAGE_H
#define COMPONENTS_ESM_TERRAIN_STORAGE_H #define COMPONENTS_ESM_TERRAIN_STORAGE_H
#include <OpenThreads/Mutex>
#include <components/terrain/storage.hpp> #include <components/terrain/storage.hpp>
#include <components/esm/loadland.hpp> #include <components/esm/loadland.hpp>
@ -105,6 +107,7 @@ namespace ESMTerrain
std::string getTextureName (UniqueTextureId id); std::string getTextureName (UniqueTextureId id);
std::map<std::string, Terrain::LayerInfo> mLayerInfoMap; std::map<std::string, Terrain::LayerInfo> mLayerInfoMap;
OpenThreads::Mutex mLayerInfoMutex;
Terrain::LayerInfo getLayerInfo(const std::string& texture); Terrain::LayerInfo getLayerInfo(const std::string& texture);
}; };

Loading…
Cancel
Save