]> git.lyx.org Git - lyx.git/commitdiff
Use std::call_once only if it is actually available
authorEnrico Forestieri <forenr@lyx.org>
Sun, 7 Aug 2016 02:58:41 +0000 (04:58 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 7 Aug 2016 02:58:41 +0000 (04:58 +0200)
config/lyxinclude.m4
src/graphics/PreviewLoader.cpp

index 36e08853f0ca19d38b050b93a5159e241ddb205d..7bddfb09da05500ff6672dc5e548985c187a4740 100644 (file)
@@ -247,6 +247,33 @@ AC_DEFUN([LYX_CXX_USE_REGEX],
 ])
 
 
+dnl Usage: LYX_CXX_USE_CALL_ONCE
+dnl check whether we can use std::call_once and set the
+dnl LYX_USE_STD_CALL_ONCE macro and conditional accordingly.
+AC_DEFUN([LYX_CXX_USE_CALL_ONCE],
+[AC_MSG_CHECKING([for std::call_once availability])
+   save_CPPFLAGS=$CPPFLAGS
+   CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
+   save_CXXFLAGS=$CXXFLAGS
+   CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS"
+   AC_TRY_LINK(
+     [
+       #include <mutex>
+       static std::once_flag flag;
+     ], [
+       std::call_once(flag, [](){ return; });
+   ], [lyx_std_call_once=yes], [lyx_std_call_once=no])
+   CXXFLAGS=$save_CXXFLAGS
+   CPPFLAGS=$save_CPPFLAGS
+   AC_MSG_RESULT([$lyx_std_call_once])
+
+ if test $lyx_std_call_once = yes ; then
+  AC_DEFINE([LYX_USE_STD_CALL_ONCE], 1, [define to 1 if std::call_once is supported by the compiler])
+ fi
+ AM_CONDITIONAL([LYX_USE_STD_CALL_ONCE], test $lyx_std_call_once = yes)
+])
+
+
 dnl Usage: LYX_LIB_STDCXX: set lyx_cv_lib_stdcxx to yes if the STL library is libstdc++.
 AC_DEFUN([LYX_LIB_STDCXX],
 [AC_CACHE_CHECK([whether STL is libstdc++],
@@ -284,6 +311,7 @@ LYX_CXX_CXX11_FLAGS
 LYX_LIB_STDCXX
 LYX_LIB_STDCXX_CXX11_ABI
 LYX_CXX_USE_REGEX
+LYX_CXX_USE_CALL_ONCE
 AC_LANG_POP(C++)
 
 if test $lyx_cv_lib_stdcxx = "yes" ; then
index f8c1d7e6c34ae22b47a1d8ee82551c3d147a6854..88f49b013ef054c8b2404dce32b97e986b657b58 100644 (file)
@@ -93,12 +93,24 @@ lyx::Converter const * setConverter(string const & from)
        }
 
        // Show the error only once
+#ifdef LYX_USE_STD_CALL_ONCE
+       // This is thread-safe.
        static once_flag flag;
        call_once(flag, [&](){
                        LYXERR0("PreviewLoader::startLoading()\n"
                                << "No converter from \"" << from
                                << "\" format has been defined.");
                });
+#else
+       // This is not thread-safe.
+       static bool first = true;
+       if (first) {
+               first = false;
+               LYXERR0("PreviewLoader::startLoading()\n"
+                       << "No converter from \"" << from
+                       << "\" format has been defined.");
+       }
+#endif
        return 0;
 }