|
@@ -38,13 +38,13 @@
|
|
// This is basically a portable version of pthread_once().
|
|
// This is basically a portable version of pthread_once().
|
|
//
|
|
//
|
|
// This header declares three things:
|
|
// 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
|
|
// * 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
|
|
// The macro may only be used at the global scope (you cannot create local
|
|
// or class member variables of this type).
|
|
// 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
|
|
// 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.
|
|
// none of the calls return before that first call to init_func has finished.
|
|
//
|
|
//
|
|
@@ -83,21 +83,21 @@ namespace protobuf {
|
|
|
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
|
|
|
-struct GoogleOnceInternal;
|
|
|
|
|
|
+struct ProtobufOnceInternal;
|
|
|
|
|
|
-struct LIBPROTOBUF_EXPORT GoogleOnceType {
|
|
|
|
- GoogleOnceType();
|
|
|
|
- ~GoogleOnceType();
|
|
|
|
|
|
+struct LIBPROTOBUF_EXPORT ProtobufOnceType {
|
|
|
|
+ ProtobufOnceType();
|
|
|
|
+ ~ProtobufOnceType();
|
|
void Init(void (*init_func)());
|
|
void Init(void (*init_func)());
|
|
|
|
|
|
volatile bool initialized_;
|
|
volatile bool initialized_;
|
|
- GoogleOnceInternal* internal_;
|
|
|
|
|
|
+ ProtobufOnceInternal* internal_;
|
|
};
|
|
};
|
|
|
|
|
|
#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
|
|
#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.
|
|
// Note: Double-checked locking is safe on x86.
|
|
if (!once->initialized_) {
|
|
if (!once->initialized_) {
|
|
once->Init(init_func);
|
|
once->Init(init_func);
|
|
@@ -106,12 +106,12 @@ inline void GoogleOnceInit(GoogleOnceType* once, void (*init_func)()) {
|
|
|
|
|
|
#else
|
|
#else
|
|
|
|
|
|
-typedef pthread_once_t GoogleOnceType;
|
|
|
|
|
|
+typedef pthread_once_t ProtobufOnceType;
|
|
|
|
|
|
#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
|
|
#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
|
|
pthread_once_t NAME = PTHREAD_ONCE_INIT
|
|
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);
|
|
pthread_once(once, init_func);
|
|
}
|
|
}
|
|
|
|
|