From c26c320dd956bf564aa417c63cfe128fc5d49eac Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 10 Apr 2014 15:05:55 +0400 Subject: [PATCH] Fixed GDTR singleton (http://stackoverflow.com/questions/22985570) --- libuavcan/include/uavcan/node/global_data_type_registry.hpp | 6 ++++++ libuavcan/src/node/uc_global_data_type_registry.cpp | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index ad6ef78ee6..25f2709568 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -60,6 +60,12 @@ 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 43e5c9c44c..9cb2ce35ef 100644 --- a/libuavcan/src/node/uc_global_data_type_registry.cpp +++ b/libuavcan/src/node/uc_global_data_type_registry.cpp @@ -10,6 +10,8 @@ namespace uavcan { +GlobalDataTypeRegistry GlobalDataTypeRegistry::singleton; + GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind kind) const { if (kind == DataTypeKindMessage) @@ -115,8 +117,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d GlobalDataTypeRegistry& GlobalDataTypeRegistry::instance() { - static GlobalDataTypeRegistry inst; - return inst; + return singleton; } void GlobalDataTypeRegistry::freeze()