mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-11 11:03:34 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user