diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-05-06 19:27:03 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-05-06 19:27:03 +0000 |
commit | 63e646b7ad6f18228c1807f8d18111ae96e86aa7 (patch) | |
tree | fc524e6f55b32b7d786bd41623402394a2f1af26 /src/google/protobuf/extension_set.cc | |
parent | 9824eda6b558cd88c63064017593521ecad2029f (diff) | |
download | protobuf-63e646b7ad6f18228c1807f8d18111ae96e86aa7.tar.gz protobuf-63e646b7ad6f18228c1807f8d18111ae96e86aa7.tar.bz2 protobuf-63e646b7ad6f18228c1807f8d18111ae96e86aa7.zip |
Provide ShutdownProtobufLibrary() which frees all startup-allocated objects.
Diffstat (limited to 'src/google/protobuf/extension_set.cc')
-rw-r--r-- | src/google/protobuf/extension_set.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 0e618902..f45eafa5 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -78,11 +78,22 @@ struct ExtensionInfo { typedef hash_map<pair<const Message*, int>, ExtensionInfo> ExtensionRegistry; ExtensionRegistry* registry_ = NULL; +GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_); + +void DeleteRegistry() { + delete registry_; + registry_ = NULL; +} + +void InitRegistry() { + registry_ = new ExtensionRegistry; + internal::OnShutdown(&DeleteRegistry); +} // This function is only called at startup, so there is no need for thread- // safety. void Register(const Message* containing_type, int number, ExtensionInfo info) { - if (registry_ == NULL) registry_ = new ExtensionRegistry; + GoogleOnceInit(®istry_init_, &InitRegistry); if (!InsertIfNotPresent(registry_, make_pair(containing_type, number), info)) { |