mirror of
https://github.com/citra-emu/citra-nightly.git
synced 2024-12-25 08:25:38 +00:00
Kernel: pass ref down to Object and wrap ID counter into kernel state
This commit is contained in:
parent
87426b29ff
commit
751ebe55e9
|
@ -65,7 +65,7 @@ SharedPtr<Thread> AddressArbiter::ResumeHighestPriorityThread(VAddr address) {
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressArbiter::AddressArbiter(KernelSystem& kernel) {}
|
AddressArbiter::AddressArbiter(KernelSystem& kernel) : Object(kernel) {}
|
||||||
AddressArbiter::~AddressArbiter() {}
|
AddressArbiter::~AddressArbiter() {}
|
||||||
|
|
||||||
SharedPtr<AddressArbiter> KernelSystem::CreateAddressArbiter(std::string name) {
|
SharedPtr<AddressArbiter> KernelSystem::CreateAddressArbiter(std::string name) {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ClientPort::ClientPort(KernelSystem& kernel) : kernel(kernel) {}
|
ClientPort::ClientPort(KernelSystem& kernel) : kernel(kernel), Object(kernel) {}
|
||||||
ClientPort::~ClientPort() = default;
|
ClientPort::~ClientPort() = default;
|
||||||
|
|
||||||
ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
|
ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ClientSession::ClientSession(KernelSystem& kernel) {}
|
ClientSession::ClientSession(KernelSystem& kernel) : Object(kernel) {}
|
||||||
ClientSession::~ClientSession() {
|
ClientSession::~ClientSession() {
|
||||||
// This destructor will be called automatically when the last ClientSession handle is closed by
|
// This destructor will be called automatically when the last ClientSession handle is closed by
|
||||||
// the emulated application.
|
// the emulated application.
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
Event::Event(KernelSystem& kernel) {}
|
Event::Event(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
Event::~Event() {}
|
Event::~Event() {}
|
||||||
|
|
||||||
SharedPtr<Event> KernelSystem::CreateEvent(ResetType reset_type, std::string name) {
|
SharedPtr<Event> KernelSystem::CreateEvent(ResetType reset_type, std::string name) {
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
std::atomic<u32> Object::next_object_id{0};
|
|
||||||
|
|
||||||
/// Initialize the kernel
|
/// Initialize the kernel
|
||||||
KernelSystem::KernelSystem(u32 system_mode) {
|
KernelSystem::KernelSystem(u32 system_mode) {
|
||||||
ConfigMem::Init();
|
ConfigMem::Init();
|
||||||
|
@ -25,8 +23,6 @@ KernelSystem::KernelSystem(u32 system_mode) {
|
||||||
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
||||||
Kernel::ThreadingInit();
|
Kernel::ThreadingInit();
|
||||||
Kernel::TimersInit();
|
Kernel::TimersInit();
|
||||||
|
|
||||||
Object::next_object_id = 0;
|
|
||||||
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
|
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
|
||||||
// reserved for low-level services
|
// reserved for low-level services
|
||||||
Process::next_process_id = 10;
|
Process::next_process_id = 10;
|
||||||
|
@ -51,4 +47,8 @@ const ResourceLimitList& KernelSystem::ResourceLimit() const {
|
||||||
return *resource_limits;
|
return *resource_limits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 KernelSystem::GenerateObjectID() {
|
||||||
|
return next_object_id++;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
||||||
|
@ -177,8 +178,11 @@ public:
|
||||||
MemoryPermission other_permissions,
|
MemoryPermission other_permissions,
|
||||||
std::string name = "Unknown Applet");
|
std::string name = "Unknown Applet");
|
||||||
|
|
||||||
|
u32 GenerateObjectID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ResourceLimitList> resource_limits;
|
std::unique_ptr<ResourceLimitList> resource_limits;
|
||||||
|
std::atomic<u32> next_object_id{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -24,7 +24,7 @@ void ReleaseThreadMutexes(Thread* thread) {
|
||||||
thread->held_mutexes.clear();
|
thread->held_mutexes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::Mutex(KernelSystem& kernel) {}
|
Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
Mutex::~Mutex() {}
|
Mutex::~Mutex() {}
|
||||||
|
|
||||||
SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {
|
SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/kernel/object.h"
|
#include "core/hle/kernel/object.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
Object::Object(KernelSystem& kernel) : object_id{kernel.GenerateObjectID()} {}
|
||||||
|
|
||||||
Object::~Object() = default;
|
Object::~Object() = default;
|
||||||
|
|
||||||
bool Object::IsWaitable() const {
|
bool Object::IsWaitable() const {
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelSystem;
|
||||||
|
|
||||||
using Handle = u32;
|
using Handle = u32;
|
||||||
|
|
||||||
enum class HandleType : u32 {
|
enum class HandleType : u32 {
|
||||||
|
@ -37,6 +39,7 @@ enum {
|
||||||
|
|
||||||
class Object : NonCopyable {
|
class Object : NonCopyable {
|
||||||
public:
|
public:
|
||||||
|
explicit Object(KernelSystem& kernel);
|
||||||
virtual ~Object();
|
virtual ~Object();
|
||||||
|
|
||||||
/// Returns a unique identifier for the object. For debugging purposes only.
|
/// Returns a unique identifier for the object. For debugging purposes only.
|
||||||
|
@ -58,15 +61,12 @@ public:
|
||||||
*/
|
*/
|
||||||
bool IsWaitable() const;
|
bool IsWaitable() const;
|
||||||
|
|
||||||
public:
|
|
||||||
static std::atomic<u32> next_object_id;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend void intrusive_ptr_add_ref(Object*);
|
friend void intrusive_ptr_add_ref(Object*);
|
||||||
friend void intrusive_ptr_release(Object*);
|
friend void intrusive_ptr_release(Object*);
|
||||||
|
|
||||||
std::atomic<u32> ref_count{0};
|
std::atomic<u32> ref_count{0};
|
||||||
std::atomic<u32> object_id{next_object_id++};
|
std::atomic<u32> object_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special functions used by boost::instrusive_ptr to do automatic ref-counting
|
// Special functions used by boost::instrusive_ptr to do automatic ref-counting
|
||||||
|
|
|
@ -29,7 +29,7 @@ SharedPtr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 program_id)
|
||||||
return codeset;
|
return codeset;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeSet::CodeSet(KernelSystem& system) {}
|
CodeSet::CodeSet(KernelSystem& kernel) : Object(kernel) {}
|
||||||
CodeSet::~CodeSet() {}
|
CodeSet::~CodeSet() {}
|
||||||
|
|
||||||
u32 Process::next_process_id;
|
u32 Process::next_process_id;
|
||||||
|
@ -304,7 +304,7 @@ ResultCode Process::LinearFree(VAddr target, u32 size) {
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::Process::Process(KernelSystem& kernel) : kernel(kernel) {}
|
Kernel::Process::Process(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
|
||||||
Kernel::Process::~Process() {}
|
Kernel::Process::~Process() {}
|
||||||
|
|
||||||
void ClearProcessList() {
|
void ClearProcessList() {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ResourceLimit::ResourceLimit(KernelSystem& kernel) {}
|
ResourceLimit::ResourceLimit(KernelSystem& kernel) : Object(kernel) {}
|
||||||
ResourceLimit::~ResourceLimit() {}
|
ResourceLimit::~ResourceLimit() {}
|
||||||
|
|
||||||
SharedPtr<ResourceLimit> ResourceLimit::Create(KernelSystem& kernel, std::string name) {
|
SharedPtr<ResourceLimit> ResourceLimit::Create(KernelSystem& kernel, std::string name) {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
Semaphore::Semaphore(KernelSystem& kernel) {}
|
Semaphore::Semaphore(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
Semaphore::~Semaphore() {}
|
Semaphore::~Semaphore() {}
|
||||||
|
|
||||||
ResultVal<SharedPtr<Semaphore>> KernelSystem::CreateSemaphore(s32 initial_count, s32 max_count,
|
ResultVal<SharedPtr<Semaphore>> KernelSystem::CreateSemaphore(s32 initial_count, s32 max_count,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ServerPort::ServerPort(KernelSystem& kernel) {}
|
ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
ServerPort::~ServerPort() {}
|
ServerPort::~ServerPort() {}
|
||||||
|
|
||||||
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ServerSession::ServerSession(KernelSystem& kernel) {}
|
ServerSession::ServerSession(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
ServerSession::~ServerSession() {
|
ServerSession::~ServerSession() {
|
||||||
// This destructor will be called automatically when the last ServerSession handle is closed by
|
// This destructor will be called automatically when the last ServerSession handle is closed by
|
||||||
// the emulated application.
|
// the emulated application.
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
SharedMemory::SharedMemory(KernelSystem& system) {}
|
SharedMemory::SharedMemory(KernelSystem& kernel) : Object(kernel) {}
|
||||||
SharedMemory::~SharedMemory() {}
|
SharedMemory::~SharedMemory() {}
|
||||||
|
|
||||||
SharedPtr<SharedMemory> KernelSystem::CreateSharedMemory(SharedPtr<Process> owner_process, u32 size,
|
SharedPtr<SharedMemory> KernelSystem::CreateSharedMemory(SharedPtr<Process> owner_process, u32 size,
|
||||||
|
|
|
@ -60,7 +60,7 @@ inline static u32 const NewThreadId() {
|
||||||
return next_thread_id++;
|
return next_thread_id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::Thread(KernelSystem&) : context(Core::CPU().NewContext()) {}
|
Thread::Thread(KernelSystem& kernel) : WaitObject(kernel), context(Core::CPU().NewContext()) {}
|
||||||
Thread::~Thread() {}
|
Thread::~Thread() {}
|
||||||
|
|
||||||
Thread* GetCurrentThread() {
|
Thread* GetCurrentThread() {
|
||||||
|
|
|
@ -19,7 +19,7 @@ static CoreTiming::EventType* timer_callback_event_type = nullptr;
|
||||||
// us to simply use a pool index or similar.
|
// us to simply use a pool index or similar.
|
||||||
static Kernel::HandleTable timer_callback_handle_table;
|
static Kernel::HandleTable timer_callback_handle_table;
|
||||||
|
|
||||||
Timer::Timer(KernelSystem& kernel) {}
|
Timer::Timer(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
Timer::~Timer() {}
|
Timer::~Timer() {}
|
||||||
|
|
||||||
SharedPtr<Timer> KernelSystem::CreateTimer(ResetType reset_type, std::string name) {
|
SharedPtr<Timer> KernelSystem::CreateTimer(ResetType reset_type, std::string name) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ class Thread;
|
||||||
/// Class that represents a Kernel object that a thread can be waiting on
|
/// Class that represents a Kernel object that a thread can be waiting on
|
||||||
class WaitObject : public Object {
|
class WaitObject : public Object {
|
||||||
public:
|
public:
|
||||||
|
using Object::Object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the specified thread should wait until the object is available
|
* Check if the specified thread should wait until the object is available
|
||||||
* @param thread The thread about which we're deciding.
|
* @param thread The thread about which we're deciding.
|
||||||
|
|
Loading…
Reference in a new issue