aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
Commit message (Collapse)AuthorAgeFilesLines
* kernel/thread: Unify wait synchronization typesLioncash2019-04-171-3/+2
| | | | | | | | | | | | | | | | This is a holdover from Citra, where the 3DS has both WaitSynchronization1 and WaitSynchronizationN. The switch only has one form of wait synchronizing (literally WaitSynchonization). This allows us to throw out code that doesn't apply at all to the Switch kernel. Because of this unnecessary dichotomy within the wait synchronization utilities, we were also neglecting to properly handle waiting on multiple objects. While we're at it, we can also scrub out any lingering references to WaitSynchronization1/WaitSynchronizationN in comments, and change them to WaitSynchronization (or remove them if the mention no longer applies).
* kernel/svc: Migrate svcCancelSynchronization behavior to a thread functionLioncash2019-04-171-0/+6
| | | | | | | The actual behavior of this function is slightly more complex than what we're currently doing within the supervisor call. To avoid dumping most of this behavior in the supervisor call itself, we can migrate this to another function.
* kernel/thread: Remove BoostPriority()Lioncash2019-04-151-5/+0
| | | | | This is a holdover from Citra that currently remains unused, so it can be removed from the Thread interface.
* Merge pull request #2314 from lioncash/constbunnei2019-04-031-6/+6
|\ | | | | kernel/thread: Minor interface cleanup
| * kernel/thread: Make AllWaitObjectsReady() a const qualified member functionLioncash2019-04-011-1/+1
| | | | | | | | | | | | Now that ShouldWait() is a const qualified member function, this one can be made const qualified as well, since it can handle passing a const qualified this pointer to ShouldWait().
| * kernel/wait_object: Make ShouldWait() take thread members by pointer-to-constLioncash2019-04-011-1/+1
| | | | | | | | | | Given this is intended as a querying function, it doesn't make sense to allow the implementer to modify the state of the given thread.
| * kernel/thread: Avoid sign conversion within GetCommandBufferAddress()Lioncash2019-04-011-2/+2
| | | | | | | | | | | | | | | | | | | | Previously this was performing a u64 + int sign conversion. When dealing with addresses, we should generally be keeping the arithmetic in the same signedness type. This also gets rid of the static lifetime of the constant, as there's no need to make a trivial type like this potentially live for the entire duration of the program.
| * kernel/thread: Make parameter of GetWaitObjectIndex() const qualifiedLioncash2019-04-011-2/+2
| | | | | | | | | | The pointed to member is never actually modified, so it can be made const.
* | kernel/svc: Implement svcGetThreadListLioncash2019-04-021-0/+4
|/ | | | | | | | | | | | | Similarly like svcGetProcessList, this retrieves the list of threads from the current process. In the kernel itself, a process instance maintains a list of threads, which are used within this function. Threads are registered to a process' thread list at thread initialization, and unregistered from the list upon thread destruction (if said thread has a non-null owning process). We assert on the debug event case, as we currently don't implement kernel debug objects.
* kernel/scheduler: Remove unused parameter to AddThread()Lioncash2019-03-301-2/+2
| | | | | This was made unused in 1913519836ce65b1b4a9e117b11d7bbf4a79e52d, but the parameter itself wasn't removed.
* Merge pull request #2266 from FernandoS27/arbitrationbunnei2019-03-281-0/+1
|\ | | | | Kernel: Fixes to Arbitration and SignalProcessWideKey Management
| * Add CondVar Thread State.Fernando Sahmkow2019-03-191-0/+1
| |
* | Fix crash caused by 2238.Fernando Sahmkow2019-03-191-1/+2
|/
* Merge pull request #2238 from lioncash/threadbunnei2019-03-171-19/+33
|\ | | | | kernel/thread: Amend conditional test and assignment within UpdatePriority()
| * kernel/thread: Expand documentation of nominal_priority and current_priorityLioncash2019-03-151-1/+3
| | | | | | | | | | Aims to disambiguate why each priority instance exists a little bit. While we're at it, also add an explanatory comment to UpdatePriority().
| * kernel/thread: Make bracing consistent within UpdatePriority()Lioncash2019-03-151-2/+4
| |
| * kernel/thread: Amend condition within UpdatePriority()Lioncash2019-03-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | This condition was checking against the nominal thread priority, whereas the kernel itself checks against the current priority instead. We were also assigning the nominal priority, when we should be assigning current_priority, which takes priority inheritance into account. This can lead to the incorrect priority being assigned to a thread. Given we recursively update the relevant threads, we don't need to go through the whole mutex waiter list. This matches what the kernel does as well (only accessing the first entry within the waiting list).
| * kernel/thread: Maintain priority ordering of added mutex waiting threadsLioncash2019-03-151-14/+24
| | | | | | | | | | The kernel keeps the internal waiting list ordered by priority. This is trivial to do with std::find_if followed by an insertion.
* | kernel/thread: Actually remove the definition of ExitCurrentThread()Lioncash2019-03-161-6/+0
| | | | | | | | | | | | This was intended to be removed in 0032bede5a880a44bffcb702eb8fe858c214dc39, but I guess I forgot to actually save the file like a dingus.
* | kernel/thread: Migrate WaitCurrentThread_Sleep into the Thread interfaceLioncash2019-03-151-5/+8
|/ | | | | | Rather than make a global accessor for this sort of thing. We can make it a part of the thread interface itself. This allows getting rid of a hidden global accessor in the kernel code.
* kernel/thread: Remove obsolete TODO in Create()Lioncash2019-03-051-2/+0
| | | | This is a TODO carried over from Citra that doesn't apply here.
* core_timing: Convert core timing into a classLioncash2019-02-151-8/+11
| | | | | | | | | | | Gets rid of the largest set of mutable global state within the core. This also paves a way for eliminating usages of GetInstance() on the System class as a follow-up. Note that no behavioral changes have been made, and this simply extracts the functionality into a class. This also has the benefit of making dependencies on the core timing functionality explicit within the relevant interfaces.
* core_timing: Rename CoreTiming namespace to Core::TimingLioncash2019-02-121-6/+7
| | | | | | Places all of the timing-related functionality under the existing Core namespace to keep things consistent, rather than having the timing utilities sitting in its own completely separate namespace.
* kernel/thread: Move process thread initialization into process.cppLioncash2018-12-271-24/+0
| | | | | | | | | | This function isn't a general purpose function that should be exposed to everything, given it's specific to initializing the main thread for a Process instance. Given that, it's a tad bit more sensible to place this within process.cpp, which keeps it visible only to the code that actually needs it.
* Merge pull request #1849 from encounter/svcSetThreadActivitybunnei2018-12-261-1/+23
|\ | | | | svc: Implement SetThreadActivity (thread suspension)
| * svc: Implement SetThreadActivity (thread suspension)Luke Street2018-12-041-1/+23
| |
* | kernel/thread: Set default fpcrMerryMage2018-12-181-0/+3
|/
* kernel/thread: Deduplicate scheduler switching codeLioncash2018-11-141-37/+11
| | | | | The code in both places was the same verbatim, so we can extract it to a function to deduplicate the logic.
* global: Use std::optional instead of boost::optional (#1578)Frederic L2018-10-301-4/+4
| | | | | | | | | | | | | | | | * get rid of boost::optional * Remove optional references * Use std::reference_wrapper for optional references * Fix clang format * Fix clang format part 2 * Adressed feedback * Fix clang format and MacOS build
* kernel/process: Make the handle table per-processLioncash2018-10-201-1/+1
| | | | | | | | In the kernel, there isn't a singular handle table that everything gets tossed into or used, rather, each process gets its own handle table that it uses. This currently isn't an issue for us, since we only execute one process at the moment, but we may as well get this out of the way so it's not a headache later on.
* core_cpu: Make Cpu scheduler instances unique_ptrs instead of shared_ptrsLioncash2018-10-151-8/+8
|
* thread: Remove unnecessary memset from ResetThreadContext()Lioncash2018-10-121-4/+1
| | | | | | Regular value initialization is adequate here for zeroing out data. It also has the benefit of not invoking undefined behavior if a non-trivial type is ever added to the struct for whatever reason.
* kernel/thread: Use a regular pointer for the owner/current processLioncash2018-10-101-4/+4
| | | | | | | | | | | There's no real need to use a shared pointer in these cases, and only makes object management more fragile in terms of how easy it would be to introduce cycles. Instead, just do the simple thing of using a regular pointer. Much of this is just a hold-over from citra anyways. It also doesn't make sense from a behavioral point of view for a process' thread to prolong the lifetime of the process itself (the process is supposed to own the thread, not the other way around).
* thread: Make the scheduler pointer a regular pointerbalika0112018-10-051-3/+3
| | | | | | | | | | | | | | Conceptually, it doesn't make sense for a thread to be able to persist the lifetime of a scheduler. A scheduler should be taking care of the threads; the threads should not be taking care of the scheduler. If the threads outlive the scheduler (or we simply don't actually terminate/shutdown the threads), then it should be considered a bug that we need to fix. Attributing this to balika011, as they opened #1317 to attempt to fix this in a similar way, but my refactoring of the kernel code caused quite a few conflicts.
* kernel/thread: Make all instance variables privateLioncash2018-10-041-4/+28
| | | | | | | | | | | | | | | | | | | | Many of the member variables of the thread class aren't even used outside of the class itself, so there's no need to make those variables public. This change follows in the steps of the previous changes that made other kernel types' members private. The main motivation behind this is that the Thread class will likely change in the future as emulation becomes more accurate, and letting random bits of the emulator access data members of the Thread class directly makes it a pain to shuffle around and/or modify internals. Having all data members public like this also makes it difficult to reason about certain bits of behavior without first verifying what parts of the core actually use them. Everything being public also generally follows the tendency for changes to be introduced in completely different translation units that would otherwise be better introduced as an addition to the Thread class' public interface.
* kernel/process: Make data member variables privateLioncash2018-09-301-2/+2
| | | | | | | Makes the public interface consistent in terms of how accesses are done on a process object. It also makes it slightly nicer to reason about the logic of the process class, as we don't want to expose everything to external code.
* memory: Dehardcode the use of fixed memory range constantsLioncash2018-09-241-1/+2
| | | | | | | | The locations of these can actually vary depending on the address space layout, so we shouldn't be using these when determining where to map memory or be using them as offsets for calculations. This keeps all the memory ranges flexible and malleable based off of the virtual memory manager instance state.
* thread/process: Move TLS slot marking/freeing to the process classLioncash2018-09-211-56/+2
| | | | | | Allows making several members of the process class private, it also avoids going through Core::CurrentProcess() just to retrieve the owning process.
* kernel/thread: Use owner_process when setting the page table in ↵Lioncash2018-09-201-3/+3
| | | | | | | | | SetupMainThread() The owning process of a thread is required to exist before the thread, so we can enforce this API-wise by using a reference. We can also avoid the reliance on the system instance by using that parameter to access the page table that needs to be set.
* arm_interface: Remove ARM11-isms from the CPU interfaceLioncash2018-09-181-2/+2
| | | | | | | | | This modifies the CPU interface to more accurately match an AArch64-supporting CPU as opposed to an ARM11 one. Two of the methods don't even make sense to keep around for this interface, as Adv Simd is used, rather than the VFP in the primary execution state. This is essentially a modernization change that should have occurred from the get-go.
* Port #4182 from Citra: "Prefix all size_t with std::"fearlessTobi2018-09-151-1/+1
|
* kernel/errors: Correct error codes for invalid thread priority and invalid ↵Lioncash2018-09-121-2/+2
| | | | processor ID
* core/core: Replace includes with forward declarations where applicableLioncash2018-08-311-1/+2
| | | | | | | | | | | The follow-up to 88597535d629ea9a265f8bf0f00a9ce4dd5dc218, which replaces most of the includes in the core header with forward declarations. This makes it so that if any of the headers the core header was previously including change, then no one will need to rebuild the bulk of the core, due to core.h being quite a prevalent inclusion. This should make turnaround for changes much faster for developers.
* kernel: Eliminate kernel global stateLioncash2018-08-281-101/+18
| | | | | | | | | | | | | | | | | | | | | | As means to pave the way for getting rid of global state within core, This eliminates kernel global state by removing all globals. Instead this introduces a KernelCore class which acts as a kernel instance. This instance lives in the System class, which keeps its lifetime contained to the lifetime of the System class. This also forces the kernel types to actually interact with the main kernel instance itself instead of having transient kernel state placed all over several translation units, keeping everything together. It also has a nice consequence of making dependencies much more explicit. This also makes our initialization a tad bit more correct. Previously we were creating a kernel process before the actual kernel was initialized, which doesn't really make much sense. The KernelCore class itself follows the PImpl idiom, which allows keeping all the implementation details sealed away from everything else, which forces the use of the exposed API and allows us to avoid any unnecessary inclusions within the main kernel header.
* core: Namespace all code in the arm subdirectory under the Core namespaceLioncash2018-08-241-2/+2
| | | | Gets all of these types and interfaces out of the global namespace.
* Core::CoreTiming: add UnscheduleEventThreadsafeB3n302018-08-131-1/+1
|
* Merge pull request #1042 from Subv/racesbunnei2018-08-121-2/+9
|\ | | | | Fixed a bunch of race conditions when running in multicore mode.
| * Kernel/Threads: Lock the HLE mutex when executing the wakeup callback.Subv2018-08-121-0/+5
| | | | | | | | Another thread might be in the middle of a reschedule, thus altering the state of the schedulers.
| * Kernel/Thread: Always use the threadsafe option when scheduling wakeups.Subv2018-08-121-2/+4
| | | | | | | | | | | | WakeAfterDelay might be called from any host thread, so err on the side of caution and use the thread-safe CoreTiming::ScheduleEventThreadsafe. Note that CoreTiming is still far from thread-safe, there may be more things we have to work on for it to be up to par with what we want.
* | Kernel/Mutex: Don't duplicate threads in the mutex waiter list.Subv2018-08-121-0/+21
|/ | | | | | | | | | Exit from AddMutexWaiter early if the thread is already waiting for a mutex owned by the owner thread. This accounts for the possibility of a thread that is waiting on a condition variable being awakened twice in a row. Also added more validation asserts. This should fix one of the random crashes in Breath Of The Wild.