feat(Core/Threading): replace ace threading (#4821)

This commit is contained in:
Kargatum
2021-04-17 00:45:29 +07:00
committed by GitHub
parent b9e84d8278
commit b2861be1cd
50 changed files with 300 additions and 342 deletions

View File

@@ -126,7 +126,7 @@ void WorldSocket::CloseSocket(std::string const& reason)
sLog->outDebug(LOG_FILTER_CLOSE_SOCKET, "Socket closed because of: %s", reason.c_str());
{
ACE_GUARD (LockType, Guard, m_OutBufferLock);
std::lock_guard<std::mutex> guard(m_OutBufferLock);
if (closing_)
return;
@@ -136,7 +136,7 @@ void WorldSocket::CloseSocket(std::string const& reason)
}
{
ACE_GUARD (LockType, Guard, m_SessionLock);
std::lock_guard<std::mutex> guard(m_SessionLock);
m_Session = nullptr;
}
@@ -149,7 +149,7 @@ const std::string& WorldSocket::GetRemoteAddress(void) const
int WorldSocket::SendPacket(WorldPacket const& pct)
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
std::lock_guard<std::mutex> guard(m_OutBufferLock);
if (closing_)
return -1;
@@ -306,20 +306,20 @@ int WorldSocket::handle_input(ACE_HANDLE)
return Update(); // another interesting line ;)
}
ACE_NOTREACHED(return -1);
return -1;
}
int WorldSocket::handle_output(ACE_HANDLE)
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
if (closing_)
return -1;
std::lock_guard<std::mutex> guard(m_OutBufferLock);
size_t send_len = m_OutBuffer->length();
if (send_len == 0)
return handle_output_queue(Guard);
return handle_output_queue();
#ifdef MSG_NOSIGNAL
ssize_t n = peer().send (m_OutBuffer->rd_ptr(), send_len, MSG_NOSIGNAL);
@@ -332,7 +332,7 @@ int WorldSocket::handle_output(ACE_HANDLE)
else if (n == -1)
{
if (errno == EWOULDBLOCK || errno == EAGAIN)
return schedule_wakeup_output (Guard);
return schedule_wakeup_output();
return -1;
}
@@ -343,22 +343,22 @@ int WorldSocket::handle_output(ACE_HANDLE)
// move the data to the base of the buffer
m_OutBuffer->crunch();
return schedule_wakeup_output (Guard);
return schedule_wakeup_output();
}
else //now n == send_len
{
m_OutBuffer->reset();
return handle_output_queue (Guard);
return handle_output_queue();
}
ACE_NOTREACHED (return 0);
}
int WorldSocket::handle_output_queue(GuardType& g)
int WorldSocket::handle_output_queue()
{
if (msg_queue()->is_empty())
return cancel_wakeup_output(g);
return cancel_wakeup_output();
ACE_Message_Block* mblk;
@@ -387,7 +387,7 @@ int WorldSocket::handle_output_queue(GuardType& g)
if (errno == EWOULDBLOCK || errno == EAGAIN)
{
msg_queue()->enqueue_head(mblk, (ACE_Time_Value*) &ACE_Time_Value::zero);
return schedule_wakeup_output (g);
return schedule_wakeup_output();
}
mblk->release();
@@ -404,23 +404,23 @@ int WorldSocket::handle_output_queue(GuardType& g)
return -1;
}
return schedule_wakeup_output (g);
return schedule_wakeup_output();
}
else //now n == send_len
{
mblk->release();
return msg_queue()->is_empty() ? cancel_wakeup_output(g) : ACE_Event_Handler::WRITE_MASK;
return msg_queue()->is_empty() ? cancel_wakeup_output() : ACE_Event_Handler::WRITE_MASK;
}
ACE_NOTREACHED(return -1);
return -1;
}
int WorldSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
{
// Critical section
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
std::lock_guard<std::mutex> guard(m_OutBufferLock);
closing_ = true;
@@ -430,7 +430,7 @@ int WorldSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
// Critical section
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
std::lock_guard<decltype(m_SessionLock)> guard(m_SessionLock);
m_Session = nullptr;
}
@@ -448,7 +448,8 @@ int WorldSocket::Update(void)
return 0;
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, 0);
std::lock_guard<std::mutex> guard(m_OutBufferLock);
if (m_OutBuffer->length() == 0 && msg_queue()->is_empty())
return 0;
}
@@ -612,15 +613,13 @@ int WorldSocket::handle_input_missing_data(void)
return size_t(n) == recv_size ? 1 : 2;
}
int WorldSocket::cancel_wakeup_output(GuardType& g)
int WorldSocket::cancel_wakeup_output()
{
if (!m_OutActive)
return 0;
m_OutActive = false;
g.release();
if (reactor()->cancel_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
@@ -632,15 +631,13 @@ int WorldSocket::cancel_wakeup_output(GuardType& g)
return 0;
}
int WorldSocket::schedule_wakeup_output(GuardType& g)
int WorldSocket::schedule_wakeup_output()
{
if (m_OutActive)
return 0;
m_OutActive = true;
g.release();
if (reactor()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
@@ -694,7 +691,7 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
return 0;
default:
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
std::lock_guard<std::mutex> guard(m_SessionLock);
if (m_Session != nullptr)
{
@@ -1050,7 +1047,7 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
if (max_count && m_OverSpeedPings > max_count)
{
ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);
std::lock_guard<std::mutex> guard(m_SessionLock);
if (m_Session && AccountMgr::IsPlayerAccount(m_Session->GetSecurity()))
{
@@ -1071,7 +1068,7 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
// critical section
{
ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);
std::lock_guard<std::mutex> guard(m_SessionLock);
if (m_Session)
{