Skip to content

Commit

Permalink
Add support for BOOST_SYSTEM_DISABLE_THREADS (refs #92)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Sep 8, 2022
1 parent 19e27a7 commit 53c0084
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion include/boost/system/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion include/boost/system/detail/error_category_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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" );
Expand All @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;
}
Expand Down

0 comments on commit 53c0084

Please sign in to comment.