1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Rewrite RSP_ThreadProc.

This commit is contained in:
Sergey Lipskiy 2015-11-23 19:42:34 +06:00
parent b9ee15bfb6
commit 6bc16d0492
2 changed files with 103 additions and 47 deletions

View File

@ -12,13 +12,7 @@
#endif
#include "FrameBufferInfoAPI.h"
enum API_COMMAND {
acNone = 0,
acProcessDList,
acProcessRDPList,
acUpdateScreen,
acRomClosed
};
class APICommand;
class PluginAPI
{
@ -92,7 +86,7 @@ public:
private:
PluginAPI()
#ifdef RSPTHREAD
: m_pRspThread(NULL), m_command(acNone)
: m_pRspThread(NULL), m_pCommand(nullptr)
#endif
{}
PluginAPI(const PluginAPI &);
@ -100,13 +94,13 @@ private:
void _initiateGFX(const GFX_INFO & _gfxInfo) const;
#ifdef RSPTHREAD
void _callAPICommand(API_COMMAND _command);
void _callAPICommand(APICommand & _command);
std::mutex m_rspThreadMtx;
std::mutex m_pluginThreadMtx;
std::condition_variable_any m_rspThreadCv;
std::condition_variable_any m_pluginThreadCv;
std::thread * m_pRspThread;
API_COMMAND m_command;
APICommand * m_pCommand;
#endif
};

View File

@ -25,7 +25,12 @@ PluginAPI & PluginAPI::get()
}
#ifdef RSPTHREAD
void RSP_ThreadProc(std::mutex * _pRspThreadMtx, std::mutex * _pPluginThreadMtx, std::condition_variable_any * _pRspThreadCv, std::condition_variable_any * _pPluginThreadCv, API_COMMAND * _pCommand)
class APICommand {
public:
virtual bool run() = 0;
};
void RSP_ThreadProc(std::mutex * _pRspThreadMtx, std::mutex * _pPluginThreadMtx, std::condition_variable_any * _pRspThreadCv, std::condition_variable_any * _pPluginThreadCv, APICommand ** _pCommand)
{
_pRspThreadMtx->lock();
RSP_Init();
@ -39,49 +44,97 @@ void RSP_ThreadProc(std::mutex * _pRspThreadMtx, std::mutex * _pPluginThreadMtx,
_pPluginThreadCv->notify_one();
_pPluginThreadMtx->unlock();
_pRspThreadCv->wait(*_pRspThreadMtx);
switch (*_pCommand) {
case acProcessDList:
RSP_ProcessDList();
break;
case acProcessRDPList:
RDP_ProcessRDPList();
break;
case acUpdateScreen:
VI_UpdateScreen();
break;
case acRomClosed:
TFH.shutdown();
video().stop();
GBI.destroy();
*_pCommand = acNone;
_pRspThreadMtx->unlock();
_pPluginThreadMtx->lock();
_pPluginThreadCv->notify_one();
_pPluginThreadMtx->unlock();
if (*_pCommand != nullptr && !(*_pCommand)->run())
return;
}
assert(!isGLError());
*_pCommand = acNone;
}
}
void PluginAPI::_callAPICommand(API_COMMAND _command)
void PluginAPI::_callAPICommand(APICommand & _command)
{
m_command = _command;
m_pCommand = &_command;
m_pluginThreadMtx.lock();
m_rspThreadMtx.lock();
m_rspThreadCv.notify_one();
m_rspThreadMtx.unlock();
m_pluginThreadCv.wait(m_pluginThreadMtx);
m_pluginThreadMtx.unlock();
m_pCommand = nullptr;
}
class ProcessDListCommand : public APICommand {
public:
bool run() {
RSP_ProcessDList();
return true;
}
};
class ProcessRDPListCommand : public APICommand {
public:
bool run() {
RDP_ProcessRDPList();
return true;
}
};
class ProcessUpdateScreenCommand : public APICommand {
public:
bool run() {
VI_UpdateScreen();
return true;
}
};
class FBReadCommand : public APICommand {
public:
FBReadCommand(u32 _addr) : m_addr(_addr) {
}
bool run() {
FrameBufferRead(m_addr);
return true;
}
private:
u32 m_addr;
};
class RomClosedCommand : public APICommand {
public:
RomClosedCommand(std::mutex * _pRspThreadMtx,
std::mutex * _pPluginThreadMtx,
std::condition_variable_any * _pRspThreadCv,
std::condition_variable_any * _pPluginThreadCv)
: m_pRspThreadMtx(_pRspThreadMtx)
, m_pPluginThreadMtx(_pPluginThreadMtx)
, m_pRspThreadCv(_pRspThreadCv)
, m_pPluginThreadCv(_pPluginThreadCv) {
}
bool run() {
TFH.shutdown();
video().stop();
GBI.destroy();
m_pRspThreadMtx->unlock();
m_pPluginThreadMtx->lock();
m_pPluginThreadCv->notify_one();
m_pPluginThreadMtx->unlock();
return false;
}
private:
std::mutex * m_pRspThreadMtx;
std::mutex * m_pPluginThreadMtx;
std::condition_variable_any * m_pRspThreadCv;
std::condition_variable_any * m_pPluginThreadCv;
};
#endif
void PluginAPI::ProcessDList()
{
LOG(LOG_APIFUNC, "ProcessDList\n");
#ifdef RSPTHREAD
_callAPICommand(acProcessDList);
_callAPICommand(ProcessDListCommand());
#else
RSP_ProcessDList();
#endif
@ -91,7 +144,7 @@ void PluginAPI::ProcessRDPList()
{
LOG(LOG_APIFUNC, "ProcessRDPList\n");
#ifdef RSPTHREAD
_callAPICommand(acProcessRDPList);
_callAPICommand(ProcessRDPListCommand());
#else
RDP_ProcessRDPList();
#endif
@ -101,7 +154,12 @@ void PluginAPI::RomClosed()
{
LOG(LOG_APIFUNC, "RomClosed\n");
#ifdef RSPTHREAD
_callAPICommand(acRomClosed);
_callAPICommand(RomClosedCommand(
&m_rspThreadMtx,
&m_pluginThreadMtx,
&m_rspThreadCv,
&m_pluginThreadCv)
);
delete m_pRspThread;
m_pRspThread = NULL;
#else
@ -120,7 +178,7 @@ void PluginAPI::RomOpen()
LOG(LOG_APIFUNC, "RomOpen\n");
#ifdef RSPTHREAD
m_pluginThreadMtx.lock();
m_pRspThread = new std::thread(RSP_ThreadProc, &m_rspThreadMtx, &m_pluginThreadMtx, &m_rspThreadCv, &m_pluginThreadCv, &m_command);
m_pRspThread = new std::thread(RSP_ThreadProc, &m_rspThreadMtx, &m_pluginThreadMtx, &m_rspThreadCv, &m_pluginThreadCv, &m_pCommand);
m_pRspThread->detach();
m_pluginThreadCv.wait(m_pluginThreadMtx);
m_pluginThreadMtx.unlock();
@ -145,7 +203,7 @@ void PluginAPI::UpdateScreen()
{
LOG(LOG_APIFUNC, "UpdateScreen\n");
#ifdef RSPTHREAD
_callAPICommand(acUpdateScreen);
_callAPICommand(ProcessUpdateScreenCommand());
#else
VI_UpdateScreen();
#endif
@ -190,22 +248,26 @@ void PluginAPI::ChangeWindow()
video().setToggleFullscreen();
}
void PluginAPI::FBWrite(unsigned int addr, unsigned int size)
void PluginAPI::FBWrite(unsigned int _addr, unsigned int _size)
{
FrameBufferWrite(addr, size);
FrameBufferWrite(_addr, _size);
}
void PluginAPI::FBWList(FrameBufferModifyEntry *plist, unsigned int size)
void PluginAPI::FBWList(FrameBufferModifyEntry * _plist, unsigned int _size)
{
FrameBufferWriteList(plist, size);
FrameBufferWriteList(_plist, _size);
}
void PluginAPI::FBRead(unsigned int addr)
void PluginAPI::FBRead(unsigned int _addr)
{
FrameBufferRead(addr);
#ifdef RSPTHREAD
_callAPICommand(FBReadCommand(_addr));
#else
FrameBufferRead(_addr);
#endif
}
void PluginAPI::FBGetFrameBufferInfo(void *pinfo)
void PluginAPI::FBGetFrameBufferInfo(void * _pinfo)
{
FrameBufferGetInfo(pinfo);
FrameBufferGetInfo(_pinfo);
}