Commit 43a1bd6751fae35828714699cc20f11d27165023

Authored by phoyd
Committed by David Gräff
1 parent 7ed6776a

Fixes a segfault on startup. The previous code assumed that ModelRegistry::insta…

…nce would be initialized before being used by other static initializers.
However, static initialization order is undefined.
Plus, at least unter C++11 and according to 6.7[stmt.decl] p.4, this initialization of get():inst is thread-safe.
openhantek/src/hantekdso/modelregistry.cpp
... ... @@ -2,9 +2,10 @@
2 2  
3 3 #include "modelregistry.h"
4 4  
5   -ModelRegistry *ModelRegistry::instance = new ModelRegistry();
6   -
7   -ModelRegistry *ModelRegistry::get() { return instance; }
  5 +ModelRegistry *ModelRegistry::get() {
  6 + static ModelRegistry inst;
  7 + return &inst;
  8 +}
8 9  
9 10 void ModelRegistry::add(DSOModel *model) { supportedModels.push_back(model); }
10 11  
... ...
openhantek/src/hantekdso/modelregistry.h
... ... @@ -11,6 +11,5 @@ public:
11 11 void add(DSOModel* model);
12 12 const std::list<DSOModel*> models() const;
13 13 private:
14   - static ModelRegistry* instance;
15 14 std::list<DSOModel*> supportedModels;
16 15 };
... ...