mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 22:37:45 +00:00
Remove the need for boost interprocess
This commit is contained in:
parent
72a034d92a
commit
79978bf778
6 changed files with 30 additions and 14 deletions
|
@ -1,7 +1,6 @@
|
|||
#include "Hive.h"
|
||||
#include "Acceptor.h"
|
||||
#include "Connection.h"
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <boost/asio.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <atomic>
|
||||
#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 );
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
#include <list>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <atomic>
|
||||
|
||||
#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 );
|
||||
|
|
|
@ -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()
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <boost/asio.hpp>
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <atomic>
|
||||
|
||||
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
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue