From 869ec46683c508de5692eaace1a66e682f90b4de Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 14:55:40 -0200 Subject: Kernel: Introduce unique Object ids for debugging --- src/core/hle/kernel/kernel.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/core/hle/kernel/kernel.h') diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 9860479ac..5567780fe 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -67,6 +67,9 @@ public: virtual ~Object() {} Handle GetHandle() const { return handle; } + /// Returns a unique identifier for the object. For debugging purposes only. + unsigned int GetObjectId() const { return object_id; } + virtual std::string GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; } virtual std::string GetName() const { return "[UNKNOWN KERNEL OBJECT]"; } virtual Kernel::HandleType GetHandleType() const = 0; @@ -101,7 +104,10 @@ private: friend void intrusive_ptr_add_ref(Object*); friend void intrusive_ptr_release(Object*); + static unsigned int next_object_id; + unsigned int ref_count = 0; + unsigned int object_id = next_object_id++; }; // Special functions used by boost::instrusive_ptr to do automatic ref-counting -- cgit v1.2.3 From 5354a479bccc2ab47692e6cb237ec66ee8251207 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 14:57:32 -0200 Subject: Kernel: Remove Object::GetHandle (it's not used anymore :D) --- src/core/hle/kernel/kernel.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/core/hle/kernel/kernel.h') diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 5567780fe..bf5b47a61 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -58,14 +58,9 @@ enum { DEFAULT_STACK_SIZE = 0x4000, }; -class HandleTable; - class Object : NonCopyable { - friend class HandleTable; - u32 handle = INVALID_HANDLE; public: virtual ~Object() {} - Handle GetHandle() const { return handle; } /// Returns a unique identifier for the object. For debugging purposes only. unsigned int GetObjectId() const { return object_id; } -- cgit v1.2.3 From 52f58e64efbf43c114f701eb8f39fb463138ffb8 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 23:26:16 -0200 Subject: Kernel: Make WaitObjects share ownership of Threads waiting on them During normal operation, a thread waiting on an WaitObject and the object hold mutual references to each other for the duration of the wait. If a process is forcefully terminated (The CTR kernel has a SVC to do this, TerminateProcess, though no equivalent exists for threads.) its threads would also be stopped and destroyed, leaving dangling pointers in the WaitObjects. The solution is to simply have the Thread remove itself from WaitObjects when it is stopped. The vector of Threads in WaitObject has also been changed to hold SharedPtrs, just in case. (Better to have a reference cycle than a crash.) --- src/core/hle/kernel/kernel.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/core/hle/kernel/kernel.h') diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index bf5b47a61..4d8e388b6 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -136,25 +136,26 @@ public: * Add a thread to wait on this object * @param thread Pointer to thread to add */ - void AddWaitingThread(Thread* thread); + void AddWaitingThread(SharedPtr thread); /** * Removes a thread from waiting on this object (e.g. if it was resumed already) * @param thread Pointer to thread to remove */ - void RemoveWaitingThread(Thread* thead); + void RemoveWaitingThread(Thread* thread); /** * Wake up the next thread waiting on this object * @return Pointer to the thread that was resumed, nullptr if no threads are waiting */ - Thread* WakeupNextThread(); + SharedPtr WakeupNextThread(); /// Wake up all threads waiting on this object void WakeupAllWaitingThreads(); private: - std::vector waiting_threads; ///< Threads waiting for this object to become available + /// Threads waiting for this object to become available + std::vector> waiting_threads; }; /** @@ -275,7 +276,6 @@ private: }; extern HandleTable g_handle_table; -extern SharedPtr g_main_thread; /// The ID code of the currently running game /// TODO(Subv): This variable should not be here, -- cgit v1.2.3