Merge pull request #6061 from ligfx/removefiforecordervolatile
FifoRecorder: remove use of volatile
This commit is contained in:
commit
ac2f59c1b5
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
|
@ -16,24 +15,16 @@
|
||||||
#include "Core/HW/Memmap.h"
|
#include "Core/HW/Memmap.h"
|
||||||
|
|
||||||
static FifoRecorder instance;
|
static FifoRecorder instance;
|
||||||
static std::recursive_mutex sMutex;
|
|
||||||
|
|
||||||
FifoRecorder::FifoRecorder() = default;
|
FifoRecorder::FifoRecorder() = default;
|
||||||
|
|
||||||
FifoRecorder::~FifoRecorder()
|
|
||||||
{
|
|
||||||
m_IsRecording = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
|
void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> lk(sMutex);
|
std::lock_guard<std::recursive_mutex> lk(m_mutex);
|
||||||
|
|
||||||
delete m_File;
|
|
||||||
|
|
||||||
FifoAnalyzer::Init();
|
FifoAnalyzer::Init();
|
||||||
|
|
||||||
m_File = new FifoDataFile;
|
m_File = std::make_unique<FifoDataFile>();
|
||||||
|
|
||||||
// TODO: This, ideally, would be deallocated when done recording.
|
// TODO: This, ideally, would be deallocated when done recording.
|
||||||
// However, care needs to be taken since global state
|
// However, care needs to be taken since global state
|
||||||
|
@ -68,9 +59,15 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
|
||||||
|
|
||||||
void FifoRecorder::StopRecording()
|
void FifoRecorder::StopRecording()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lk(m_mutex);
|
||||||
m_RequestedRecordingEnd = true;
|
m_RequestedRecordingEnd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FifoDataFile* FifoRecorder::GetRecordedFile() const
|
||||||
|
{
|
||||||
|
return m_File.get();
|
||||||
|
}
|
||||||
|
|
||||||
void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
|
void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
|
||||||
{
|
{
|
||||||
if (!m_SkipNextData)
|
if (!m_SkipNextData)
|
||||||
|
@ -95,7 +92,7 @@ void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
|
||||||
m_CurrentFrame.fifoData = m_FifoData;
|
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
|
// Copy frame to file
|
||||||
// The file will be responsible for freeing the memory allocated for each frame's fifoData
|
// 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)
|
void FifoRecorder::EndFrame(u32 fifoStart, u32 fifoEnd)
|
||||||
{
|
{
|
||||||
// m_IsRecording is assumed to be true at this point, otherwise this function would not be called
|
// 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;
|
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,
|
void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32* xfMem,
|
||||||
const u32* xfRegs, u32 xfRegsSize, const u8* texMem)
|
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)
|
if (m_File)
|
||||||
{
|
{
|
||||||
|
@ -213,6 +210,11 @@ void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32*
|
||||||
FifoRecordAnalyzer::Initialize(cpMem);
|
FifoRecordAnalyzer::Initialize(cpMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FifoRecorder::IsRecording() const
|
||||||
|
{
|
||||||
|
return m_IsRecording;
|
||||||
|
}
|
||||||
|
|
||||||
FifoRecorder& FifoRecorder::GetInstance()
|
FifoRecorder& FifoRecorder::GetInstance()
|
||||||
{
|
{
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||||
|
@ -14,12 +16,11 @@ public:
|
||||||
typedef void (*CallbackFunc)(void);
|
typedef void (*CallbackFunc)(void);
|
||||||
|
|
||||||
FifoRecorder();
|
FifoRecorder();
|
||||||
~FifoRecorder();
|
|
||||||
|
|
||||||
void StartRecording(s32 numFrames, CallbackFunc finishedCb);
|
void StartRecording(s32 numFrames, CallbackFunc finishedCb);
|
||||||
void StopRecording();
|
void StopRecording();
|
||||||
|
|
||||||
FifoDataFile* GetRecordedFile() const { return m_File; }
|
FifoDataFile* GetRecordedFile() const;
|
||||||
// Called from video thread
|
// Called from video thread
|
||||||
|
|
||||||
// Must write one full GP command at a time
|
// Must write one full GP command at a time
|
||||||
|
@ -40,21 +41,21 @@ public:
|
||||||
u32 xfRegsSize, const u8* texMem);
|
u32 xfRegsSize, const u8* texMem);
|
||||||
|
|
||||||
// Checked once per frame prior to callng EndFrame()
|
// Checked once per frame prior to callng EndFrame()
|
||||||
bool IsRecording() const { return m_IsRecording; }
|
bool IsRecording() const;
|
||||||
static FifoRecorder& GetInstance();
|
static FifoRecorder& GetInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Accessed from both GUI and video threads
|
// Accessed from both GUI and video threads
|
||||||
|
|
||||||
|
std::recursive_mutex m_mutex;
|
||||||
// True if video thread should send data
|
// 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
|
// True if m_IsRecording was true during last frame
|
||||||
volatile bool m_WasRecording = false;
|
bool m_WasRecording = false;
|
||||||
volatile bool m_RequestedRecordingEnd = false;
|
bool m_RequestedRecordingEnd = false;
|
||||||
volatile s32 m_RecordFramesRemaining = 0;
|
s32 m_RecordFramesRemaining = 0;
|
||||||
volatile CallbackFunc m_FinishedCb = nullptr;
|
CallbackFunc m_FinishedCb = nullptr;
|
||||||
|
std::unique_ptr<FifoDataFile> m_File;
|
||||||
FifoDataFile* volatile m_File = nullptr;
|
|
||||||
|
|
||||||
// Accessed only from video thread
|
// Accessed only from video thread
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue