NetworkSingleton: LibEvent thread is joined properly on server exit.
This commit is contained in:
parent
af1a5b36db
commit
70d54054e3
@ -63,8 +63,7 @@ cNetworkSingleton::cNetworkSingleton(void):
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the event loop thread:
|
// Create the event loop thread:
|
||||||
std::thread EventLoopThread(RunEventLoop, this);
|
m_EventLoopThread = std::thread(RunEventLoop, this);
|
||||||
EventLoopThread.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +97,7 @@ void cNetworkSingleton::Terminate(void)
|
|||||||
|
|
||||||
// Wait for the LibEvent event loop to terminate:
|
// Wait for the LibEvent event loop to terminate:
|
||||||
event_base_loopbreak(m_EventBase);
|
event_base_loopbreak(m_EventBase);
|
||||||
m_EventLoopTerminated.Wait();
|
m_EventLoopThread.join();
|
||||||
|
|
||||||
// Remove all objects:
|
// Remove all objects:
|
||||||
{
|
{
|
||||||
@ -143,7 +142,6 @@ void cNetworkSingleton::LogCallback(int a_Severity, const char * a_Msg)
|
|||||||
void cNetworkSingleton::RunEventLoop(cNetworkSingleton * a_Self)
|
void cNetworkSingleton::RunEventLoop(cNetworkSingleton * a_Self)
|
||||||
{
|
{
|
||||||
event_base_loop(a_Self->m_EventBase, EVLOOP_NO_EXIT_ON_EMPTY);
|
event_base_loop(a_Self->m_EventBase, EVLOOP_NO_EXIT_ON_EMPTY);
|
||||||
a_Self->m_EventLoopTerminated.Set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,12 +116,12 @@ protected:
|
|||||||
/** Mutex protecting all containers against multithreaded access. */
|
/** Mutex protecting all containers against multithreaded access. */
|
||||||
cCriticalSection m_CS;
|
cCriticalSection m_CS;
|
||||||
|
|
||||||
/** Event that gets signalled when the event loop terminates. */
|
|
||||||
cEvent m_EventLoopTerminated;
|
|
||||||
|
|
||||||
/** Set to true if Terminate has been called. */
|
/** Set to true if Terminate has been called. */
|
||||||
volatile bool m_HasTerminated;
|
volatile bool m_HasTerminated;
|
||||||
|
|
||||||
|
/** The thread in which the main LibEvent loop runs. */
|
||||||
|
std::thread m_EventLoopThread;
|
||||||
|
|
||||||
|
|
||||||
/** Initializes the LibEvent internals. */
|
/** Initializes the LibEvent internals. */
|
||||||
cNetworkSingleton(void);
|
cNetworkSingleton(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user