Add support for BOOST_SYSTEM_DISABLE_THREADS (refs #92)

This commit is contained in:
Peter Dimov
2022-09-08 18:32:26 +03:00
parent 19e27a73e9
commit 53c00841fc
4 changed files with 19 additions and 2 deletions

View File

@ -12,8 +12,14 @@
#include <boost/config/workaround.hpp>
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
//
// The macro BOOST_SYSTEM_DISABLE_THREADS can be defined on configurations
// that provide <system_error> and <atomic>, but not <mutex>, 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

View File

@ -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 <boost/system/detail/std_category_impl.hpp>
#include <mutex>
#include <new>
#if !defined(BOOST_SYSTEM_DISABLE_THREADS)
# include <mutex>
#endif
namespace boost
{
namespace system
{
#if !defined(BOOST_SYSTEM_DISABLE_THREADS)
namespace detail
{
@ -118,6 +123,8 @@ template<class T> std::mutex stdcat_mx_holder<T>::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<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
#endif
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{

View File

@ -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()

View File

@ -33,6 +33,7 @@ rule system-run ( sources + )
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>shared : $(sources[1]:B)_shared ] ;
result += [ run $(sources) : : : <define>BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_DISABLE_THREADS : $(sources[1]:B)_nthr ] ;
return $(result) ;
}