summaryrefslogtreecommitdiff
path: root/sc/inc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2018-06-15 11:33:39 +0200
committerLuboš Luňák <l.lunak@collabora.com>2018-06-20 10:56:49 +0200
commit004b4ab80d467e0be373590ee55d87b2852e075d (patch)
treefe06ed3943ce2fbac3fbb5434df4f579ed014cdb /sc/inc
parent4a0bf6f4f30a3b020dcab1e1e7b2517948cc4b9c (diff)
use std::atomic rather than OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER
Sources such as http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/ or https://en.wikipedia.org/wiki/Double-checked_locking suggest that it wasn't possible to reliably do a portable double-checked initialization before C++11. It may be true that for all platforms we support those memory barriers are in fact not needed (which seems to be the assumption behind OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER being empty), and looking at the generated assembly here on x86-64 seems to confirm that, but in the worst case then this is a more chatty and standard way of writing a no-op. I don't want to use threadsafe statics or std::call_once() because ScGlobal::Clear() does cleanup, which would be non-trivial to do with these, and also some functions may not necessarily always force creation of the singleton when touching the pointer, so it can't be easily hidden behind a single function call. The need to explicitly use load() with delete (thus preventing DELETEZ) looks like a Clang bug to me. Change-Id: Id3b0ef4b273ed25a5c154f90cde090ea1f9674fb Reviewed-on: https://gerrit.libreoffice.org/55851 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/56141 Reviewed-by: Luboš Luňák <l.lunak@collabora.com> Tested-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc/inc')
-rw-r--r--sc/inc/global.hxx18
1 files changed, 11 insertions, 7 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index bb63731c1a12..b9ef661f43db 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -28,6 +28,10 @@
#include "scdllapi.h"
#include <rtl/ustring.hxx>
+#include <atomic>
+// HACK: <atomic> includes <stdbool.h>, which in some Clang versions does '#define bool bool',
+// which confuses clang plugins.
+#undef bool
#include <map>
#include <vector>
@@ -501,8 +505,8 @@ class ScGlobal
{
static SvxSearchItem* pSearchItem;
static ScAutoFormat* pAutoFormat;
- static LegacyFuncCollection* pLegacyFuncCollection;
- static ScUnoAddInCollection* pAddInCollection;
+ static std::atomic<LegacyFuncCollection*> pLegacyFuncCollection;
+ static std::atomic<ScUnoAddInCollection*> pAddInCollection;
static ScUserList* pUserList;
static std::map<const char*, OUString>* pRscString;
static OUString* pStrScDoc;
@@ -521,12 +525,12 @@ class ScGlobal
static css::uno::Reference< css::i18n::XOrdinalSuffix> xOrdinalSuffix;
static CalendarWrapper* pCalendar;
- static CollatorWrapper* pCaseCollator;
- static CollatorWrapper* pCollator;
- static ::utl::TransliterationWrapper* pTransliteration;
- static ::utl::TransliterationWrapper* pCaseTransliteration;
+ static std::atomic<CollatorWrapper*> pCaseCollator;
+ static std::atomic<CollatorWrapper*> pCollator;
+ static std::atomic<::utl::TransliterationWrapper*> pTransliteration;
+ static std::atomic<::utl::TransliterationWrapper*> pCaseTransliteration;
static IntlWrapper* pScIntlWrapper;
- static css::lang::Locale* pLocale;
+ static std::atomic<css::lang::Locale*> pLocale;
static ScFieldEditEngine* pFieldEditEngine;