mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 08:18:05 +01:00
Compare commits
4 Commits
feature/sy
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbc5ec42f | ||
|
|
9deadda4b4 | ||
|
|
1d845408dd | ||
|
|
e08e4253d0 |
@@ -22,6 +22,11 @@
|
||||
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_MUTEX)
|
||||
// Required for thread-safe map manipulation
|
||||
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_NOEXCEPT
|
||||
// Retained for backward compatibility
|
||||
|
||||
@@ -43,15 +48,4 @@
|
||||
# define BOOST_SYSTEM_CONSTEXPR
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
|
||||
#define BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(clang::require_constant_initialization)
|
||||
# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <system_error>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
//
|
||||
|
||||
@@ -30,8 +31,20 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
|
||||
{
|
||||
if( id != 0 )
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
|
||||
|
||||
// Poking into the protected _Addr member of std::error_category
|
||||
// is not a particularly good programming practice, but what can
|
||||
// you do
|
||||
|
||||
_Addr = id;
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
@@ -55,24 +68,48 @@ public:
|
||||
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat ) BOOST_SYMBOL_VISIBLE;
|
||||
|
||||
struct cat_ptr_less
|
||||
{
|
||||
bool operator()( boost::system::error_category const * p1, boost::system::error_category const * p2 ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *p1 < *p2;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
|
||||
{
|
||||
typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category> > map_type;
|
||||
|
||||
static map_type map_;
|
||||
|
||||
map_type::iterator i = map_.find( &cat );
|
||||
|
||||
if( i == map_.end() )
|
||||
if( cat == boost::system::system_category() )
|
||||
{
|
||||
std::unique_ptr<std_category> p( new std_category( &cat ) );
|
||||
|
||||
std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );
|
||||
|
||||
i = r.first;
|
||||
static const std_category system_instance( &cat, 0x1F4D7 );
|
||||
return system_instance;
|
||||
}
|
||||
else if( cat == boost::system::generic_category() )
|
||||
{
|
||||
static const std_category generic_instance( &cat, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category>, cat_ptr_less > map_type;
|
||||
|
||||
return *i->second;
|
||||
static map_type map_;
|
||||
static std::mutex map_mx_;
|
||||
|
||||
std::lock_guard<std::mutex> guard( map_mx_ );
|
||||
|
||||
map_type::iterator i = map_.find( &cat );
|
||||
|
||||
if( i == map_.end() )
|
||||
{
|
||||
std::unique_ptr<std_category> p( new std_category( &cat, 0 ) );
|
||||
|
||||
std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );
|
||||
|
||||
i = r.first;
|
||||
}
|
||||
|
||||
return *i->second;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
|
||||
|
||||
@@ -331,12 +331,12 @@ namespace detail
|
||||
|
||||
template<class T> struct BOOST_SYMBOL_VISIBLE cat_holder
|
||||
{
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr system_error_category system_category_instance{};
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr generic_error_category generic_category_instance{};
|
||||
static constexpr system_error_category system_category_instance{};
|
||||
static constexpr generic_error_category generic_category_instance{};
|
||||
};
|
||||
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr generic_error_category cat_holder<T>::generic_category_instance;
|
||||
template<class T> constexpr system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> constexpr generic_error_category cat_holder<T>::generic_category_instance;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
@@ -68,4 +68,4 @@ lib std_single_instance_lib2 : std_single_instance_2.cpp : <link>shared:<define>
|
||||
|
||||
system-run std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp ;
|
||||
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>static : std_single_instance_lib_static ;
|
||||
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared : std_single_instance_lib_shared ;
|
||||
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared <define>STD_SINGLE_INSTANCE_SHARED : std_single_instance_lib_shared ;
|
||||
|
||||
@@ -31,4 +31,10 @@ EXPORT std::error_code get_generic_code()
|
||||
|
||||
} // namespace lib1
|
||||
|
||||
#else
|
||||
|
||||
EXPORT void lib1_f()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,4 +31,10 @@ EXPORT std::error_code get_generic_code()
|
||||
|
||||
} // namespace lib2
|
||||
|
||||
#else
|
||||
|
||||
EXPORT void lib2_f()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,11 +4,31 @@
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config/helper_macros.hpp>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(__CYGWIN__)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, __CYGWIN__" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_MSC_VER)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _MSC_VER" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_CPPLIB_VER)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _CPPLIB_VER" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && (_MSC_VER < 1900 || _MSC_VER >= 2000)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, _MSC_VER is " BOOST_STRINGIZE(_MSC_VER) )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user