diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-04-03 20:58:32 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-04-03 21:43:48 +0100 |
commit | e8920fbe19a9164f00b476ad42243aaa081e8449 (patch) | |
tree | fd025289de055455209e2602bd7e3b37b779e811 /sal | |
parent | 562a46dbd8a4fa05cff806d7eab164065e30bbe6 (diff) |
use simpler local statics for gcc
a) gcc's -fthreadsafe-static is apparently sufficient so
removes an extra layer of locking
b) and this helps out helgrind to better analyze thread-safety
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/rtl/instance.hxx | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/sal/inc/rtl/instance.hxx b/sal/inc/rtl/instance.hxx index d4ee7cc7f68d..3a85e56711ee 100644 --- a/sal/inc/rtl/instance.hxx +++ b/sal/inc/rtl/instance.hxx @@ -361,6 +361,22 @@ namespace rtl { using the outer class (the one that derives from this base class) */ +#if (__GNUC__ >= 4) +template<typename T, typename Unique> +class Static { +public: + /** Gets the static. Mutual exclusion is implied by a functional + -fthreadsafe-statics + + @return + static variable + */ + static T & get() { + static T instance; + return instance; + } +}; +#else template<typename T, typename Unique> class Static { public: @@ -384,6 +400,7 @@ private: } }; }; +#endif /** Helper class for a late-initialized static aggregate, e.g. an array, implementing the double-checked locking pattern correctly. @@ -393,6 +410,23 @@ private: @tplparam InitAggregate initializer functor class */ +#if (__GNUC__ >= 4) +template<typename T, typename InitAggregate> +class StaticAggregate { +public: + /** Gets the static aggregate, late-initializing. + Mutual exclusion is implied by a functional + -fthreadsafe-statics + + @return + aggregate + */ + static T * get() { + static T *instance = InitAggregate()(); + return instance; + } +}; +#else template<typename T, typename InitAggregate> class StaticAggregate { public: @@ -409,7 +443,7 @@ public: InitAggregate(), ::osl::GetGlobalMutex() ); } }; - +#endif /** Helper base class for a late-initialized static variable, implementing the double-checked locking pattern correctly. @@ -441,6 +475,23 @@ public: Initializer functor's return type. Default is T (common practice). */ +#if (__GNUC__ >= 4) +template<typename T, typename InitData, + typename Unique = InitData, typename Data = T> +class StaticWithInit { +public: + /** Gets the static. Mutual exclusion is implied by a functional + -fthreadsafe-statics + + @return + static variable + */ + static T & get() { + static T instance = InitData()(); + return instance; + } +}; +#else template<typename T, typename InitData, typename Unique = InitData, typename Data = T> class StaticWithInit { @@ -467,7 +518,7 @@ private: } }; }; - +#endif } // namespace rtl #endif // INCLUDED_RTL_INSTANCE_HXX |