Merge pull request #6061 from ligfx/removefiforecordervolatile

FifoRecorder: remove use of volatile
This commit is contained in:
Leo Lam 2017-09-15 18:23:03 +02:00 committed by GitHub
commit ac2f59c1b5
2 changed files with 27 additions and 24 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,9 +59,15 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
void FifoRecorder::StopRecording()
{
std::lock_guard<std::recursive_mutex> lk(m_mutex);
m_RequestedRecordingEnd = true;
}
FifoDataFile* FifoRecorder::GetRecordedFile() const
{
return m_File.get();
}
void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
{
if (!m_SkipNextData)
@ -95,7 +92,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 +150,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 +193,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)
{
@ -213,6 +210,11 @@ void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32*
FifoRecordAnalyzer::Initialize(cpMem);
}
bool FifoRecorder::IsRecording() const
{
return m_IsRecording;
}
FifoRecorder& FifoRecorder::GetInstance()
{
return instance;

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;
// Called from video thread
// Must write one full GP command at a time
@ -40,21 +41,21 @@ public:
u32 xfRegsSize, const u8* texMem);
// Checked once per frame prior to callng EndFrame()
bool IsRecording() const { return m_IsRecording; }
bool IsRecording() const;
static FifoRecorder& GetInstance();
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