[Libreoffice-commits] .: 4 commits - cppuhelper/source cppu/source sal/inc sal/rtl
Caolán McNamara
caolan at kemper.freedesktop.org
Mon Apr 4 03:02:00 PDT 2011
cppu/source/uno/lbenv.cxx | 27 ++++++++++-------
cppuhelper/source/macro_expander.cxx | 35 ++++++++++++++--------
sal/inc/rtl/instance.hxx | 55 +++++++++++++++++++++++++++++++++--
sal/rtl/source/logfile.cxx | 20 +++++-------
sal/rtl/source/unload.cxx | 20 +++++-------
5 files changed, 108 insertions(+), 49 deletions(-)
New commits:
commit 03e70541de65af207b5f5a580d402967c533b857
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sun Apr 3 21:35:06 2011 +0100
use rtl::Static where double-locked pattern used
diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx
index 331662c..0cbc962 100644
--- a/cppu/source/uno/lbenv.cxx
+++ b/cppu/source/uno/lbenv.cxx
@@ -825,14 +825,14 @@ extern "C" void SAL_CALL uno_dumpEnvironmentByName(
}
}
-//------------------------------------------------------------------------------
-inline static const OUString & unoenv_getStaticOIdPart()
+namespace
{
- static OUString * s_pStaticOidPart = 0;
- if (! s_pStaticOidPart)
+ class makeOIdPart
{
- ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
- if (! s_pStaticOidPart)
+ private:
+ OUString m_sOidPart;
+ public:
+ makeOIdPart()
{
::rtl::OUStringBuffer aRet( 64 );
aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") );
@@ -856,11 +856,18 @@ inline static const OUString & unoenv_getStaticOIdPart()
for ( sal_Int32 i = 0; i < 16; ++i )
aRet.append( (sal_Int32)ar[i], 16 );
- static OUString s_aStaticOidPart( aRet.makeStringAndClear() );
- s_pStaticOidPart = &s_aStaticOidPart;
+ m_sOidPart = aRet.makeStringAndClear();
}
- }
- return *s_pStaticOidPart;
+ const OUString& getOIdPart() const { return m_sOidPart; }
+ };
+
+ class theStaticOIdPart : public rtl::Static<makeOIdPart, theStaticOIdPart> {};
+}
+
+//------------------------------------------------------------------------------
+inline static const OUString & unoenv_getStaticOIdPart()
+{
+ return theStaticOIdPart::get().getOIdPart();
}
extern "C"
commit 485126c3feaf1d49234acad8111b76f872f12e3c
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sun Apr 3 21:04:22 2011 +0100
use rtl::Static where double-locked pattern used
diff --git a/sal/rtl/source/logfile.cxx b/sal/rtl/source/logfile.cxx
index 51fdcdc..fa1955a 100644
--- a/sal/rtl/source/logfile.cxx
+++ b/sal/rtl/source/logfile.cxx
@@ -42,6 +42,7 @@
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/alloc.h>
+#include <rtl/instance.hxx>
#include "osl/thread.h"
#include <algorithm>
@@ -90,19 +91,14 @@ LoggerGuard::~LoggerGuard()
// g_buffer in init():
LoggerGuard loggerGuard;
-Mutex & getLogMutex()
+namespace
{
- static Mutex *pMutex = 0;
- if( !pMutex )
- {
- MutexGuard guard( Mutex::getGlobalMutex() );
- if( ! pMutex )
- {
- static Mutex mutex;
- pMutex = &mutex;
- }
- }
- return *pMutex;
+ class theLogMutex : public rtl::Static<osl::Mutex, theLogMutex>{};
+}
+
+static Mutex & getLogMutex()
+{
+ return theLogMutex::get();
}
OUString getFileUrl( const OUString &name )
diff --git a/sal/rtl/source/unload.cxx b/sal/rtl/source/unload.cxx
index 6bc024a..8785baf 100644
--- a/sal/rtl/source/unload.cxx
+++ b/sal/rtl/source/unload.cxx
@@ -31,6 +31,7 @@
#include <rtl/unload.h>
#include <rtl/alloc.h>
#include <rtl/ustring.hxx>
+#include <rtl/instance.hxx>
#include <osl/mutex.hxx>
#include <boost/unordered_map.hpp>
#include "rtl/allocator.hxx"
@@ -109,19 +110,14 @@ static sal_Bool hasEnoughTimePassed( const TimeValue* unusedSince, const TimeVal
return retval;
}
-static osl::Mutex* getUnloadingMutex()
+namespace
{
- static osl::Mutex * g_pMutex= NULL;
- if (!g_pMutex)
- {
- MutexGuard guard( osl::Mutex::getGlobalMutex() );
- if (!g_pMutex)
- {
- static osl::Mutex g_aMutex;
- g_pMutex= &g_aMutex;
- }
- }
- return g_pMutex;
+ class theUnloadingMutex : public rtl::Static<osl::Mutex, theUnloadingMutex>{};
+}
+
+static osl::Mutex& getUnloadingMutex()
+{
+ return theUnloadingMutex::get();
}
extern "C" void rtl_moduleCount_acquire(rtl_ModuleCount * that )
commit 41c5e7e66942ae2b21638c13a72c649b93625339
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sun Apr 3 20:58:32 2011 +0100
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
diff --git a/sal/inc/rtl/instance.hxx b/sal/inc/rtl/instance.hxx
index 15277da..61f7ba0 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
commit 39eb918405621cec31fdf54b4454351d19fdb453
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sat Apr 2 17:20:24 2011 +0100
use rtl::Static where double-locked pattern used
diff --git a/cppuhelper/source/macro_expander.cxx b/cppuhelper/source/macro_expander.cxx
index 38dc08b..db74d36 100644
--- a/cppuhelper/source/macro_expander.cxx
+++ b/cppuhelper/source/macro_expander.cxx
@@ -73,22 +73,30 @@ rtl::OUString expandMacros(rtl::OUString const & text) {
namespace
{
-inline OUString s_impl_name() { return OUSTR(IMPL_NAME); }
-static Sequence< OUString > const & s_get_service_names()
+
+class ImplNames
{
- static Sequence< OUString > const * s_pnames = 0;
- if (! s_pnames)
+private:
+ Sequence<OUString> m_aNames;
+public:
+ ImplNames() : m_aNames(2)
{
- MutexGuard guard( Mutex::getGlobalMutex() );
- if (! s_pnames)
- {
- static Sequence< OUString > s_names( 2 );
- s_names[ 0 ] = OUSTR(SERVICE_NAME_A);
- s_names[ 1 ] = OUSTR(SERVICE_NAME_B);
- s_pnames = &s_names;
- }
+ m_aNames[0] = OUSTR(SERVICE_NAME_A);
+ m_aNames[1] = OUSTR(SERVICE_NAME_B);
}
- return *s_pnames;
+ const Sequence<OUString>& getNames() const { return m_aNames; }
+};
+
+class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
+
+inline OUString s_impl_name()
+{
+ return OUSTR(IMPL_NAME);
+}
+
+inline Sequence< OUString > const & s_get_service_names()
+{
+ return theImplNames::get().getNames();
}
typedef ::cppu::WeakComponentImplHelper2<
@@ -98,6 +106,7 @@ struct mutex_holder
{
Mutex m_mutex;
};
+
class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl
{
protected:
More information about the Libreoffice-commits
mailing list