mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-08 16:05:56 +00:00
Partial commit: Cell
This commit is contained in:
parent
42e1d4d752
commit
c4e99dbdb2
32 changed files with 10685 additions and 12527 deletions
99
rpcs3/Emu/Cell/PPUCallback.cpp
Normal file
99
rpcs3/Emu/Cell/PPUCallback.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include "stdafx.h"
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/IdManager.h"
|
||||
|
||||
#include "PPUThread.h"
|
||||
#include "PPUCallback.h"
|
||||
|
||||
void CallbackManager::Register(check_cb_t func)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
m_check_cb.emplace(std::move(func));
|
||||
}
|
||||
|
||||
void CallbackManager::Async(async_cb_t func)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (!m_cb_thread)
|
||||
{
|
||||
throw EXCEPTION("Callback thread not found");
|
||||
}
|
||||
|
||||
m_async_cb.emplace(std::move(func));
|
||||
|
||||
m_cb_thread->cv.notify_one();
|
||||
}
|
||||
|
||||
CallbackManager::check_cb_t CallbackManager::Check()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (m_check_cb.size())
|
||||
{
|
||||
check_cb_t func = std::move(m_check_cb.front());
|
||||
|
||||
m_check_cb.pop();
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CallbackManager::Init()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
auto task = [this](PPUThread& ppu)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
while (true)
|
||||
{
|
||||
CHECK_EMU_STATUS;
|
||||
|
||||
if (!lock)
|
||||
{
|
||||
lock.lock();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_async_cb.size())
|
||||
{
|
||||
async_cb_t func = std::move(m_async_cb.front());
|
||||
|
||||
m_async_cb.pop();
|
||||
|
||||
if (lock) lock.unlock();
|
||||
|
||||
func(ppu);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ppu.cv.wait(lock);
|
||||
}
|
||||
};
|
||||
|
||||
auto thread = idm::make_ptr<PPUThread>("Callback Thread");
|
||||
|
||||
thread->prio = 1001;
|
||||
thread->stack_size = 0x10000;
|
||||
thread->custom_task = task;
|
||||
thread->cpu_init();
|
||||
|
||||
m_cb_thread = thread;
|
||||
}
|
||||
|
||||
void CallbackManager::Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
m_check_cb = decltype(m_check_cb){};
|
||||
m_async_cb = decltype(m_async_cb){};
|
||||
|
||||
m_cb_thread.reset();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue