aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs
diff options
context:
space:
mode:
authorGravatar Jisi Liu <liujisi@google.com>2017-07-24 14:59:27 -0700
committerGravatar GitHub <noreply@github.com>2017-07-24 14:59:27 -0700
commit72cc5a6eb3975bbe3bc8454f053835d9e46dbcb5 (patch)
treec04e02e5fe58c1db617a6b8eb0bf6e2b69f55d96 /src/google/protobuf/stubs
parent942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff)
parentdd091aad48423f3a047977e6662f0201194b9bfc (diff)
Merge pull request #3393 from pherl/3.4.x
Create 3.4.x branch
Diffstat (limited to 'src/google/protobuf/stubs')
-rw-r--r--src/google/protobuf/stubs/common.cc42
-rw-r--r--src/google/protobuf/stubs/common.h3
-rw-r--r--src/google/protobuf/stubs/mutex.h8
-rw-r--r--src/google/protobuf/stubs/port.h4
4 files changed, 34 insertions, 23 deletions
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc
index 14655916..78aa4d64 100644
--- a/src/google/protobuf/stubs/common.cc
+++ b/src/google/protobuf/stubs/common.cc
@@ -416,13 +416,26 @@ uint32 ghtonl(uint32 x) {
namespace internal {
typedef void OnShutdownFunc();
-vector<void (*)()>* shutdown_functions = NULL;
-Mutex* shutdown_functions_mutex = NULL;
+struct ShutdownData {
+ ~ShutdownData() {
+ for (int i = 0; i < functions.size(); i++) {
+ functions[i]();
+ }
+ for (int i = 0; i < strings.size(); i++) {
+ strings[i]->~string();
+ }
+ }
+
+ vector<void (*)()> functions;
+ vector<const std::string*> strings;
+ Mutex mutex;
+};
+
+ShutdownData* shutdown_data = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(shutdown_functions_init);
void InitShutdownFunctions() {
- shutdown_functions = new vector<void (*)()>;
- shutdown_functions_mutex = new Mutex;
+ shutdown_data = new ShutdownData;
}
inline void InitShutdownFunctionsOnce() {
@@ -431,8 +444,14 @@ inline void InitShutdownFunctionsOnce() {
void OnShutdown(void (*func)()) {
InitShutdownFunctionsOnce();
- MutexLock lock(shutdown_functions_mutex);
- shutdown_functions->push_back(func);
+ MutexLock lock(&shutdown_data->mutex);
+ shutdown_data->functions.push_back(func);
+}
+
+void OnShutdownDestroyString(const std::string* ptr) {
+ InitShutdownFunctionsOnce();
+ MutexLock lock(&shutdown_data->mutex);
+ shutdown_data->strings.push_back(ptr);
}
} // namespace internal
@@ -445,15 +464,10 @@ void ShutdownProtobufLibrary() {
// called.
// Make it safe to call this multiple times.
- if (internal::shutdown_functions == NULL) return;
+ if (internal::shutdown_data == NULL) return;
- for (int i = 0; i < internal::shutdown_functions->size(); i++) {
- internal::shutdown_functions->at(i)();
- }
- delete internal::shutdown_functions;
- internal::shutdown_functions = NULL;
- delete internal::shutdown_functions_mutex;
- internal::shutdown_functions_mutex = NULL;
+ delete internal::shutdown_data;
+ internal::shutdown_data = NULL;
}
#if PROTOBUF_USE_EXCEPTIONS
diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h
index 19d59843..f32fd228 100644
--- a/src/google/protobuf/stubs/common.h
+++ b/src/google/protobuf/stubs/common.h
@@ -200,7 +200,8 @@ namespace internal {
// Register a function to be called when ShutdownProtocolBuffers() is called.
LIBPROTOBUF_EXPORT void OnShutdown(void (*func)());
-
+// Destroy the string (call string destructor)
+LIBPROTOBUF_EXPORT void OnShutdownDestroyString(const std::string* ptr);
} // namespace internal
#if PROTOBUF_USE_EXCEPTIONS
diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h
index 7ef1cb69..174290f6 100644
--- a/src/google/protobuf/stubs/mutex.h
+++ b/src/google/protobuf/stubs/mutex.h
@@ -70,14 +70,6 @@ class LIBPROTOBUF_EXPORT Mutex {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex);
};
-// Undefine the macros to workaround the conflicts with Google internal
-// MutexLock implementation.
-// TODO(liujisi): Remove the undef once internal macros are removed.
-#undef MutexLock
-#undef ReaderMutexLock
-#undef WriterMutexLock
-#undef MutexLockMaybe
-
// MutexLock(mu) acquires mu when constructed and releases it when destroyed.
class LIBPROTOBUF_EXPORT MutexLock {
public:
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h
index 7879aed4..dbc29861 100644
--- a/src/google/protobuf/stubs/port.h
+++ b/src/google/protobuf/stubs/port.h
@@ -467,6 +467,10 @@ class BigEndian {
}
};
+#ifndef GOOGLE_ATTRIBUTE_SECTION_VARIABLE
+#define GOOGLE_ATTRIBUTE_SECTION_VARIABLE(name)
+#endif
+
} // namespace protobuf
} // namespace google