Threading: Reworked the way our scheduler works.
Threads will now be awakened when the objects they're waiting on are signaled, instead of repeating the WaitSynchronization call every now and then. The scheduler is now called once after every SVC call, and once after a thread is awakened from sleep by its timeout callback. This new implementation is based off reverse-engineering of the real kernel. See https://gist.github.com/Subv/02f29bd9f1e5deb7aceea1e8f019c8f4 for a more detailed description of how the real kernel handles rescheduling.
This commit is contained in:
parent
0423a38ab5
commit
8634b8cb83
8 changed files with 189 additions and 199 deletions
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include "common/common_types.h"
|
||||
|
@ -124,6 +125,16 @@ public:
|
|||
*/
|
||||
void SetWaitSynchronizationOutput(s32 output);
|
||||
|
||||
/**
|
||||
* Retrieves the index that this particular object occupies in the list of objects
|
||||
* that the thread passed to WaitSynchronizationN.
|
||||
* It is used to set the output value of WaitSynchronizationN when the thread is awakened.
|
||||
* @param object Object to query the index of.
|
||||
*/
|
||||
s32 GetWaitObjectIndex(WaitObject* object) {
|
||||
return wait_objects_index[object->GetObjectId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a thread, invalidating it from further use
|
||||
*/
|
||||
|
@ -154,16 +165,16 @@ public:
|
|||
|
||||
VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread
|
||||
|
||||
bool waitsynch_waited; ///< Set to true if the last svcWaitSynch call caused the thread to wait
|
||||
|
||||
/// Mutexes currently held by this thread, which will be released when it exits.
|
||||
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
|
||||
|
||||
SharedPtr<Process> owner_process; ///< Process that owns this thread
|
||||
std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
|
||||
std::unordered_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited 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
|
||||
|
||||
bool wait_set_output; ///< True if the WaitSynchronizationN output parameter should be set on thread wakeup
|
||||
|
||||
std::string name;
|
||||
|
||||
|
@ -215,10 +226,9 @@ void WaitCurrentThread_Sleep();
|
|||
* @param wait_objects Kernel objects that we are waiting on
|
||||
* @param wait_set_output If true, set the output parameter on thread wakeup (for
|
||||
* WaitSynchronizationN only)
|
||||
* @param wait_all If true, wait on all objects before resuming (for WaitSynchronizationN only)
|
||||
*/
|
||||
void WaitCurrentThread_WaitSynchronization(std::vector<SharedPtr<WaitObject>> wait_objects,
|
||||
bool wait_set_output, bool wait_all);
|
||||
bool wait_set_output);
|
||||
|
||||
/**
|
||||
* Waits the current thread from an ArbitrateAddress call
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue