From 7a029604018c95df75d504500df92fe16c640cf5 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 20 Apr 2014 23:14:02 +0400 Subject: [PATCH] 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 --- libuavcan/include/uavcan/node/global_data_type_registry.hpp | 6 ------ libuavcan/src/node/uc_global_data_type_registry.cpp | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 8ee4638371..e3402fe0e1 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -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; diff --git a/libuavcan/src/node/uc_global_data_type_registry.cpp b/libuavcan/src/node/uc_global_data_type_registry.cpp index 206815c174..29aafa6b7f 100644 --- a/libuavcan/src/node/uc_global_data_type_registry.cpp +++ b/libuavcan/src/node/uc_global_data_type_registry.cpp @@ -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; }