@ -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 Google OnceType.
// * A type called Protobuf OnceType.
// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type
// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type
// Google OnceType. This is the only legal way to declare such a variable.
// Protobuf OnceType. 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(Google OnceType* once, void (*init_func)()).
// * A function GogoleOnceInit(Protobuf OnceType* once, void (*init_func)()).
// This function, when invoked multiple times given the same Google OnceType
// This function, when invoked multiple times given the same Protobuf OnceType
// 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 Google OnceInternal;
struct Protobuf OnceInternal;
struct LIBPROTOBUF_EXPORT Google OnceType {
struct LIBPROTOBUF_EXPORT Protobuf OnceType {
Google OnceType( ) ;
Protobuf OnceType( ) ;
~ Google OnceType( ) ;
~ Protobuf OnceType( ) ;
void Init ( void ( * init_func ) ( ) ) ;
void Init ( void ( * init_func ) ( ) ) ;
volatile bool initialized_ ;
volatile bool initialized_ ;
Google OnceInternal* internal_ ;
Protobuf OnceInternal* internal_ ;
} ;
} ;
# define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
# define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
: : google : : protobuf : : Google OnceType NAME
: : google : : protobuf : : Protobuf OnceType NAME
inline void GoogleOnceInit ( Google OnceType* once , void ( * init_func ) ( ) ) {
inline void GoogleOnceInit ( Protobuf OnceType* 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 Google OnceType;
typedef pthread_once_t Protobuf OnceType;
# 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 ( Google OnceType* once , void ( * init_func ) ( ) ) {
inline void GoogleOnceInit ( Protobuf OnceType* once , void ( * init_func ) ( ) ) {
pthread_once ( once , init_func ) ;
pthread_once ( once , init_func ) ;
}
}