don't do concurrent access to a static member variable

in situations where the renderer is used from multiple threads, this causes memory corruption.

fixes mapbox/node-mapbox-gl-native#7
This commit is contained in:
Konstantin Käfer
2014-10-08 15:27:33 +02:00
parent 36b7bb0c09
commit 91f40daa69
4 changed files with 39 additions and 12 deletions

View File

@@ -14,17 +14,22 @@ enum class ClassID : uint32_t {
};
class ClassDictionary {
private:
ClassDictionary();
public:
static ClassDictionary &Get();
// Returns an ID for a class name. If the class name does not yet have an ID, one is
// auto-generated and stored for future reference.
static ClassID Lookup(const std::string &class_name);
ClassID lookup(const std::string &class_name);
// Returns either Fallback, Default or Named, depending on the type of the class id.
static ClassID Normalize(ClassID id);
ClassID normalize(ClassID id);
private:
static std::unordered_map<std::string, ClassID> store;
static uint32_t offset;
std::unordered_map<std::string, ClassID> store = { { "", ClassID::Default } };
uint32_t offset = 0;
};
}