fix some issues with static initialisation order

...also uncovered by compiling with GCC-5
This commit is contained in:
Fischlurch 2017-05-02 01:37:17 +02:00
parent d29e4e2d6f
commit 46192cadbf
4 changed files with 34 additions and 17 deletions

View file

@ -37,6 +37,19 @@ using util::cStr;
namespace lumiera {
// ==== implementation Lifecycle Registry =======
/** @remark since the LifecycleRegistry is used to implement
* the most basic initialisation, we need to ensure it is fully
* initialised and gets up on demand as early as possible. */
LifecycleRegistry&
LifecycleRegistry::instance()
{
static LifecycleRegistry theRegistry;
return theRegistry; // Meyer's singleton
}
// ==== implementation LifecycleHook class =======

View file

@ -43,7 +43,6 @@
#include <boost/noncopyable.hpp>
#include <functional>
#include <memory>
#include <string>
#include <set>
#include <map>
@ -53,7 +52,6 @@ namespace lumiera {
using boost::noncopyable;
using util::contains;
using std::unique_ptr;
using std::function;
using std::string;
@ -94,12 +92,7 @@ namespace lumiera {
/** get the (single) LifecycleRegistry instance.
* @warning don't use it after the end of main()! */
static LifecycleRegistry& instance() // Meyer's singleton
{
static unique_ptr<LifecycleRegistry> theRegistry_;
if (!theRegistry_) theRegistry_.reset (new LifecycleRegistry ());
return *theRegistry_;
}
static LifecycleRegistry& instance();
private:
@ -110,7 +103,6 @@ namespace lumiera {
}
~LifecycleRegistry () { }
friend class std::default_delete<LifecycleRegistry>;
};

View file

@ -60,7 +60,12 @@ namespace lib {
namespace { // global symbol table
SymbolTable symbolTable;
SymbolTable&
symbolTable()
{
static SymbolTable theSymbolTable;
return theSymbolTable; // Meyer's Singleton
}
}
@ -68,9 +73,11 @@ namespace lib {
* create Symbol by symbol table lookup.
* @note identical strings will be mapped to the same Symbol (embedded pointer)
* @warning potential lock contention, since each ctor call needs to do a lookup
* @remark since lumiera::LifecycleHook entries use a Symbol, the symbol table is
* implemented as Meyer's singleton and pulled up early, way before main()
*/
Symbol::Symbol (string&& definition)
: Literal{symbolTable.internedString (forward<string> (definition))}
: Literal{symbolTable().internedString (forward<string> (definition))}
{ }

View file

@ -69,7 +69,12 @@ namespace control {
using CmdDefEntry = std::tuple<Symbol, DefinitionClosure>;
std::deque<CmdDefEntry> pendingCmdDefinitions;
std::deque<CmdDefEntry>&
pendingCmdDefinitions()
{
static std::deque<CmdDefEntry> definitionQueue;
return definitionQueue;
}
}//(End) implementation details
@ -119,7 +124,7 @@ namespace control {
throw error::Invalid ("unbound function/closure provided for CommandSetup"
, error::LUMIERA_ERROR_BOTTOM_VALUE);
pendingCmdDefinitions.emplace_front (cmdID_, move(definitionBlock));
pendingCmdDefinitions().emplace_front (cmdID_, move(definitionBlock));
return *this;
}
@ -127,22 +132,22 @@ namespace control {
size_t
CommandSetup::pendingCnt()
{
return pendingCmdDefinitions.size();
return pendingCmdDefinitions().size();
}
void
CommandSetup::invokeDefinitionClosures()
{
while (not pendingCmdDefinitions.empty())
while (not pendingCmdDefinitions().empty())
{
CmdDefEntry& entry = pendingCmdDefinitions.back();
CmdDefEntry& entry = pendingCmdDefinitions().back();
Symbol& cmdID{get<Symbol>(entry)};
DefinitionClosure& buildDefinition{get<DefinitionClosure> (entry)};
TRACE (command, "defining Command(%s)...", cmdID.c());
CommandDef def(cmdID);
buildDefinition(def);
pendingCmdDefinitions.pop_back();
pendingCmdDefinitions().pop_back();
}
}