From 53c00841fc0d892bf43cda60e3ea2f05c4362b32 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 8 Sep 2022 18:32:26 +0300 Subject: [PATCH] Add support for BOOST_SYSTEM_DISABLE_THREADS (refs #92) --- include/boost/system/detail/config.hpp | 8 +++++++- include/boost/system/detail/error_category_impl.hpp | 11 ++++++++++- test/CMakeLists.txt | 1 + test/Jamfile.v2 | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/boost/system/detail/config.hpp b/include/boost/system/detail/config.hpp index ad958bc..2dbb2f9 100644 --- a/include/boost/system/detail/config.hpp +++ b/include/boost/system/detail/config.hpp @@ -12,8 +12,14 @@ #include // BOOST_SYSTEM_HAS_SYSTEM_ERROR +// +// The macro BOOST_SYSTEM_DISABLE_THREADS can be defined on configurations +// that provide and , but not , such as the +// single-threaded libstdc++. +// +// https://github.com/boostorg/system/issues/92 -#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_NO_CXX11_HDR_MUTEX) +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && ( !defined(BOOST_NO_CXX11_HDR_MUTEX) || defined(BOOST_SYSTEM_DISABLE_THREADS) ) # define BOOST_SYSTEM_HAS_SYSTEM_ERROR #endif diff --git a/include/boost/system/detail/error_category_impl.hpp b/include/boost/system/detail/error_category_impl.hpp index 982c667..904a3a6 100644 --- a/include/boost/system/detail/error_category_impl.hpp +++ b/include/boost/system/detail/error_category_impl.hpp @@ -98,14 +98,19 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR) #include -#include #include +#if !defined(BOOST_SYSTEM_DISABLE_THREADS) +# include +#endif + namespace boost { namespace system { +#if !defined(BOOST_SYSTEM_DISABLE_THREADS) + namespace detail { @@ -118,6 +123,8 @@ template std::mutex stdcat_mx_holder::mx_; } // namespace detail +#endif + inline void error_category::init_stdcat() const { static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" ); @@ -130,7 +137,9 @@ inline void error_category::init_stdcat() const #endif +#if !defined(BOOST_SYSTEM_DISABLE_THREADS) std::lock_guard lk( boost::system::detail::stdcat_mx_holder<>::mx_ ); +#endif if( sc_init_.load( std::memory_order_acquire ) == 0 ) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 172e9eb..55efd27 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ macro(system_run s1) boost_test(SOURCES ${s1} ${ARGN}) boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_NO_ANSI_APIS NAME ${n1}_no_ansi) boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_USE_UTF8 NAME ${n1}_utf8) + boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_DISABLE_THREADS NAME ${n1}_nthr) endmacro() diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d930c02..d110d39 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -33,6 +33,7 @@ rule system-run ( sources + ) result += [ run $(sources) : : : /boost/system//boost_system shared : $(sources[1]:B)_shared ] ; result += [ run $(sources) : : : BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ; result += [ run $(sources) : : : BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ; + result += [ run $(sources) : : : BOOST_SYSTEM_DISABLE_THREADS : $(sources[1]:B)_nthr ] ; return $(result) ; }