Skip to content

Commit a34f65e

Browse files
committed
fixed accept loop
1 parent b7419e9 commit a34f65e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/DMDUtil/DMDServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DMDUTILAPI DMDServer
2222

2323
bool Start(const char* addr, in_port_t port);
2424
void Stop();
25-
bool IsRunning() const { return m_running; }
25+
bool IsRunning() const { return m_running.load(std::memory_order_acquire); }
2626

2727
private:
2828
void AcceptLoop();

src/DMDServer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DMDServer::~DMDServer() { Stop(); }
2727

2828
bool DMDServer::Start(const char* addr, in_port_t port)
2929
{
30-
if (m_running) return false;
30+
if (m_running.load(std::memory_order_acquire) || !m_dmd->HasDisplay()) return false;
3131

3232
sockpp::initialize();
3333
m_acceptor = sockpp::tcp_acceptor({addr, port});
@@ -37,14 +37,14 @@ bool DMDServer::Start(const char* addr, in_port_t port)
3737
return false;
3838
}
3939

40-
m_running = true;
40+
m_running.store(true, std::memory_order_release);
4141
m_acceptThread = new std::thread(&DMDServer::AcceptLoop, this);
4242
return true;
4343
}
4444

4545
void DMDServer::Stop()
4646
{
47-
m_running = false;
47+
m_running.store(false, std::memory_order_release);
4848

4949
if (m_acceptThread)
5050
{
@@ -62,7 +62,9 @@ void DMDServer::AcceptLoop()
6262
{
6363
uint32_t threadId = 0;
6464

65-
while (m_running && m_dmd->HasDisplay())
65+
(void)m_running.load(std::memory_order_acquire);
66+
67+
while (m_running.load(std::memory_order_relaxed))
6668
{
6769
sockpp::inet_address peer;
6870
sockpp::tcp_socket sock = m_acceptor.accept(&peer);

0 commit comments

Comments
 (0)