From 664c79ff47054df845096e7e29d5cc437dfec2a2 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 30 Jan 2015 23:07:54 -0200 Subject: Thread: Modernize two functions that slipped through previous rebases --- src/core/hle/kernel/thread.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index d6299364a..cba074e07 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -77,6 +77,12 @@ public: /// Resumes a thread from waiting by marking it as "ready" void ResumeFromWait(); + /** + * Schedules an event to wake up the specified thread after the specified delay. + * @param nanoseconds The time this thread will be allowed to sleep for. + */ + void WakeAfterDelay(s64 nanoseconds); + /** * Sets the result after the thread awakens (from either WaitSynchronization SVC) * @param result Value to set to the returned result @@ -150,20 +156,13 @@ void WaitCurrentThread_WaitSynchronization(SharedPtr wait_object, bo */ void WaitCurrentThread_ArbitrateAddress(VAddr wait_address); -/** - * Schedules an event to wake up the specified thread after the specified delay. - * @param handle The thread handle. - * @param nanoseconds The time this thread will be allowed to sleep for. - */ -void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds); - /** * Sets up the idle thread, this is a thread that is intended to never execute instructions, * only to advance the timing. It is scheduled when there are no other ready threads in the thread queue * and will try to yield on every call. * @returns The handle of the idle thread */ -Handle SetupIdleThread(); +SharedPtr SetupIdleThread(); /// Initialize threading void ThreadingInit(); -- cgit v1.2.3 From a9b86db3cfec5ce907051d6730ffd98c0fd03876 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 14:23:09 -0200 Subject: Kernel: Use separate Handle tables for CoreTiming userdata This is to support the removal of GetHandle soon --- src/core/hle/kernel/thread.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index cba074e07..9a4a00fe8 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -122,6 +122,9 @@ public: private: Thread() = default; + + /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. + Handle callback_handle; }; /// Sets up the primary application thread -- cgit v1.2.3 From 4e84df8be30c5bac65e4c4e9faf07bf0fc3fb33a Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 19:22:40 -0200 Subject: Mutex: Replace g_mutex_held_locks with a set inside Thread --- src/core/hle/kernel/thread.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 9a4a00fe8..f29897ae8 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -7,6 +7,8 @@ #include #include +#include + #include "common/common_types.h" #include "core/core.h" @@ -40,6 +42,8 @@ enum ThreadStatus { namespace Kernel { +class Mutex; + class Thread final : public WaitObject { public: static ResultVal> Create(std::string name, VAddr entry_point, s32 priority, @@ -109,8 +113,10 @@ public: s32 processor_id; - std::vector> wait_objects; ///< Objects that the thread is waiting on + /// Mutexes currently held by this thread, which will be released when it exits. + boost::container::flat_set> held_mutexes; + std::vector> wait_objects; ///< Objects that the thread is waiting on VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address bool wait_all; ///< True if the thread is waiting on all objects before resuming bool wait_set_output; ///< True if the output parameter should be set on thread wakeup @@ -121,7 +127,7 @@ public: bool idle = false; private: - Thread() = default; + Thread(); /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. Handle callback_handle; -- cgit v1.2.3 From 7725256f649719dcce2c50ea84e79d6199dd9a50 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 31 Jan 2015 22:56:59 -0200 Subject: Explicitly instantiate constructors/destructors for Kernel objects This should speed up compile times a bit, as well as enable more liberal use of forward declarations. (Due to SharedPtr not trying to emit the destructor anymore.) --- src/core/hle/kernel/thread.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index f29897ae8..980c2613a 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -128,6 +128,7 @@ public: private: Thread(); + ~Thread() override; /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. Handle callback_handle; -- 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/thread.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 980c2613a..633bb7c98 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -134,6 +134,8 @@ private: Handle callback_handle; }; +extern SharedPtr g_main_thread; + /// Sets up the primary application thread SharedPtr SetupMainThread(s32 priority, u32 stack_size); -- cgit v1.2.3