Kernel: pass ref down to Object and wrap ID counter into kernel state

This commit is contained in:
Weiyi Wang 2018-10-13 17:24:51 -04:00
parent 87426b29ff
commit 751ebe55e9
18 changed files with 31 additions and 22 deletions

View File

@ -65,7 +65,7 @@ SharedPtr<Thread> AddressArbiter::ResumeHighestPriorityThread(VAddr address) {
return thread;
}
AddressArbiter::AddressArbiter(KernelSystem& kernel) {}
AddressArbiter::AddressArbiter(KernelSystem& kernel) : Object(kernel) {}
AddressArbiter::~AddressArbiter() {}
SharedPtr<AddressArbiter> KernelSystem::CreateAddressArbiter(std::string name) {

View File

@ -13,7 +13,7 @@
namespace Kernel {
ClientPort::ClientPort(KernelSystem& kernel) : kernel(kernel) {}
ClientPort::ClientPort(KernelSystem& kernel) : kernel(kernel), Object(kernel) {}
ClientPort::~ClientPort() = default;
ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {

View File

@ -13,7 +13,7 @@
namespace Kernel {
ClientSession::ClientSession(KernelSystem& kernel) {}
ClientSession::ClientSession(KernelSystem& kernel) : Object(kernel) {}
ClientSession::~ClientSession() {
// This destructor will be called automatically when the last ClientSession handle is closed by
// the emulated application.

View File

@ -12,7 +12,7 @@
namespace Kernel {
Event::Event(KernelSystem& kernel) {}
Event::Event(KernelSystem& kernel) : WaitObject(kernel) {}
Event::~Event() {}
SharedPtr<Event> KernelSystem::CreateEvent(ResetType reset_type, std::string name) {

View File

@ -14,8 +14,6 @@
namespace Kernel {
std::atomic<u32> Object::next_object_id{0};
/// Initialize the kernel
KernelSystem::KernelSystem(u32 system_mode) {
ConfigMem::Init();
@ -25,8 +23,6 @@ KernelSystem::KernelSystem(u32 system_mode) {
resource_limits = std::make_unique<ResourceLimitList>(*this);
Kernel::ThreadingInit();
Kernel::TimersInit();
Object::next_object_id = 0;
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
// reserved for low-level services
Process::next_process_id = 10;
@ -51,4 +47,8 @@ const ResourceLimitList& KernelSystem::ResourceLimit() const {
return *resource_limits;
}
u32 KernelSystem::GenerateObjectID() {
return next_object_id++;
}
} // namespace Kernel

View File

@ -4,6 +4,7 @@
#pragma once
#include <atomic>
#include <memory>
#include <string>
#include <boost/smart_ptr/intrusive_ptr.hpp>
@ -177,8 +178,11 @@ public:
MemoryPermission other_permissions,
std::string name = "Unknown Applet");
u32 GenerateObjectID();
private:
std::unique_ptr<ResourceLimitList> resource_limits;
std::atomic<u32> next_object_id{0};
};
} // namespace Kernel

View File

@ -24,7 +24,7 @@ void ReleaseThreadMutexes(Thread* thread) {
thread->held_mutexes.clear();
}
Mutex::Mutex(KernelSystem& kernel) {}
Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel) {}
Mutex::~Mutex() {}
SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {

View File

@ -3,10 +3,13 @@
// Refer to the license.txt file included.
#include "common/assert.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/object.h"
namespace Kernel {
Object::Object(KernelSystem& kernel) : object_id{kernel.GenerateObjectID()} {}
Object::~Object() = default;
bool Object::IsWaitable() const {

View File

@ -11,6 +11,8 @@
namespace Kernel {
class KernelSystem;
using Handle = u32;
enum class HandleType : u32 {
@ -37,6 +39,7 @@ enum {
class Object : NonCopyable {
public:
explicit Object(KernelSystem& kernel);
virtual ~Object();
/// Returns a unique identifier for the object. For debugging purposes only.
@ -58,15 +61,12 @@ public:
*/
bool IsWaitable() const;
public:
static std::atomic<u32> next_object_id;
private:
friend void intrusive_ptr_add_ref(Object*);
friend void intrusive_ptr_release(Object*);
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

View File

@ -29,7 +29,7 @@ SharedPtr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 program_id)
return codeset;
}
CodeSet::CodeSet(KernelSystem& system) {}
CodeSet::CodeSet(KernelSystem& kernel) : Object(kernel) {}
CodeSet::~CodeSet() {}
u32 Process::next_process_id;
@ -304,7 +304,7 @@ ResultCode Process::LinearFree(VAddr target, u32 size) {
return RESULT_SUCCESS;
}
Kernel::Process::Process(KernelSystem& kernel) : kernel(kernel) {}
Kernel::Process::Process(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
Kernel::Process::~Process() {}
void ClearProcessList() {

View File

@ -9,7 +9,7 @@
namespace Kernel {
ResourceLimit::ResourceLimit(KernelSystem& kernel) {}
ResourceLimit::ResourceLimit(KernelSystem& kernel) : Object(kernel) {}
ResourceLimit::~ResourceLimit() {}
SharedPtr<ResourceLimit> ResourceLimit::Create(KernelSystem& kernel, std::string name) {

View File

@ -10,7 +10,7 @@
namespace Kernel {
Semaphore::Semaphore(KernelSystem& kernel) {}
Semaphore::Semaphore(KernelSystem& kernel) : WaitObject(kernel) {}
Semaphore::~Semaphore() {}
ResultVal<SharedPtr<Semaphore>> KernelSystem::CreateSemaphore(s32 initial_count, s32 max_count,

View File

@ -13,7 +13,7 @@
namespace Kernel {
ServerPort::ServerPort(KernelSystem& kernel) {}
ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {}
ServerPort::~ServerPort() {}
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {

View File

@ -13,7 +13,7 @@
namespace Kernel {
ServerSession::ServerSession(KernelSystem& kernel) {}
ServerSession::ServerSession(KernelSystem& kernel) : WaitObject(kernel) {}
ServerSession::~ServerSession() {
// This destructor will be called automatically when the last ServerSession handle is closed by
// the emulated application.

View File

@ -11,7 +11,7 @@
namespace Kernel {
SharedMemory::SharedMemory(KernelSystem& system) {}
SharedMemory::SharedMemory(KernelSystem& kernel) : Object(kernel) {}
SharedMemory::~SharedMemory() {}
SharedPtr<SharedMemory> KernelSystem::CreateSharedMemory(SharedPtr<Process> owner_process, u32 size,

View File

@ -60,7 +60,7 @@ inline static u32 const NewThreadId() {
return next_thread_id++;
}
Thread::Thread(KernelSystem&) : context(Core::CPU().NewContext()) {}
Thread::Thread(KernelSystem& kernel) : WaitObject(kernel), context(Core::CPU().NewContext()) {}
Thread::~Thread() {}
Thread* GetCurrentThread() {

View File

@ -19,7 +19,7 @@ static CoreTiming::EventType* timer_callback_event_type = nullptr;
// us to simply use a pool index or similar.
static Kernel::HandleTable timer_callback_handle_table;
Timer::Timer(KernelSystem& kernel) {}
Timer::Timer(KernelSystem& kernel) : WaitObject(kernel) {}
Timer::~Timer() {}
SharedPtr<Timer> KernelSystem::CreateTimer(ResetType reset_type, std::string name) {

View File

@ -16,6 +16,8 @@ class Thread;
/// Class that represents a Kernel object that a thread can be waiting on
class WaitObject : public Object {
public:
using Object::Object;
/**
* Check if the specified thread should wait until the object is available
* @param thread The thread about which we're deciding.