Fix race conditions in Config Layers

API has been made stricter, layers are now managed with shared pointers,
so using them temporarily increased their reference counters.
Additionally, any s_layers map has been guarded by a read/write lock,
as concurrent write/reads to it were possible.
This commit is contained in:
Silent
2019-07-30 16:40:52 +02:00
parent dea2b9c509
commit cb4eecde52
2 changed files with 70 additions and 32 deletions

View File

@ -16,16 +16,12 @@
namespace Config
{
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
using ConfigChangedCallback = std::function<void()>;
// Layer management
Layers* GetLayers();
void AddLayer(std::unique_ptr<Layer> layer);
void AddLayer(std::unique_ptr<ConfigLayerLoader> loader);
Layer* GetLayer(LayerType layer);
std::shared_ptr<Layer> GetLayer(LayerType layer);
void RemoveLayer(LayerType layer);
bool LayerExists(LayerType layer);
void AddConfigChangedCallback(ConfigChangedCallback func);
void InvokeConfigChangedCallbacks();