mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-23 21:35:44 +01:00
Kernel: Stop creating useless Handles during object creation
They're finally unnecessary, and will stop cluttering the application's handle table.
This commit is contained in:
parent
52f58e64ef
commit
88a4a808c6
@ -18,14 +18,12 @@ namespace Kernel {
|
||||
AddressArbiter::AddressArbiter() {}
|
||||
AddressArbiter::~AddressArbiter() {}
|
||||
|
||||
ResultVal<SharedPtr<AddressArbiter>> AddressArbiter::Create(std::string name) {
|
||||
SharedPtr<AddressArbiter> AddressArbiter::Create(std::string name) {
|
||||
SharedPtr<AddressArbiter> address_arbiter(new AddressArbiter);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(address_arbiter));
|
||||
|
||||
address_arbiter->name = std::move(name);
|
||||
|
||||
return MakeResult<SharedPtr<AddressArbiter>>(std::move(address_arbiter));
|
||||
return address_arbiter;
|
||||
}
|
||||
|
||||
ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, s32 value,
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
* @param name Optional name used for debugging.
|
||||
* @returns The created AddressArbiter.
|
||||
*/
|
||||
static ResultVal<SharedPtr<AddressArbiter>> Create(std::string name = "Unknown");
|
||||
static SharedPtr<AddressArbiter> Create(std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override { return "Arbiter"; }
|
||||
std::string GetName() const override { return name; }
|
||||
|
@ -17,16 +17,14 @@ namespace Kernel {
|
||||
Event::Event() {}
|
||||
Event::~Event() {}
|
||||
|
||||
ResultVal<SharedPtr<Event>> Event::Create(ResetType reset_type, std::string name) {
|
||||
SharedPtr<Event> Event::Create(ResetType reset_type, std::string name) {
|
||||
SharedPtr<Event> evt(new Event);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(evt));
|
||||
|
||||
evt->signaled = false;
|
||||
evt->reset_type = evt->intitial_reset_type = reset_type;
|
||||
evt->name = std::move(name);
|
||||
|
||||
return MakeResult<SharedPtr<Event>>(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
bool Event::ShouldWait() {
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
* @param reset_type ResetType describing how to create event
|
||||
* @param name Optional name of event
|
||||
*/
|
||||
static ResultVal<SharedPtr<Event>> Create(ResetType reset_type, std::string name = "Unknown");
|
||||
static SharedPtr<Event> Create(ResetType reset_type, std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override { return "Event"; }
|
||||
std::string GetName() const override { return name; }
|
||||
|
@ -41,10 +41,8 @@ void ReleaseThreadMutexes(Thread* thread) {
|
||||
Mutex::Mutex() {}
|
||||
Mutex::~Mutex() {}
|
||||
|
||||
ResultVal<SharedPtr<Mutex>> Mutex::Create(bool initial_locked, std::string name) {
|
||||
SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) {
|
||||
SharedPtr<Mutex> mutex(new Mutex);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(mutex));
|
||||
|
||||
mutex->initial_locked = initial_locked;
|
||||
mutex->locked = false;
|
||||
@ -55,7 +53,7 @@ ResultVal<SharedPtr<Mutex>> Mutex::Create(bool initial_locked, std::string name)
|
||||
if (initial_locked)
|
||||
mutex->Acquire();
|
||||
|
||||
return MakeResult<SharedPtr<Mutex>>(mutex);
|
||||
return mutex;
|
||||
}
|
||||
|
||||
bool Mutex::ShouldWait() {
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
* @param name Optional name of mutex
|
||||
* @return Pointer to new Mutex object
|
||||
*/
|
||||
static ResultVal<SharedPtr<Mutex>> Create(bool initial_locked, std::string name = "Unknown");
|
||||
static SharedPtr<Mutex> Create(bool initial_locked, std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override { return "Mutex"; }
|
||||
std::string GetName() const override { return name; }
|
||||
|
@ -21,8 +21,6 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_cou
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||
|
||||
SharedPtr<Semaphore> semaphore(new Semaphore);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(semaphore));
|
||||
|
||||
// When the semaphore is created, some slots are reserved for other threads,
|
||||
// and the rest is reserved for the caller thread
|
||||
|
@ -12,14 +12,12 @@ namespace Kernel {
|
||||
SharedMemory::SharedMemory() {}
|
||||
SharedMemory::~SharedMemory() {}
|
||||
|
||||
ResultVal<SharedPtr<SharedMemory>> SharedMemory::Create(std::string name) {
|
||||
SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
|
||||
SharedPtr<SharedMemory> shared_memory(new SharedMemory);
|
||||
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(shared_memory));
|
||||
|
||||
shared_memory->name = std::move(name);
|
||||
return MakeResult<SharedPtr<SharedMemory>>(std::move(shared_memory));
|
||||
|
||||
return shared_memory;
|
||||
}
|
||||
|
||||
ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
* Creates a shared memory object
|
||||
* @param name Optional object name, used only for debugging purposes.
|
||||
*/
|
||||
static ResultVal<SharedPtr<SharedMemory>> Create(std::string name = "Unknown");
|
||||
static SharedPtr<SharedMemory> Create(std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override { return "SharedMemory"; }
|
||||
|
||||
|
@ -368,14 +368,6 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
|
||||
|
||||
SharedPtr<Thread> thread(new Thread);
|
||||
|
||||
// TODO(yuriks): Thread requires a handle to be inserted into the various scheduling queues for
|
||||
// the time being. Create a handle here, it will be copied to the handle field in
|
||||
// the object and use by the rest of the code. This should be removed when other
|
||||
// code doesn't rely on the handle anymore.
|
||||
ResultVal<Handle> handle = Kernel::g_handle_table.Create(thread);
|
||||
if (handle.Failed())
|
||||
return handle.Code();
|
||||
|
||||
thread_list.push_back(thread);
|
||||
thread_ready_queue.prepare(priority);
|
||||
|
||||
|
@ -20,10 +20,8 @@ static Kernel::HandleTable timer_callback_handle_table;
|
||||
Timer::Timer() {}
|
||||
Timer::~Timer() {}
|
||||
|
||||
ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name) {
|
||||
SharedPtr<Timer> Timer::Create(ResetType reset_type, std::string name) {
|
||||
SharedPtr<Timer> timer(new Timer);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(timer));
|
||||
|
||||
timer->reset_type = reset_type;
|
||||
timer->signaled = false;
|
||||
@ -31,7 +29,8 @@ ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name
|
||||
timer->initial_delay = 0;
|
||||
timer->interval_delay = 0;
|
||||
timer->callback_handle = timer_callback_handle_table.Create(timer).MoveFrom();
|
||||
return MakeResult<SharedPtr<Timer>>(timer);
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
bool Timer::ShouldWait() {
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
* @param name Optional name of timer
|
||||
* @return The created Timer
|
||||
*/
|
||||
static ResultVal<SharedPtr<Timer>> Create(ResetType reset_type, std::string name = "Unknown");
|
||||
static SharedPtr<Timer> Create(ResetType reset_type, std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override { return "Timer"; }
|
||||
std::string GetName() const override { return name; }
|
||||
|
@ -69,8 +69,8 @@ void Initialize(Service::Interface* self) {
|
||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||
|
||||
// TODO(bunnei): Check if these are created in Initialize or on APT process startup.
|
||||
notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification").MoveFrom();
|
||||
pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause").MoveFrom();
|
||||
notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification");
|
||||
pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause");
|
||||
|
||||
cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom();
|
||||
cmd_buff[4] = Kernel::g_handle_table.Create(pause_event).MoveFrom();
|
||||
@ -512,13 +512,13 @@ Interface::Interface() {
|
||||
file.ReadBytes(shared_font.data(), (size_t)file.GetSize());
|
||||
|
||||
// Create shared font memory object
|
||||
shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem").MoveFrom();
|
||||
shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem");
|
||||
} else {
|
||||
LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str());
|
||||
shared_font_mem = nullptr;
|
||||
}
|
||||
|
||||
lock = Kernel::Mutex::Create(false, "APT_U:Lock").MoveFrom();
|
||||
lock = Kernel::Mutex::Create(false, "APT_U:Lock");
|
||||
|
||||
Register(FunctionTable);
|
||||
}
|
||||
|
@ -201,8 +201,7 @@ const Interface::FunctionInfo FunctionTable[] = {
|
||||
// Interface class
|
||||
|
||||
Interface::Interface() {
|
||||
semaphore_event = Kernel::Event::Create(RESETTYPE_ONESHOT,
|
||||
"DSP_DSP::semaphore_event").MoveFrom();
|
||||
semaphore_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "DSP_DSP::semaphore_event");
|
||||
interrupt_event = nullptr;
|
||||
read_pipe_count = 0;
|
||||
|
||||
|
@ -187,7 +187,7 @@ static void RegisterInterruptRelayQueue(Service::Interface* self) {
|
||||
|
||||
g_interrupt_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[3]);
|
||||
_assert_msg_(GSP, (g_interrupt_event != nullptr), "handle is not valid!");
|
||||
g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem").MoveFrom();
|
||||
g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem");
|
||||
|
||||
Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom();
|
||||
|
||||
|
@ -124,14 +124,14 @@ void PadUpdateComplete() {
|
||||
void HIDInit() {
|
||||
using namespace Kernel;
|
||||
|
||||
g_shared_mem = SharedMemory::Create("HID:SharedMem").MoveFrom();
|
||||
g_shared_mem = SharedMemory::Create("HID:SharedMem");
|
||||
|
||||
// Create event handles
|
||||
g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1").MoveFrom();
|
||||
g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2").MoveFrom();
|
||||
g_event_accelerometer = Event::Create(RESETTYPE_ONESHOT, "HID:EventAccelerometer").MoveFrom();
|
||||
g_event_gyroscope = Event::Create(RESETTYPE_ONESHOT, "HID:EventGyroscope").MoveFrom();
|
||||
g_event_debug_pad = Event::Create(RESETTYPE_ONESHOT, "HID:EventDebugPad").MoveFrom();
|
||||
g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1");
|
||||
g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2");
|
||||
g_event_accelerometer = Event::Create(RESETTYPE_ONESHOT, "HID:EventAccelerometer");
|
||||
g_event_gyroscope = Event::Create(RESETTYPE_ONESHOT, "HID:EventGyroscope");
|
||||
g_event_debug_pad = Event::Create(RESETTYPE_ONESHOT, "HID:EventDebugPad");
|
||||
}
|
||||
|
||||
void HIDShutdown() {
|
||||
|
@ -23,7 +23,7 @@ static void GetProcSemaphore(Service::Interface* self) {
|
||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||
|
||||
// TODO(bunnei): Change to a semaphore once these have been implemented
|
||||
event_handle = Kernel::Event::Create(RESETTYPE_ONESHOT, "SRV:Event").MoveFrom();
|
||||
event_handle = Kernel::Event::Create(RESETTYPE_ONESHOT, "SRV:Event");
|
||||
event_handle->Clear();
|
||||
|
||||
cmd_buff[1] = 0; // No error
|
||||
|
@ -261,7 +261,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou
|
||||
static ResultCode CreateAddressArbiter(Handle* out_handle) {
|
||||
using Kernel::AddressArbiter;
|
||||
|
||||
CASCADE_RESULT(SharedPtr<AddressArbiter> arbiter, AddressArbiter::Create());
|
||||
SharedPtr<AddressArbiter> arbiter = AddressArbiter::Create();
|
||||
CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(arbiter)));
|
||||
LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *out_handle);
|
||||
return RESULT_SUCCESS;
|
||||
@ -366,7 +366,7 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) {
|
||||
static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) {
|
||||
using Kernel::Mutex;
|
||||
|
||||
CASCADE_RESULT(SharedPtr<Mutex> mutex, Mutex::Create(initial_locked != 0));
|
||||
SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0);
|
||||
CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex)));
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X",
|
||||
@ -434,7 +434,9 @@ static ResultCode QueryMemory(void* info, void* out, u32 addr) {
|
||||
|
||||
/// Create an event
|
||||
static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) {
|
||||
CASCADE_RESULT(auto evt, Kernel::Event::Create(static_cast<ResetType>(reset_type)));
|
||||
using Kernel::Event;
|
||||
|
||||
SharedPtr<Event> evt = Kernel::Event::Create(static_cast<ResetType>(reset_type));
|
||||
CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt)));
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
|
||||
@ -451,9 +453,10 @@ static ResultCode DuplicateHandle(Handle* out, Handle handle) {
|
||||
|
||||
/// Signals an event
|
||||
static ResultCode SignalEvent(Handle handle) {
|
||||
using Kernel::Event;
|
||||
LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
|
||||
|
||||
auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
|
||||
SharedPtr<Event> evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
|
||||
if (evt == nullptr)
|
||||
return ERR_INVALID_HANDLE;
|
||||
|
||||
@ -464,9 +467,10 @@ static ResultCode SignalEvent(Handle handle) {
|
||||
|
||||
/// Clears an event
|
||||
static ResultCode ClearEvent(Handle handle) {
|
||||
using Kernel::Event;
|
||||
LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
|
||||
|
||||
auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
|
||||
SharedPtr<Event> evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
|
||||
if (evt == nullptr)
|
||||
return ERR_INVALID_HANDLE;
|
||||
|
||||
@ -478,7 +482,7 @@ static ResultCode ClearEvent(Handle handle) {
|
||||
static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) {
|
||||
using Kernel::Timer;
|
||||
|
||||
CASCADE_RESULT(auto timer, Timer::Create(static_cast<ResetType>(reset_type)));
|
||||
SharedPtr<Timer> timer = Timer::Create(static_cast<ResetType>(reset_type));
|
||||
CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer)));
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
|
||||
@ -552,7 +556,7 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32
|
||||
using Kernel::SharedMemory;
|
||||
// TODO(Subv): Implement this function
|
||||
|
||||
CASCADE_RESULT(auto shared_memory, SharedMemory::Create());
|
||||
SharedPtr<SharedMemory> shared_memory = SharedMemory::Create();
|
||||
CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory)));
|
||||
|
||||
LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);
|
||||
|
Loading…
Reference in New Issue
Block a user