diff --git a/src/common/Network/Acceptor.cpp b/src/common/Network/Acceptor.cpp index 94134845..2b04cc43 100644 --- a/src/common/Network/Acceptor.cpp +++ b/src/common/Network/Acceptor.cpp @@ -1,7 +1,6 @@ #include "Hive.h" #include "Acceptor.h" #include "Connection.h" -#include #include namespace Core { @@ -36,7 +35,9 @@ void Acceptor::OnError( const boost::system::error_code& error ) void Acceptor::StartError( const boost::system::error_code& error ) { - if( boost::interprocess::ipcdetail::atomic_cas32( &m_error_state, 1, 0 ) == 0 ) + uint32_t v1 = 1; + uint32_t v2 = 0; + if( m_error_state.compare_exchange_strong( v1, v2 ) ) { boost::system::error_code ec; m_acceptor.cancel( ec ); @@ -123,7 +124,9 @@ boost::asio::ip::tcp::acceptor& Acceptor::GetAcceptor() bool Acceptor::HasError() { - return ( boost::interprocess::ipcdetail::atomic_cas32( &m_error_state, 1, 1 ) == 1 ); + uint32_t v1 = 1; + uint32_t v2 = 1; + return ( m_error_state.compare_exchange_strong( v1, v2 ) ); } } diff --git a/src/common/Network/Acceptor.h b/src/common/Network/Acceptor.h index 99586d45..e73114ab 100644 --- a/src/common/Network/Acceptor.h +++ b/src/common/Network/Acceptor.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "Forwards.h" namespace Core { @@ -20,7 +21,7 @@ private: HivePtr m_hive; boost::asio::ip::tcp::acceptor m_acceptor; boost::asio::strand m_io_strand; - volatile uint32_t m_error_state; + std::atomic< uint32_t > m_error_state; private: Acceptor( const Acceptor& rhs ); diff --git a/src/common/Network/Connection.cpp b/src/common/Network/Connection.cpp index 9b314f18..2f672700 100644 --- a/src/common/Network/Connection.cpp +++ b/src/common/Network/Connection.cpp @@ -67,7 +67,9 @@ void Connection::StartRecv( int32_t total_bytes ) void Connection::StartError( const boost::system::error_code& error ) { - if( boost::interprocess::ipcdetail::atomic_cas32( &m_error_state, 1, 0 ) == 0 ) + uint32_t v1 = 1; + uint32_t v2 = 0; + if( !m_error_state.compare_exchange_strong( v1, v2 ) ) { boost::system::error_code ec; m_socket.shutdown( boost::asio::ip::tcp::socket::shutdown_both, ec ); @@ -204,10 +206,12 @@ int32_t Connection::GetReceiveBufferSize() const bool Connection::HasError() { - return ( boost::interprocess::ipcdetail::atomic_cas32( &m_error_state, 1, 1 ) == 1 ); + uint32_t v1 = 1; + uint32_t v2 = 1; + return ( m_error_state.compare_exchange_strong( v1, v2 ) ); } } } -//----------------------------------------------------------------------------- \ No newline at end of file +//----------------------------------------------------------------------------- diff --git a/src/common/Network/Connection.h b/src/common/Network/Connection.h index bb4decf6..d92c0901 100644 --- a/src/common/Network/Connection.h +++ b/src/common/Network/Connection.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "Forwards.h" #include "Acceptor.h" @@ -40,7 +41,7 @@ protected: std::list< int32_t > m_pending_recvs; std::list< std::vector< uint8_t > > m_pending_sends; int32_t m_receive_buffer_size; - volatile uint32_t m_error_state; + std::atomic< uint32_t > m_error_state; Connection( HivePtr hive ); diff --git a/src/common/Network/Hive.cpp b/src/common/Network/Hive.cpp index 73c12895..772cfa40 100644 --- a/src/common/Network/Hive.cpp +++ b/src/common/Network/Hive.cpp @@ -26,7 +26,9 @@ boost::asio::io_service& Hive::GetService() bool Hive::HasStopped() { - return ( boost::interprocess::ipcdetail::atomic_cas32( &m_shutdown, 1, 1 ) == 1 ); + uint32_t v1 = 1; + uint32_t v2 = 1; + return m_shutdown.compare_exchange_strong( v1, v2 ); } void Hive::Poll() @@ -41,7 +43,9 @@ void Hive::Run() void Hive::Stop() { - if( boost::interprocess::ipcdetail::atomic_cas32( &m_shutdown, 1, 0 ) == 0 ) + uint32_t v1 = 1; + uint32_t v2 = 0; + if( !m_shutdown.compare_exchange_strong( v1, v2 ) ) { m_work_ptr.reset(); m_io_service.run(); @@ -51,7 +55,9 @@ void Hive::Stop() void Hive::Reset() { - if( boost::interprocess::ipcdetail::atomic_cas32( &m_shutdown, 0, 1 ) == 1 ) + uint32_t v1 = 0; + uint32_t v2 = 1; + if( m_shutdown.compare_exchange_strong( v1, v2 ) ) { m_io_service.reset(); m_work_ptr.reset( new boost::asio::io_service::work( m_io_service ) ); @@ -59,4 +65,4 @@ void Hive::Reset() } } -} \ No newline at end of file +} diff --git a/src/common/Network/Hive.h b/src/common/Network/Hive.h index 4e77ae8a..41ed1d88 100644 --- a/src/common/Network/Hive.h +++ b/src/common/Network/Hive.h @@ -4,6 +4,7 @@ #include #include +#include namespace Core { namespace Network { @@ -14,7 +15,7 @@ class Hive : private: boost::asio::io_service m_io_service; boost::shared_ptr< boost::asio::io_service::work > m_work_ptr; - volatile uint32_t m_shutdown; + std::atomic< uint32_t > m_shutdown; private: Hive( const Hive& rhs ); @@ -54,4 +55,4 @@ public: } } //----------------------------------------------------------------------------- -#endif \ No newline at end of file +#endif