aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kenichiro IDA <ida.kenichiro@gmail.com>2015-12-19 10:14:42 +0900
committerGravatar Kenichiro IDA <ida.kenichiro@gmail.com>2015-12-19 10:14:42 +0900
commit674e92d314cd79b2f47eab22a7c3af8732feb93f (patch)
tree6b7c25e518ce4ad77fc519d841c2bfe6f82734b9 /src
parent894d18fba4e9920985e5d9d23391527b97893ca5 (diff)
Initialize singleton instance by GoogleOnceInit()
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/descriptor.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
index 07a6ca22..bd60806e 100644
--- a/src/google/protobuf/descriptor.cc
+++ b/src/google/protobuf/descriptor.cc
@@ -665,9 +665,31 @@ FileDescriptorTables::FileDescriptorTables()
FileDescriptorTables::~FileDescriptorTables() {}
+namespace {
+
+FileDescriptorTables* file_descriptor_tables_ = NULL;
+GOOGLE_PROTOBUF_DECLARE_ONCE(file_descriptor_tables_once_init_);
+
+void DeleteFileDescriptorTables() {
+ delete file_descriptor_tables_;
+ file_descriptor_tables_ = NULL;
+}
+
+void InitFileDescriptorTables() {
+ file_descriptor_tables_ = new FileDescriptorTables();
+ internal::OnShutdown(&DeleteFileDescriptorTables);
+}
+
+inline void InitFileDescriptorTablesOnce() {
+ ::google::protobuf::GoogleOnceInit(
+ &file_descriptor_tables_once_init_, &InitFileDescriptorTables);
+}
+
+} // anonymous namespace
+
inline const FileDescriptorTables& FileDescriptorTables::GetEmptyInstance() {
- static const FileDescriptorTables kEmpty;
- return kEmpty;
+ InitFileDescriptorTablesOnce();
+ return *file_descriptor_tables_;
}
void DescriptorPool::Tables::AddCheckpoint() {