commit 2fd2e657458f571df373a1b3fba1e6a33c8f6d59
Author: Guillaume Munch <[email protected]>
Date: Sat Jul 30 20:28:44 2016 +0100
C++11 supports thread-safe initialization of statics
A static local variable is guaranteed to be initialized only once, and in
time.
Lambda expressions can be used to perform complex initialization of those
static
variables on the spot.
(starting from: gcc >= 4.8, msvc >= 2015)
---
src/ConverterCache.cpp | 1 -
src/CutAndPaste.cpp | 18 ++++++++++--------
src/frontends/qt4/GuiWorkArea.cpp | 2 +-
src/graphics/GraphicsCache.cpp | 1 -
src/graphics/GraphicsLoader.cpp | 1 -
src/support/os.cpp | 2 +-
6 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp
index 29d07e4..b87bfe5 100644
--- a/src/ConverterCache.cpp
+++ b/src/ConverterCache.cpp
@@ -223,7 +223,6 @@ ConverterCache::~ConverterCache()
}
-// FIXME THREAD
ConverterCache & ConverterCache::get()
{
// Now return the cache
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 988dba4..4ec9811 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -486,16 +486,18 @@ Buffer * copyToTempBuffer(ParagraphList const &
paragraphs, DocumentClassConstPt
// to be so, but the alternative is to construct a new one of these
(with a
// new temporary directory, etc) every time, and then to destroy it. So
maybe
// it's worth just keeping this one around.
- // FIXME THREAD
static TempFile tempfile("clipboard.internal");
tempfile.setAutoRemove(false);
- static Buffer * staticbuffer = theBufferList().newInternalBuffer(
- tempfile.name().absFileName());
-
- // These two things only really need doing the first time.
- staticbuffer->setUnnamed(true);
- staticbuffer->inset().setBuffer(*staticbuffer);
-
+ // The initialization of staticbuffer is thread-safe. Using a lambda
+ // guarantees that the properties are set only once.
+ static Buffer * staticbuffer = [&](){
+ Buffer * b =
+
theBufferList().newInternalBuffer(tempfile.name().absFileName());
+ b->setUnnamed(true);
+ b->inset().setBuffer(*b);
+ //initialize staticbuffer with b
+ return b;
+ }();
// Use a clone for the complicated stuff so that we do not need to clean
// up in order to avoid a crash.
Buffer * buffer = staticbuffer->cloneBufferOnly();
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index 75afebf..69090b3 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1251,7 +1251,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
stopBlinkingCursor();
// last_width : for checking if last preedit string was/wasn't empty.
- // FIXME THREAD
+ // FIXME THREAD && FIXME
// We could have more than one work area, right?
static bool last_width = false;
if (!last_width && preedit_string.empty()) {
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index 5ed9052..a51f232 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -44,7 +44,6 @@ public:
};
-// FIXME THREAD
Cache & Cache::get()
{
// Now return the cache
diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp
index 1fa5c65..36a6c06 100644
--- a/src/graphics/GraphicsLoader.cpp
+++ b/src/graphics/GraphicsLoader.cpp
@@ -78,7 +78,6 @@ static int const s_numimages_ = 10;
static int const s_millisecs_ = 500;
-// FIXME THREAD
LoaderQueue & LoaderQueue::get()
{
static LoaderQueue singleton;
diff --git a/src/support/os.cpp b/src/support/os.cpp
index c21d9c5..9dc19e9 100644
--- a/src/support/os.cpp
+++ b/src/support/os.cpp
@@ -64,9 +64,9 @@ int timeout_min()
string const python(bool reset)
{
- // FIXME THREAD
// Check whether the first python in PATH is the right one.
static string command = python23("python -tt");
+ // FIXME THREAD
if (reset) {
command = python23("python -tt");
}