Core/Misc: Make World::m_stopEvent thread-safe. Note that the 'virtual' keyword in C/C++ is pretty useless for multithreading

This commit is contained in:
Machiavelli
2012-03-27 13:19:27 +02:00
parent 1ee7196ec0
commit 79a782f143
2 changed files with 7 additions and 6 deletions
+4 -4
View File
@@ -78,7 +78,7 @@
#include "Warden.h"
#include "CalendarMgr.h"
volatile bool World::m_stopEvent = false;
ACE_Atomic_Op<ACE_Thread_Mutex, bool> World::m_stopEvent = false;
uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
volatile uint32 World::m_worldLoopCounter = 0;
@@ -2470,7 +2470,7 @@ void World::_UpdateGameTime()
m_gameTime = thisTime;
///- if there is a shutdown timer
if (!m_stopEvent && m_ShutdownTimer > 0 && elapsed > 0)
if (!IsStopped() && m_ShutdownTimer > 0 && elapsed > 0)
{
///- ... and it is overdue, stop the world (set m_stopEvent)
if (m_ShutdownTimer <= elapsed)
@@ -2494,7 +2494,7 @@ void World::_UpdateGameTime()
void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
{
// ignore if server shutdown at next tick
if (m_stopEvent)
if (IsStopped())
return;
m_ShutdownMask = options;
@@ -2546,7 +2546,7 @@ void World::ShutdownMsg(bool show, Player* player)
void World::ShutdownCancel()
{
// nothing cancel or too later
if (!m_ShutdownTimer || m_stopEvent)
if (!m_ShutdownTimer || m_stopEvent.value())
return;
ServerMessageType msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_CANCELLED : SERVER_MSG_SHUTDOWN_CANCELLED;
+3 -2
View File
@@ -26,6 +26,7 @@
#include "Common.h"
#include "Timer.h"
#include <ace/Singleton.h>
#include <ace/Atomic_Op.h>
#include "SharedDefines.h"
#include "QueryResult.h"
#include "Callback.h"
@@ -650,7 +651,7 @@ class World
void ShutdownMsg(bool show = false, Player* player = NULL);
static uint8 GetExitCode() { return m_ExitCode; }
static void StopNow(uint8 exitcode) { m_stopEvent = true; m_ExitCode = exitcode; }
static bool IsStopped() { return m_stopEvent; }
static bool IsStopped() { return m_stopEvent.value(); }
void Update(uint32 diff);
@@ -770,7 +771,7 @@ class World
void ResetWeeklyQuests();
void ResetRandomBG();
private:
static volatile bool m_stopEvent;
static ACE_Atomic_Op<ACE_Thread_Mutex, bool> m_stopEvent;
static uint8 m_ExitCode;
uint32 m_ShutdownTimer;
uint32 m_ShutdownMask;