rtl::Static -> thread-safe static local

Change-Id: Iac0501e6aa35cc3d8e62f6b6e68b76cf70233aae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120459
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2021-08-15 19:17:01 +02:00
parent 6c12c659fb
commit 00f257a7ef
7 changed files with 15 additions and 57 deletions
@@ -204,19 +204,14 @@ namespace comphelper
return false;
}
namespace
{
class theEmptyDefault : public rtl::Static<Any, theEmptyDefault> {};
}
const Any& NamedValueCollection::impl_get( const OUString& _rValueName ) const
{
static Any theEmptyDefault;
auto pos = maValues.find( _rValueName );
if ( pos != maValues.end() )
return pos->second;
return theEmptyDefault::get();
return theEmptyDefault;
}
+2 -14
View File
@@ -25,7 +25,6 @@
#include <unordered_map>
#include <osl/diagnose.h>
#include <rtl/instance.hxx>
#include <sal/log.hxx>
#include <uno/threadpool.h>
@@ -43,21 +42,10 @@ namespace cppu_threadpool
rtl::Reference<ORequestThread> const & theThread): thread(theThread)
{}
namespace {
struct theDisposedCallerAdmin :
public rtl::StaticWithInit< DisposedCallerAdminHolder, theDisposedCallerAdmin >
{
DisposedCallerAdminHolder operator () () {
return std::make_shared<DisposedCallerAdmin>();
}
};
}
DisposedCallerAdminHolder const & DisposedCallerAdmin::getInstance()
{
return theDisposedCallerAdmin::get();
static DisposedCallerAdminHolder theDisposedCallerAdmin = std::make_shared<DisposedCallerAdmin>();
return theDisposedCallerAdmin;
}
DisposedCallerAdmin::~DisposedCallerAdmin()
+2 -3
View File
@@ -819,11 +819,10 @@ namespace
const OUString& getOIdPart() const { return m_sOidPart; }
};
class theStaticOIdPart : public rtl::Static<makeOIdPart, theStaticOIdPart> {};
const OUString & unoenv_getStaticOIdPart()
{
return theStaticOIdPart::get().getOIdPart();
static makeOIdPart theStaticOIdPart;
return theStaticOIdPart.getOIdPart();
}
}
+5 -16
View File
@@ -69,21 +69,6 @@ OUString expandMacros(OUString const & text) {
namespace
{
class ImplNames
{
private:
Sequence<OUString> m_aNames;
public:
ImplNames() : m_aNames(2)
{
m_aNames[0] = SERVICE_NAME_A;
m_aNames[1] = SERVICE_NAME_B;
}
const Sequence<OUString>& getNames() const { return m_aNames; }
};
class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
OUString s_impl_name()
{
return IMPL_NAME;
@@ -91,7 +76,11 @@ OUString s_impl_name()
Sequence< OUString > const & s_get_service_names()
{
return theImplNames::get().getNames();
static const Sequence< OUString > IMPL_NAMES {
SERVICE_NAME_A,
SERVICE_NAME_B
};
return IMPL_NAMES;
}
typedef cppu::WeakComponentImplHelper<
@@ -26,13 +26,6 @@
namespace dbaccess
{
// ResourceManager
namespace
{
// access safety
struct theResourceManagerMutex : public rtl::Static< osl::Mutex, theResourceManagerMutex > {};
}
OUString ResourceManager::loadString(TranslateId pResId)
{
return Translate::get(pResId, Translate::Create("dba"));
+2 -3
View File
@@ -383,13 +383,12 @@ void FatalError(const OUString& sMessage)
_exit(EXITHELPER_FATAL_ERROR);
}
struct theCommandLineArgs : public rtl::Static< CommandLineArgs, theCommandLineArgs > {};
}
CommandLineArgs& Desktop::GetCommandLineArgs()
{
return theCommandLineArgs::get();
static CommandLineArgs theCommandLineArgs;
return theCommandLineArgs;
}
OUString ReplaceStringHookProc( const OUString& rStr )
+2 -7
View File
@@ -635,15 +635,10 @@ void DbusIpcThread::close() {
#endif
namespace
{
class theRequestHandlerMutex
: public rtl::Static<osl::Mutex, theRequestHandlerMutex> {};
}
::osl::Mutex& RequestHandler::GetMutex()
{
return theRequestHandlerMutex::get();
static ::osl::Mutex theRequestHandlerMutex;
return theRequestHandlerMutex;
}
void RequestHandler::SetDowning()