[redcode/crythread-2nd-pass] remove dependency on cry threads in the remote console runtime

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
AMZN-ScottR
2021-08-06 17:45:54 -07:00
parent 6b2c9cbede
commit 2f5927f1ac
2 changed files with 84 additions and 46 deletions
@@ -11,9 +11,11 @@
#include <AzCore/std/containers/map.h>
#include <AzCore/std/containers/list.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/parallel/condition_variable.h>
#include <AzCore/std/parallel/mutex.h>
#include <AzCore/std/parallel/thread.h>
#include <AzCore/std/string/string.h>
#include <CryThread.h>
extern const int defaultRemoteConsolePort;
@@ -146,6 +148,30 @@ private:
typedef AZStd::list<IRemoteEvent*> TEventBuffer;
/////////////////////////////////////////////////////////////////////////////////////////////
// SRemoteThreadedObject
//
// Simple runnable-like threaded object
//
/////////////////////////////////////////////////////////////////////////////////////////////
struct SRemoteThreadedObject
{
virtual ~SRemoteThreadedObject() = default;
void Start(const char* name);
void WaitForThread();
virtual void Run() = 0;
virtual void Terminate() = 0;
private:
void ThreadFunction();
AZStd::thread m_thread;
};
/////////////////////////////////////////////////////////////////////////////////////////////
// SRemoteServer
//
@@ -154,10 +180,10 @@ typedef AZStd::list<IRemoteEvent*> TEventBuffer;
/////////////////////////////////////////////////////////////////////////////////////////////
struct SRemoteClient;
struct SRemoteServer
: public CrySimpleThread<>
: public SRemoteThreadedObject
{
SRemoteServer()
: m_socket(AZ_SOCKET_INVALID) { m_stopEvent.Set(); }
: m_socket(AZ_SOCKET_INVALID) {}
void StartServer();
void StopServer();
@@ -165,10 +191,8 @@ struct SRemoteServer
void AddEvent(IRemoteEvent* pEvent);
void GetEvents(TEventBuffer& buffer);
// CrySimpleThread
void Terminate() override;
void Run() override;
// ~CrySimpleThread
private:
bool WriteBuffer(SRemoteClient* pClient, char* buffer, int& size);
@@ -189,9 +213,9 @@ private:
typedef AZStd::vector<SRemoteClientInfo> TClients;
TClients m_clients;
AZSOCKET m_socket;
CryMutex m_lock;
AZStd::recursive_mutex m_mutex;
TEventBuffer m_eventBuffer;
CryEvent m_stopEvent;
AZStd::condition_variable_any m_stopCondition;
volatile bool m_bAcceptClients;
friend struct SRemoteClient;
};
@@ -204,7 +228,7 @@ private:
//
/////////////////////////////////////////////////////////////////////////////////////////////
struct SRemoteClient
: public CrySimpleThread<>
: public SRemoteThreadedObject
{
SRemoteClient(SRemoteServer* pServer)
: m_pServer(pServer)
@@ -213,10 +237,8 @@ struct SRemoteClient
void StartClient(AZSOCKET socket);
void StopClient();
// CrySimpleThread
void Terminate() override;
void Run() override;
// ~CrySimpleThread
private:
bool RecvPackage(char* buffer, int& size);