Skip to content

Commit

Permalink
Merge branch 'ace2' into devcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Sep 15, 2024
2 parents ff028e8 + 9e2faf8 commit 3cac454
Show file tree
Hide file tree
Showing 106 changed files with 2,370 additions and 1,753 deletions.
1 change: 0 additions & 1 deletion contrib/mmap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ include_directories(
../../src/shared
../../src/game
../../src/game/vmap
../../src/game/Maps
../../src/game/Commands
../../dep/include/g3dlite
../../src/framework
Expand Down
4 changes: 2 additions & 2 deletions contrib/mmap/src/TerrainBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ namespace MMAP
ModelInstance& instance = models[i];

// model instances exist in tree even though there are instances of that model in this tile
std::shared_ptr<WorldModel> worldModel = instance.getWorldModel();
WorldModel* worldModel = instance.getWorldModel();
if (!worldModel)
continue;

Expand Down Expand Up @@ -731,7 +731,7 @@ namespace MMAP
ModelInstance instance = models[i];

// model instances exist in tree even though there are instances of that model in this tile
std::shared_ptr<WorldModel> worldModel = instance.getWorldModel();
WorldModel* worldModel = instance.getWorldModel();
if (!worldModel)
continue;

Expand Down
1 change: 0 additions & 1 deletion dep/loadlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ include_directories(
)

# link loadlib with zlib

if(UNIX)
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
Expand Down
9 changes: 5 additions & 4 deletions src/framework/Network/MangosSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include <ace/SOCK_Connector.h>
#include <ace/Acceptor.h>
#include <ace/Connector.h>
#include <ace/Thread_Mutex.h>
#include <ace/Guard_T.h>
#include <ace/Unbounded_Queue.h>
#include <ace/Message_Block.h>
#include <mutex>

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
Expand Down Expand Up @@ -101,9 +102,9 @@ class MangosSocket : public WorldHandler
friend class ACE_Connector<SocketName, ACE_SOCK_CONNECTOR>;
friend class ACE_NonBlocking_Connect_Handler<SocketName>;

// Mutex type used for various synchronizations.
using LockType = std::mutex;
typedef std::unique_lock<LockType> GuardType;
/// Mutex type used for various synchronizations.
typedef ACE_Thread_Mutex LockType;
typedef ACE_Guard<LockType> GuardType;

// Queue for storing packets for which there is no space.
typedef ACE_Unbounded_Queue<WorldPacket*> PacketQueueT;
Expand Down
27 changes: 14 additions & 13 deletions src/framework/Network/MangosSocketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ace/os_include/sys/os_socket.h>
#include <ace/OS_NS_string.h>
#include <ace/Reactor.h>
#include <ace/Auto_Ptr.h>

#include "MangosSocket.h"
#include "Common.h"
Expand Down Expand Up @@ -62,7 +63,7 @@ template <typename SessionType, typename SocketName, typename Crypt>
void MangosSocket<SessionType, SocketName, Crypt>::CloseSocket(void)
{
{
GuardType lock(m_OutBufferLock);
ACE_GUARD(LockType, Guard, m_OutBufferLock);

if (closing_)
return;
Expand All @@ -72,7 +73,7 @@ void MangosSocket<SessionType, SocketName, Crypt>::CloseSocket(void)
}

{
GuardType lock(m_SessionLock);
ACE_GUARD(LockType, Guard, m_SessionLock);

m_Session = nullptr;
}
Expand All @@ -81,7 +82,7 @@ void MangosSocket<SessionType, SocketName, Crypt>::CloseSocket(void)
template <typename SessionType, typename SocketName, typename Crypt>
int MangosSocket<SessionType, SocketName, Crypt>::SendPacket(const WorldPacket& pct)
{
GuardType lock(m_OutBufferLock);
ACE_GUARD_RETURN(LockType, Guard, m_OutBufferLock, -1);

if (closing_)
return -1;
Expand Down Expand Up @@ -204,15 +205,15 @@ int MangosSocket<SessionType, SocketName, Crypt>::handle_input(ACE_HANDLE)
template <typename SessionType, typename SocketName, typename Crypt>
int MangosSocket<SessionType, SocketName, Crypt>::handle_output(ACE_HANDLE)
{
GuardType lock(m_OutBufferLock);
ACE_GUARD_RETURN(LockType, Guard, m_OutBufferLock, -1);

if (closing_)
return -1;

const size_t send_len = m_OutBuffer->length();

if (send_len == 0)
return cancel_wakeup_output(lock);
return cancel_wakeup_output(Guard);

#ifdef MSG_NOSIGNAL
ssize_t n = peer().send(m_OutBuffer->rd_ptr(), send_len, MSG_NOSIGNAL);
Expand All @@ -230,7 +231,7 @@ int MangosSocket<SessionType, SocketName, Crypt>::handle_output(ACE_HANDLE)
#endif

if (errno == EWOULDBLOCK || errno == EAGAIN)
return schedule_wakeup_output(lock);
return schedule_wakeup_output(Guard);

return -1;
}
Expand All @@ -241,16 +242,16 @@ int MangosSocket<SessionType, SocketName, Crypt>::handle_output(ACE_HANDLE)
// move the data to the base of the buffer
m_OutBuffer->crunch();

return schedule_wakeup_output(lock);
return schedule_wakeup_output(Guard);
}
else //now n == send_len
{
m_OutBuffer->reset();

if (!iFlushPacketQueue())
return cancel_wakeup_output(lock);
return cancel_wakeup_output(Guard);
else
return schedule_wakeup_output(lock);
return schedule_wakeup_output(Guard);
}

ACE_NOTREACHED(return 0);
Expand All @@ -261,7 +262,7 @@ int MangosSocket<SessionType, SocketName, Crypt>::handle_close(ACE_HANDLE h, ACE
{
// Critical section
{
GuardType lock(m_OutBufferLock);
ACE_GUARD_RETURN(LockType, Guard, m_OutBufferLock, -1);

closing_ = true;

Expand All @@ -271,7 +272,7 @@ int MangosSocket<SessionType, SocketName, Crypt>::handle_close(ACE_HANDLE h, ACE

// Critical section
{
GuardType lock(m_SessionLock);
ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);

m_Session = nullptr;
}
Expand Down Expand Up @@ -452,7 +453,7 @@ int MangosSocket<SessionType, SocketName, Crypt>::cancel_wakeup_output(GuardType

m_OutActive = false;

g.unlock();
g.release();

if (reactor()->cancel_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
Expand All @@ -473,7 +474,7 @@ int MangosSocket<SessionType, SocketName, Crypt>::schedule_wakeup_output(GuardTy

m_OutActive = true;

g.unlock();
g.release();

if (reactor()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
Expand Down
2 changes: 2 additions & 0 deletions src/framework/Network/MangosSocketMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define MANGOSSOCKETMGR_H

#include <ace/Basic_Types.h>
#include <ace/Singleton.h>
#include <ace/Thread_Mutex.h>

#include <string>

Expand Down
12 changes: 6 additions & 6 deletions src/framework/Network/MangosSocketMgrImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ace/TP_Reactor.h>
#include <ace/Dev_Poll_Reactor.h>
#include <ace/Guard_T.h>
#include <ace/Atomic_Op.h>
#include <ace/os_include/arpa/os_inet.h>
#include <ace/os_include/netinet/os_tcp.h>
#include <ace/os_include/sys/os_types.h>
Expand All @@ -16,7 +17,6 @@
#include <ace/SOCK_Acceptor.h>

#include <set>
#include <atomic>

#include "Log.h"
#include "Common.h"
Expand Down Expand Up @@ -121,12 +121,12 @@ class ReactorRunnable : protected ACE_Task_Base

long Connections()
{
return m_Connections;
return static_cast<long>(m_Connections.value());
}

int AddSocket(SocketType* sock)
{
std::unique_lock<std::mutex> lock(m_NewSockets_Lock);
ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1);

++m_Connections;
sock->AddReference();
Expand All @@ -144,7 +144,7 @@ class ReactorRunnable : protected ACE_Task_Base
protected:
void AddNewSockets()
{
std::unique_lock<std::mutex> lock(m_NewSockets_Lock);
ACE_GUARD(ACE_Thread_Mutex, Guard, m_NewSockets_Lock);

if (m_NewSockets.empty())
return;
Expand Down Expand Up @@ -210,7 +210,7 @@ class ReactorRunnable : protected ACE_Task_Base
}

private:
using AtomicInt = std::atomic<int>;
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, int> AtomicInt;
typedef std::set<SocketType*> SocketSet;

ACE_Reactor* m_Reactor;
Expand All @@ -221,7 +221,7 @@ class ReactorRunnable : protected ACE_Task_Base
SocketSet m_Sockets;

SocketSet m_NewSockets;
std::mutex m_NewSockets_Lock;
ACE_Thread_Mutex m_NewSockets_Lock;
};

template <typename SocketType>
Expand Down
107 changes: 79 additions & 28 deletions src/framework/Policies/ThreadingModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/

#include "Platform/Define.h"
#include <mutex>

namespace MaNGOS
{
Expand All @@ -40,63 +39,115 @@ namespace MaNGOS
GeneralLock(MUTEX &m)
: i_mutex(m)
{
i_mutex.acquire();
}

~GeneralLock()
{
i_mutex.release();
}

GeneralLock(const GeneralLock &) = delete;
GeneralLock& operator=(const GeneralLock &) = delete;
private:

GeneralLock(const GeneralLock &);
GeneralLock& operator=(const GeneralLock &);
MUTEX &i_mutex;
std::unique_lock<MUTEX> m_lock{i_mutex};

};

template<class T>
class SingleThreaded
{
public:
public:

struct Lock // empty object
{
Lock()
{
}
Lock(const T&)
{
}

Lock(const SingleThreaded<T>&) // for single threaded we ignore this
{
}
};
};

template<class T, class MUTEX>
class ObjectLevelLockable
{
public:

struct Lock // empty object
{
Lock() = default;
ObjectLevelLockable()
: i_mtx()
{
}

friend class Lock;

class Lock
{
public:

Lock(const T&) { }
Lock(ObjectLevelLockable<T, MUTEX> &host)
: i_lock(host.i_mtx)
{
}

Lock(const SingleThreaded<T>&) { } // for single threaded we ignore this
};
private:

GeneralLock<MUTEX> i_lock;
};

private:

// prevent the compiler creating a copy construct
ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX>&);
ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX>&);

MUTEX i_mtx;
};

template<class T, class MUTEX>
class ClassLevelLockable
{
public:
public:

ClassLevelLockable()
{
}
ClassLevelLockable()
{
}

friend class Lock;
friend class Lock;

class Lock
{
public:
class Lock
{
public:

Lock(const T& /*host*/) { }
Lock(const T& /*host*/)
{
ClassLevelLockable<T, MUTEX>::si_mtx.acquire();
}

Lock(const ClassLevelLockable<T, MUTEX> &) { }
Lock(const ClassLevelLockable<T, MUTEX> &)
{
ClassLevelLockable<T, MUTEX>::si_mtx.acquire();
}

Lock() = default;
private:
std::unique_lock<MUTEX> m_lock{si_mtx};
};
Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.acquire();
}

~Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.release();
}
};

private:
private:

static MUTEX si_mtx;
static MUTEX si_mtx;
};

}
Expand Down
Loading

0 comments on commit 3cac454

Please sign in to comment.