diff options
author | jieluo@google.com <jieluo@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2014-07-18 00:47:59 +0000 |
---|---|---|
committer | jieluo@google.com <jieluo@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2014-07-18 00:47:59 +0000 |
commit | 4de8f55113007fdc8e34107950e605fc0209d465 (patch) | |
tree | 92b7da8757a7740d9e1f2d3ead233542947d8c8c /src/google/protobuf/stubs/once.h | |
parent | c5553a3d18f80132b9079c5504bc0aa1f7f950a0 (diff) |
down integrate to svn
Diffstat (limited to 'src/google/protobuf/stubs/once.h')
-rw-r--r-- | src/google/protobuf/stubs/once.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/once.h b/src/google/protobuf/stubs/once.h index 7fbc117f..86a4c01f 100644 --- a/src/google/protobuf/stubs/once.h +++ b/src/google/protobuf/stubs/once.h @@ -139,6 +139,24 @@ inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)(Arg*), #endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY +class GoogleOnceDynamic { + public: + GoogleOnceDynamic() : state_(GOOGLE_PROTOBUF_ONCE_INIT) { } + + // If this->Init() has not been called before by any thread, + // execute (*func_with_arg)(arg) then return. + // Otherwise, wait until that prior invocation has finished + // executing its function, then return. + template<typename T> + void Init(void (*func_with_arg)(T*), T* arg) { + GoogleOnceInit<T>(&this->state_, + func_with_arg, + arg); + } + private: + ProtobufOnceType state_; +}; + #define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ ::google::protobuf::ProtobufOnceType NAME = GOOGLE_PROTOBUF_ONCE_INIT |