Good old GDTR singleton re-implemented via static local again, because previous implementation could cause undefined behavior as GDTR could be initialized after static type registrators that use it

This commit is contained in:
Pavel Kirienko
2014-04-20 23:14:02 +04:00
parent afc56cf87b
commit 7a02960401
2 changed files with 1 additions and 8 deletions
@@ -64,12 +64,6 @@ private:
mutable List srvs_;
bool frozen_;
/**
* We can't use function local static variable for singleton because of code size issues:
* http://stackoverflow.com/questions/22985570
*/
static GlobalDataTypeRegistry singleton;
GlobalDataTypeRegistry() : frozen_(false) { }
List* selectList(DataTypeKind kind) const;
@@ -10,8 +10,6 @@
namespace uavcan
{
GlobalDataTypeRegistry GlobalDataTypeRegistry::singleton;
GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind kind) const
{
if (kind == DataTypeKindMessage)
@@ -129,6 +127,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d
GlobalDataTypeRegistry& GlobalDataTypeRegistry::instance()
{
static GlobalDataTypeRegistry singleton;
return singleton;
}