Allow rewind manager to have 2 process instances

This commit is contained in:
Benau 2020-02-28 09:43:19 +08:00
parent ca0749cf6b
commit 1958e5940c
2 changed files with 16 additions and 14 deletions

View File

@ -36,24 +36,26 @@
#include <algorithm>
RewindManager* RewindManager::m_rewind_manager = NULL;
bool RewindManager::m_enable_rewind_manager = false;
RewindManager* RewindManager::m_rewind_manager[PT_COUNT];
std::atomic_bool RewindManager::m_enable_rewind_manager(false);
/** Creates the singleton. */
RewindManager *RewindManager::create()
{
assert(!m_rewind_manager);
m_rewind_manager = new RewindManager();
return m_rewind_manager;
ProcessType pt = STKProcess::getType();
assert(!m_rewind_manager[pt]);
m_rewind_manager[pt] = new RewindManager();
return m_rewind_manager[pt];
} // create
// ----------------------------------------------------------------------------
/** Destroys the singleton. */
void RewindManager::destroy()
{
assert(m_rewind_manager);
delete m_rewind_manager;
m_rewind_manager = NULL;
ProcessType pt = STKProcess::getType();
assert(m_rewind_manager[pt]);
delete m_rewind_manager[pt];
m_rewind_manager[pt] = NULL;
} // destroy
// ============================================================================

View File

@ -20,8 +20,7 @@
#define HEADER_REWIND_MANAGER_HPP
#include "network/rewind_queue.hpp"
#include "utils/ptr_vector.hpp"
#include "utils/synchronised.hpp"
#include "utils/stk_process.hpp"
#include <assert.h>
#include <atomic>
@ -86,11 +85,11 @@ class RewindManager
{
private:
/** Singleton pointer. */
static RewindManager *m_rewind_manager;
static RewindManager *m_rewind_manager[PT_COUNT];
/** En- or Disable the rewind manager. This is used to disable storing
* rewind data in case of local races only. */
static bool m_enable_rewind_manager;
static std::atomic_bool m_enable_rewind_manager;
std::map<int, std::vector<std::function<void()> > > m_local_state;
@ -150,8 +149,9 @@ public:
* the singleton. */
static RewindManager *get()
{
assert(m_rewind_manager);
return m_rewind_manager;
ProcessType pt = STKProcess::getType();
assert(m_rewind_manager[pt]);
return m_rewind_manager[pt];
} // get
// Non-static function declarations: