FifoRecorder: remove use of volatile

This commit is contained in:
Michael M 2017-09-14 11:54:05 -07:00
parent 5576af061b
commit a47ce0d625
2 changed files with 16 additions and 23 deletions

View File

@ -6,7 +6,6 @@
#include <algorithm>
#include <cstring>
#include <mutex>
#include "Common/MsgHandler.h"
#include "Common/Thread.h"
@ -16,24 +15,16 @@
#include "Core/HW/Memmap.h"
static FifoRecorder instance;
static std::recursive_mutex sMutex;
FifoRecorder::FifoRecorder() = default;
FifoRecorder::~FifoRecorder()
{
m_IsRecording = false;
}
void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
{
std::lock_guard<std::recursive_mutex> lk(sMutex);
delete m_File;
std::lock_guard<std::recursive_mutex> lk(m_mutex);
FifoAnalyzer::Init();
m_File = new FifoDataFile;
m_File = std::make_unique<FifoDataFile>();
// TODO: This, ideally, would be deallocated when done recording.
// However, care needs to be taken since global state
@ -68,6 +59,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
void FifoRecorder::StopRecording()
{
std::lock_guard<std::recursive_mutex> lk(m_mutex);
m_RequestedRecordingEnd = true;
}
@ -95,7 +87,7 @@ void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
m_CurrentFrame.fifoData = m_FifoData;
{
std::lock_guard<std::recursive_mutex> lk(sMutex);
std::lock_guard<std::recursive_mutex> lk(m_mutex);
// Copy frame to file
// The file will be responsible for freeing the memory allocated for each frame's fifoData
@ -153,7 +145,7 @@ void FifoRecorder::UseMemory(u32 address, u32 size, MemoryUpdate::Type type, boo
void FifoRecorder::EndFrame(u32 fifoStart, u32 fifoEnd)
{
// m_IsRecording is assumed to be true at this point, otherwise this function would not be called
std::lock_guard<std::recursive_mutex> lk(sMutex);
std::lock_guard<std::recursive_mutex> lk(m_mutex);
m_FrameEnded = true;
@ -196,7 +188,7 @@ void FifoRecorder::EndFrame(u32 fifoStart, u32 fifoEnd)
void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32* xfMem,
const u32* xfRegs, u32 xfRegsSize, const u8* texMem)
{
std::lock_guard<std::recursive_mutex> lk(sMutex);
std::lock_guard<std::recursive_mutex> lk(m_mutex);
if (m_File)
{

View File

@ -4,6 +4,8 @@
#pragma once
#include <memory>
#include <mutex>
#include <vector>
#include "Core/FifoPlayer/FifoDataFile.h"
@ -14,12 +16,11 @@ public:
typedef void (*CallbackFunc)(void);
FifoRecorder();
~FifoRecorder();
void StartRecording(s32 numFrames, CallbackFunc finishedCb);
void StopRecording();
FifoDataFile* GetRecordedFile() const { return m_File; }
FifoDataFile* GetRecordedFile() const { return m_File.get(); }
// Called from video thread
// Must write one full GP command at a time
@ -46,15 +47,15 @@ public:
private:
// Accessed from both GUI and video threads
std::recursive_mutex m_mutex;
// True if video thread should send data
volatile bool m_IsRecording = false;
bool m_IsRecording = false;
// True if m_IsRecording was true during last frame
volatile bool m_WasRecording = false;
volatile bool m_RequestedRecordingEnd = false;
volatile s32 m_RecordFramesRemaining = 0;
volatile CallbackFunc m_FinishedCb = nullptr;
FifoDataFile* volatile m_File = nullptr;
bool m_WasRecording = false;
bool m_RequestedRecordingEnd = false;
s32 m_RecordFramesRemaining = 0;
CallbackFunc m_FinishedCb = nullptr;
std::unique_ptr<FifoDataFile> m_File;
// Accessed only from video thread