aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google
diff options
context:
space:
mode:
authorGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-18 08:21:00 +0000
committerGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-18 08:21:00 +0000
commitbdbb863099c7ef3e1ecdeefa732798e095b85fb8 (patch)
tree221b358332016ecb81d2da4f7529be0cdaef1e1f /src/google
parent91218afc67773ebf85e37d91c80cb3a7d423b0ba (diff)
Ensure that 'once' objects are declared using the macro. This is either the third or fourth time I've screwed this up when down-integrating, because our internal code does not require the macro (it's not portable) and on Linux a pthread_once_t that is zero-initialized just happens to work. So, I only discover the problem when I test on Mac, then kick myself for making the same mistake yet again. No more! This time, I have renamed GoogleOnceType to ProtobufOnceType, thus making the type name differ from our internal code. As a result, if you don't update the decls to use the macros, they won't compile. Hah! Take that, future self!
Diffstat (limited to 'src/google')
-rw-r--r--src/google/protobuf/descriptor.cc2
-rw-r--r--src/google/protobuf/extension_set.cc2
-rw-r--r--src/google/protobuf/message.cc2
-rw-r--r--src/google/protobuf/stubs/once.cc16
-rw-r--r--src/google/protobuf/stubs/once.h26
-rw-r--r--src/google/protobuf/stubs/once_unittest.cc10
6 files changed, 29 insertions, 29 deletions
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
index e0a95077..fe2caad3 100644
--- a/src/google/protobuf/descriptor.cc
+++ b/src/google/protobuf/descriptor.cc
@@ -799,7 +799,7 @@ namespace {
EncodedDescriptorDatabase* generated_database_ = NULL;
DescriptorPool* generated_pool_ = NULL;
-GoogleOnceType generated_pool_init_;
+GOOGLE_PROTOBUF_DECLARE_ONCE(generated_pool_init_);
void DeleteGeneratedPool() {
delete generated_database_;
diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc
index 615f33c7..b08b4b14 100644
--- a/src/google/protobuf/extension_set.cc
+++ b/src/google/protobuf/extension_set.cc
@@ -62,7 +62,7 @@ inline WireFormatLite::CppType cpp_type(FieldType type) {
typedef hash_map<pair<const MessageLite*, int>,
ExtensionInfo> ExtensionRegistry;
ExtensionRegistry* registry_ = NULL;
-GoogleOnceType registry_init_;
+GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_);
void DeleteRegistry() {
delete registry_;
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index d43507cd..09166f3a 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -212,7 +212,7 @@ class GeneratedMessageFactory : public MessageFactory {
};
GeneratedMessageFactory* generated_message_factory_ = NULL;
-GoogleOnceType generated_message_factory_once_init_;
+GOOGLE_PROTOBUF_DECLARE_ONCE(generated_message_factory_once_init_);
void ShutdownGeneratedMessageFactory() {
delete generated_message_factory_;
diff --git a/src/google/protobuf/stubs/once.cc b/src/google/protobuf/stubs/once.cc
index 3c53bcd7..5b7af9ce 100644
--- a/src/google/protobuf/stubs/once.cc
+++ b/src/google/protobuf/stubs/once.cc
@@ -46,33 +46,33 @@ namespace protobuf {
#ifdef _WIN32
-struct GoogleOnceInternal {
- GoogleOnceInternal() {
+struct ProtobufOnceInternal {
+ ProtobufOnceInternal() {
InitializeCriticalSection(&critical_section);
}
- ~GoogleOnceInternal() {
+ ~ProtobufOnceInternal() {
DeleteCriticalSection(&critical_section);
}
CRITICAL_SECTION critical_section;
};
-GoogleOnceType::~GoogleOnceType()
+ProtobufOnceType::~ProtobufOnceType()
{
delete internal_;
internal_ = NULL;
}
-GoogleOnceType::GoogleOnceType() {
+ProtobufOnceType::ProtobufOnceType() {
// internal_ may be non-NULL if Init() was already called.
- if (internal_ == NULL) internal_ = new GoogleOnceInternal;
+ if (internal_ == NULL) internal_ = new ProtobufOnceInternal;
}
-void GoogleOnceType::Init(void (*init_func)()) {
+void ProtobufOnceType::Init(void (*init_func)()) {
// internal_ may be NULL if we're still in dynamic initialization and the
// constructor has not been called yet. As mentioned in once.h, we assume
// that the program is still single-threaded at this time, and therefore it
// should be safe to initialize internal_ like so.
- if (internal_ == NULL) internal_ = new GoogleOnceInternal;
+ if (internal_ == NULL) internal_ = new ProtobufOnceInternal;
EnterCriticalSection(&internal_->critical_section);
if (!initialized_) {
diff --git a/src/google/protobuf/stubs/once.h b/src/google/protobuf/stubs/once.h
index 22b0d4e6..0dee4076 100644
--- a/src/google/protobuf/stubs/once.h
+++ b/src/google/protobuf/stubs/once.h
@@ -38,13 +38,13 @@
// This is basically a portable version of pthread_once().
//
// This header declares three things:
-// * A type called GoogleOnceType.
+// * A type called ProtobufOnceType.
// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type
-// GoogleOnceType. This is the only legal way to declare such a variable.
+// ProtobufOnceType. This is the only legal way to declare such a variable.
// The macro may only be used at the global scope (you cannot create local
// or class member variables of this type).
-// * A function GogoleOnceInit(GoogleOnceType* once, void (*init_func)()).
-// This function, when invoked multiple times given the same GoogleOnceType
+// * A function GogoleOnceInit(ProtobufOnceType* once, void (*init_func)()).
+// This function, when invoked multiple times given the same ProtobufOnceType
// object, will invoke init_func on the first call only, and will make sure
// none of the calls return before that first call to init_func has finished.
//
@@ -83,21 +83,21 @@ namespace protobuf {
#ifdef _WIN32
-struct GoogleOnceInternal;
+struct ProtobufOnceInternal;
-struct LIBPROTOBUF_EXPORT GoogleOnceType {
- GoogleOnceType();
- ~GoogleOnceType();
+struct LIBPROTOBUF_EXPORT ProtobufOnceType {
+ ProtobufOnceType();
+ ~ProtobufOnceType();
void Init(void (*init_func)());
volatile bool initialized_;
- GoogleOnceInternal* internal_;
+ ProtobufOnceInternal* internal_;
};
#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
- ::google::protobuf::GoogleOnceType NAME
+ ::google::protobuf::ProtobufOnceType NAME
-inline void GoogleOnceInit(GoogleOnceType* once, void (*init_func)()) {
+inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) {
// Note: Double-checked locking is safe on x86.
if (!once->initialized_) {
once->Init(init_func);
@@ -106,12 +106,12 @@ inline void GoogleOnceInit(GoogleOnceType* once, void (*init_func)()) {
#else
-typedef pthread_once_t GoogleOnceType;
+typedef pthread_once_t ProtobufOnceType;
#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
pthread_once_t NAME = PTHREAD_ONCE_INIT
-inline void GoogleOnceInit(GoogleOnceType* once, void (*init_func)()) {
+inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) {
pthread_once(once, init_func);
}
diff --git a/src/google/protobuf/stubs/once_unittest.cc b/src/google/protobuf/stubs/once_unittest.cc
index 86e06478..b8f86a0f 100644
--- a/src/google/protobuf/stubs/once_unittest.cc
+++ b/src/google/protobuf/stubs/once_unittest.cc
@@ -52,10 +52,10 @@ class OnceInitTest : public testing::Test {
current_test_ = this;
}
- // Since GoogleOnceType is only allowed to be allocated in static storage,
- // each test must use a different pair of GoogleOnceType objects which it
+ // Since ProtobufOnceType is only allowed to be allocated in static storage,
+ // each test must use a different pair of ProtobufOnceType objects which it
// must declare itself.
- void SetOnces(GoogleOnceType* once, GoogleOnceType* recursive_once) {
+ void SetOnces(ProtobufOnceType* once, ProtobufOnceType* recursive_once) {
once_ = once;
recursive_once_ = recursive_once;
}
@@ -155,8 +155,8 @@ class OnceInitTest : public testing::Test {
Mutex mutex_;
Mutex init_blocker_;
State state_;
- GoogleOnceType* once_;
- GoogleOnceType* recursive_once_;
+ ProtobufOnceType* once_;
+ ProtobufOnceType* recursive_once_;
void Init() {
MutexLock lock(&mutex_);