mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-14 01:27:00 +00:00
Removed std::enable_shared_from_this
Minor ID manager refactoring
This commit is contained in:
parent
09ae45c566
commit
7ccdea7822
@ -2238,18 +2238,18 @@ std::string named_thread::get_name() const
|
||||
return fmt::format("('%s') Unnamed Thread", typeid(*this).name());
|
||||
}
|
||||
|
||||
void named_thread::start()
|
||||
void named_thread::start_thread(const std::shared_ptr<void>& _this)
|
||||
{
|
||||
// Get shared_ptr instance (will throw if called from the constructor or the object has been created incorrectly)
|
||||
auto&& ptr = shared_from_this();
|
||||
// Ensure it's not called from the constructor and the correct object is passed
|
||||
ENSURES(_this.get() == this);
|
||||
|
||||
// Run thread
|
||||
m_thread = thread_ctrl::spawn(get_name(), [thread = std::move(ptr)]()
|
||||
m_thread = thread_ctrl::spawn(get_name(), [this, _this]()
|
||||
{
|
||||
try
|
||||
{
|
||||
LOG_TRACE(GENERAL, "Thread started");
|
||||
thread->on_task();
|
||||
on_task();
|
||||
LOG_TRACE(GENERAL, "Thread ended");
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@ -2262,6 +2262,6 @@ void named_thread::start()
|
||||
LOG_NOTICE(GENERAL, "Thread aborted");
|
||||
}
|
||||
|
||||
thread->on_exit();
|
||||
on_exit();
|
||||
});
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class named_thread : public std::enable_shared_from_this<named_thread>
|
||||
class named_thread
|
||||
{
|
||||
// Pointer to managed resource (shared with actual thread)
|
||||
std::shared_ptr<thread_ctrl> m_thread;
|
||||
@ -329,8 +329,8 @@ public:
|
||||
virtual std::string get_name() const;
|
||||
|
||||
protected:
|
||||
// Start thread (cannot be called from the constructor: should throw bad_weak_ptr in such case)
|
||||
void start();
|
||||
// Start thread (cannot be called from the constructor: should throw in such case)
|
||||
void start_thread(const std::shared_ptr<void>& _this);
|
||||
|
||||
// Thread task (called in the thread)
|
||||
virtual void on_task() = 0;
|
||||
@ -340,9 +340,9 @@ protected:
|
||||
|
||||
public:
|
||||
// ID initialization
|
||||
virtual void on_init()
|
||||
virtual void on_init(const std::shared_ptr<void>& _this)
|
||||
{
|
||||
start();
|
||||
return start_thread(_this);
|
||||
}
|
||||
|
||||
// ID finalization
|
||||
|
@ -24,7 +24,7 @@ void RawSPUThread::cpu_task()
|
||||
npc = pc | ((ch_event_stat & SPU_EVENT_INTR_ENABLED) != 0);
|
||||
}
|
||||
|
||||
void RawSPUThread::on_init()
|
||||
void RawSPUThread::on_init(const std::shared_ptr<void>& _this)
|
||||
{
|
||||
if (!offset)
|
||||
{
|
||||
@ -33,7 +33,7 @@ void RawSPUThread::on_init()
|
||||
const_cast<u32&>(offset) = vm::falloc(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * index, 0x40000);
|
||||
VERIFY(offset);
|
||||
|
||||
SPUThread::on_init();
|
||||
SPUThread::on_init(_this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
static constexpr u32 id_min = 0;
|
||||
static constexpr u32 id_max = 4;
|
||||
|
||||
void on_init() override;
|
||||
void on_init(const std::shared_ptr<void>&) override;
|
||||
|
||||
RawSPUThread(const std::string& name);
|
||||
|
||||
|
@ -23,7 +23,7 @@ void lv2_cond_t::notify(lv2_lock_t, cpu_thread* thread)
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex->owner = std::static_pointer_cast<cpu_thread>(thread->shared_from_this());
|
||||
mutex->owner = idm::get<PPUThread>(thread->id);
|
||||
|
||||
VERIFY(!thread->state.test_and_set(cpu_state::signal));
|
||||
(*thread)->notify();
|
||||
@ -212,7 +212,7 @@ s32 sys_cond_wait(PPUThread& ppu, u32 cond_id, u64 timeout)
|
||||
// try to reown mutex and exit if timed out
|
||||
if (!cond->mutex->owner)
|
||||
{
|
||||
cond->mutex->owner = std::static_pointer_cast<cpu_thread>(ppu.shared_from_this());
|
||||
cond->mutex->owner = idm::get<PPUThread>(ppu.id);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ void lv2_mutex_t::unlock(lv2_lock_t)
|
||||
if (sq.size())
|
||||
{
|
||||
// pick new owner; protocol is ignored in current implementation
|
||||
owner = std::static_pointer_cast<cpu_thread>(sq.front()->shared_from_this());
|
||||
owner = idm::get<PPUThread>(sq.front()->id);
|
||||
|
||||
VERIFY(!owner->state.test_and_set(cpu_state::signal));
|
||||
(*owner)->notify();
|
||||
@ -127,7 +127,7 @@ s32 sys_mutex_lock(PPUThread& ppu, u32 mutex_id, u64 timeout)
|
||||
// lock immediately if not locked
|
||||
if (!mutex->owner)
|
||||
{
|
||||
mutex->owner = std::static_pointer_cast<cpu_thread>(ppu.shared_from_this());
|
||||
mutex->owner = idm::get<PPUThread>(ppu.id);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
@ -202,7 +202,7 @@ s32 sys_mutex_trylock(PPUThread& ppu, u32 mutex_id)
|
||||
}
|
||||
|
||||
// own the mutex if free
|
||||
mutex->owner = std::static_pointer_cast<cpu_thread>(ppu.shared_from_this());
|
||||
mutex->owner = idm::get<PPUThread>(ppu.id);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ void lv2_rwlock_t::notify_all(lv2_lock_t)
|
||||
// pick a new writer if possible; protocol is ignored in current implementation
|
||||
if (!readers && !writer && wsq.size())
|
||||
{
|
||||
writer = std::static_pointer_cast<cpu_thread>(wsq.front()->shared_from_this());
|
||||
writer = idm::get<PPUThread>(wsq.front()->id);
|
||||
|
||||
VERIFY(!writer->state.test_and_set(cpu_state::signal));
|
||||
(*writer)->notify();
|
||||
@ -221,7 +221,7 @@ s32 sys_rwlock_wlock(PPUThread& ppu, u32 rw_lock_id, u64 timeout)
|
||||
|
||||
if (!rwlock->readers && !rwlock->writer)
|
||||
{
|
||||
rwlock->writer = std::static_pointer_cast<cpu_thread>(ppu.shared_from_this());
|
||||
rwlock->writer = idm::get<PPUThread>(ppu.id);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
@ -293,7 +293,7 @@ s32 sys_rwlock_trywlock(PPUThread& ppu, u32 rw_lock_id)
|
||||
return CELL_EBUSY;
|
||||
}
|
||||
|
||||
rwlock->writer = std::static_pointer_cast<cpu_thread>(ppu.shared_from_this());
|
||||
rwlock->writer = idm::get<PPUThread>(ppu.id);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace id_manager
|
||||
template<typename T, typename = void>
|
||||
struct on_init
|
||||
{
|
||||
static inline void func(T*)
|
||||
static inline void func(T*, const std::shared_ptr<void>&)
|
||||
{
|
||||
// Forbid forward declarations
|
||||
static constexpr auto size = sizeof(std::conditional_t<std::is_void<T>::value, void*, T>);
|
||||
@ -43,11 +43,11 @@ namespace id_manager
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct on_init<T, decltype(std::declval<T>().on_init())>
|
||||
struct on_init<T, decltype(std::declval<T>().on_init(std::declval<const std::shared_ptr<void>&>()))>
|
||||
{
|
||||
static inline void func(T* ptr)
|
||||
static inline void func(T* ptr, const std::shared_ptr<void>&_ptr)
|
||||
{
|
||||
if (ptr) ptr->on_init();
|
||||
if (ptr) ptr->on_init(_ptr);
|
||||
}
|
||||
};
|
||||
|
||||
@ -87,7 +87,6 @@ namespace id_manager
|
||||
static u32 add_type();
|
||||
|
||||
public:
|
||||
void(*on_init)(void*) = nullptr;
|
||||
void(*on_stop)(void*) = nullptr;
|
||||
|
||||
// Get type index
|
||||
@ -101,10 +100,7 @@ namespace id_manager
|
||||
template<typename T>
|
||||
static inline void update()
|
||||
{
|
||||
auto& info = access()[get_index<T>()];
|
||||
|
||||
info.on_init = [](void* ptr) { return_ id_manager::on_init<T>::func(static_cast<T*>(ptr)); };
|
||||
info.on_stop = [](void* ptr) { return_ id_manager::on_stop<T>::func(static_cast<T*>(ptr)); };
|
||||
access()[get_index<T>()].on_stop = [](void* ptr) { return_ id_manager::on_stop<T>::func(static_cast<T*>(ptr)); };
|
||||
}
|
||||
|
||||
// Read all registered types
|
||||
@ -251,7 +247,7 @@ public:
|
||||
{
|
||||
if (auto pair = create_id<T>(WRAP_EXPR(std::make_shared<Make>(std::forward<Args>(args)...))))
|
||||
{
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()));
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()), pair->second);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
return{ pair->second, static_cast<T*>(pair->second.get()) };
|
||||
}
|
||||
@ -265,7 +261,7 @@ public:
|
||||
{
|
||||
if (auto pair = create_id<T>(WRAP_EXPR(std::make_shared<Make>(std::forward<Args>(args)...))))
|
||||
{
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()));
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()), pair->second);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
return pair->first;
|
||||
}
|
||||
@ -279,7 +275,7 @@ public:
|
||||
{
|
||||
if (auto pair = create_id<T>(WRAP_EXPR(ptr)))
|
||||
{
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()));
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()), pair->second);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
return pair->first;
|
||||
}
|
||||
@ -293,7 +289,7 @@ public:
|
||||
{
|
||||
if (auto pair = create_id<T>(std::forward<F>(provider)))
|
||||
{
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()));
|
||||
id_manager::on_init<T>::func(static_cast<T*>(pair->second.get()), pair->second);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
return { pair->second, static_cast<T*>(pair->second.get()) };
|
||||
}
|
||||
@ -477,7 +473,7 @@ public:
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
id_manager::on_init<T>::func(ptr.get());
|
||||
id_manager::on_init<T>::func(ptr.get(), ptr);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
}
|
||||
|
||||
@ -506,7 +502,7 @@ public:
|
||||
id_manager::on_stop<T>::func(static_cast<T*>(old.get()));
|
||||
}
|
||||
|
||||
id_manager::on_init<T>::func(ptr.get());
|
||||
id_manager::on_init<T>::func(ptr.get(), ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -530,7 +526,7 @@ public:
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
id_manager::on_init<T>::func(ptr.get());
|
||||
id_manager::on_init<T>::func(ptr.get(), ptr);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
}
|
||||
|
||||
@ -559,7 +555,7 @@ public:
|
||||
id_manager::on_stop<T>::func(static_cast<T*>(old.get()));
|
||||
}
|
||||
|
||||
id_manager::on_init<T>::func(ptr.get());
|
||||
id_manager::on_init<T>::func(ptr.get(), ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -585,7 +581,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
id_manager::on_init<T>::func(ptr.get());
|
||||
id_manager::on_init<T>::func(ptr.get(), ptr);
|
||||
id_manager::on_stop<T>::func(nullptr);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Utilities/Config.h"
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/IdManager.h"
|
||||
#include "RSXThread.h"
|
||||
|
||||
#include "Emu/Cell/PPUCallback.h"
|
||||
@ -14,6 +15,8 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
class GSRender;
|
||||
|
||||
#define CMD_DEBUG 0
|
||||
|
||||
cfg::bool_entry g_cfg_rsx_write_color_buffers(cfg::root.video, "Write Color Buffers");
|
||||
@ -881,7 +884,7 @@ namespace rsx
|
||||
m_used_gcm_commands.clear();
|
||||
|
||||
on_init_rsx();
|
||||
start();
|
||||
start_thread(fxm::get<GSRender>());
|
||||
}
|
||||
|
||||
GcmTileInfo *thread::find_tile(u32 offset, u32 location)
|
||||
|
@ -274,7 +274,7 @@ namespace rsx
|
||||
public:
|
||||
virtual std::string get_name() const override;
|
||||
|
||||
virtual void on_init() override {} // disable start() (TODO)
|
||||
virtual void on_init(const std::shared_ptr<void>&) override {} // disable start() (TODO)
|
||||
virtual void on_stop() override {} // disable join()
|
||||
|
||||
virtual void begin();
|
||||
|
Loading…
x
Reference in New Issue
Block a user