summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_thread.cpp (unfollow)
Commit message (Collapse)AuthorFilesLines
2022-04-12core: hle: kernel: k_thread: Rework dummy thread waiting.bunnei1-24/+15
2022-04-04k_thread: Fix data racelat9nq1-2/+2
TSan reports a data race between writing at cpp:1162 and reading at h:262. Make the thread_state atomic to prevent this.
2022-03-19core: Reduce unused includesameerj1-3/+0
2022-03-15core: hle: kernel: k_process: Implement thread local storage accurately.bunnei1-2/+2
2022-03-15core: hle: kernel: k_thread: Ensure host Fiber is freed.bunnei1-0/+3
2022-01-23hle: kernel: KThread: Improve Increment/Decrement RunningThreadCount.bunnei1-8/+3
- Previously implementation was incorrect, and would occasionally underflow.
2022-01-22hle: kernel: KThread: Ensure host (dummy) threads block on locking.bunnei1-0/+37
- But do not enter the priority queue, as otherwise they will be scheduled. - Allows dummy threads to use guest synchronization primitives.
2022-01-21hle: kernel: KThread: DummyThread can be waited, ensure wait_queue is not nullptr.bunnei1-6/+6
2022-01-21hle: kernel: KThread: Decrease DummyThread priority to ensure it is never scheduled.bunnei1-2/+3
2022-01-21hle: kernel: KThread: Ensure dummy threads never call EndWait.bunnei1-0/+5
- These are only used by host threads for locking and will never have a wait_queue.
2022-01-21hle: kernel: KThread: Rename thread_type_for_debugging -> thread_type.bunnei1-1/+1
- This will be used to ensure that we do not schedule dummy threads.
2022-01-15core: hle: kernel: KThread: Integrate with KWorkerTask and implement DoWorkerTaskImpl.bunnei1-1/+22
- This is used to terminate a thread asynchronously after it has been exited. - This fixes a crash that can occur in Pokemon Sword/Shield because a thread is incorrectly closed on svcExitThread, then, the thread is destroyed on svcCloseHandle while it is still scheduled. - Instead, we now wait for the thread to no longer be scheduled on all cores before destroying it from KWorkerTaskManager, which is accurate to HOS behavior.
2022-01-15core: hle: kernel: KThread: Replace Suspend with UpdateState & various updates.bunnei1-31/+24
- This makes our implementations of these more closely match HOS.
2021-12-31core: hle: kernel: Implement thread pinning.bunnei1-3/+41
- We largely had the mechanics in place for thread pinning, this change hooks these up. - Validated with tests https://github.com/Atmosphere-NX/Atmosphere/blob/master/tests/TestSvc/source/test_thread_pinning.cpp.
2021-12-23 core: hle: kernel: KThread: X18 should be a cryptographically random number.bunnei1-0/+2
- This was added with firmware 11.0.0 (https://switchbrew.org/wiki/11.0.0). - X18 is OR'd by kernel with 1, to make sure it is odd.
2021-12-07hle: kernel: Remove unnecessary virtual specifier on CancelWait.bunnei1-2/+2
2021-12-07hle: kernel: k_thread: Skip reschedule on DisableDispatch with SC.bunnei1-0/+5
2021-12-07hle: kernel: k_thread: Rename sleeping_queue -> wait_queue.bunnei1-11/+11
2021-12-07hle: kernel: k_thread: Treat dummy threads as a special type.bunnei1-1/+3
2021-12-07hle: kernel: Add a flag for indicating that the kernel is currently shutting down.bunnei1-0/+5
2021-12-07hle: kernel: Cleanup to match coding style.bunnei1-5/+4
2021-12-07hle: kernel: KThread: Migrate to updated KThreadQueue (part 2).bunnei1-29/+19
2021-12-07hle: kernel: KThread: Migrate to updated KThreadQueue (part 1).bunnei1-57/+64
2021-12-07hle: kernel: KThread: Remove tracking of sync object from threads.bunnei1-5/+2
2021-12-07hle: kernel: Update KThreadQueue and migrate KSynchronizationObject.bunnei1-2/+40
2021-12-07core: hle: kernel: Disable dispatch count tracking on single core.bunnei1-1/+5
- This would have limited value, and would be a mess to handle properly.
2021-12-07core: hle: kernel: k_thread: Add KScopedDisableDispatch.bunnei1-1/+16
2021-11-04core: Remove unused includesameerj1-4/+0
2021-08-26Revert "kernel: Various improvements to scheduler"bunnei1-19/+2
2021-08-14core: hle: kernel: Disable dispatch count tracking on single core.bunnei1-1/+3
- This would have limited value, and would be a mess to handle properly.
2021-08-07core: hle: kernel: k_thread: Add KScopedDisableDispatch.bunnei1-1/+16
2021-06-02general: Replace RESULT_SUCCESS with ResultSuccessMorph1-9/+9
Transition to PascalCase for result names.
2021-05-29k_thread: Move dereference after null check in Initialize()Lioncash1-5/+5
Prevents a -Wnonnull warning on GCC.
2021-05-08kernel: Eliminate variable shadowingLioncash1-16/+16
Now that the large kernel refactor is merged, we can eliminate the remaining variable shadowing cases.
2021-05-06hle: kernel: Migrate to KHandleTable.bunnei1-1/+1
2021-05-06hle: kernel: Rename Process to KProcess.bunnei1-5/+5
2021-05-06hle: kernel: Remove deprecated Object class.bunnei1-1/+0
2021-05-06hle: kernel: KThread: Remove incorrect resource release.bunnei1-2/+1
2021-05-06hle: kernel: KThread: Add missing resource hint release.bunnei1-1/+1
2021-05-06hle: kernel: Migrate KSharedMemory to KAutoObject.bunnei1-0/+3
2021-05-06hle: kernel: Migrate KThread to KAutoObject.bunnei1-52/+48
2021-03-06hle: kernel: KThread: Rework dummy threads & fix memory leak.bunnei1-19/+31
- Dummy threads are created on thread local storage for all host threads. - Fixes a leak by removing creation of fibers, which are not applicable here.
2021-03-06Revert "core: Switch to unique_ptr for usage of Common::Fiber."bunnei1-1/+5
2021-02-27core: Switch to unique_ptr for usage of Common::Fiber.bunnei1-5/+1
- With using unique_ptr instead of shared_ptr, we have more explicit ownership of the context. - Fixes a memory leak due to circular reference of the shared pointer.
2021-02-19hle: kernel: Migrate MemoryLayout to KMemoryLayout.bunnei1-4/+4
2021-02-13kernel: Unify result codes (#5890)Chloe1-16/+14
* kernel: Unify result codes Drop the usage of ERR_NAME convention in kernel for ResultName. Removed seperation between svc_results.h & errors.h as we mainly include both most of the time anyways. * oops * rename errors to svc_results
2021-02-03Simplify limitableresource namesChloe Marcec1-1/+1
2021-01-30kernel: Rewrite resource limit to be more accurateChloe Marcec1-2/+2
Matches closer to hardware
2021-01-29hle: kernel: KThread: Release thread resource on thread exit.bunnei1-0/+1
2021-01-29yuzu: debugger: Ignore HLE threads.bunnei1-7/+8
2021-01-29hle: kernel: Allocate a dummy KThread for each host thread, and use it for scheduling.bunnei1-5/+1
2021-01-29kernel: Fix build errors.bunnei1-2/+7
2021-01-29hle: kernel: Recode implementation of KThread to be more accurate.bunnei1-197/+796
2021-01-29hle: kernel: KThread: Clean up thread priorities.bunnei1-9/+1
2021-01-29hle: kernel: KThread: Reorganize thread priority defaults.bunnei1-7/+6
2021-01-29hle: kernel: KThread: Remove thread types that do not exist.bunnei1-12/+9
2021-01-29core: hle: kernel: Rename Thread to KThread.bunnei1-39/+39
2021-01-11hle: kernel: thread: Preserve thread wait reason for debugging only.bunnei1-1/+5
- This is decoupled from core functionality and used for debugging only.
2021-01-11core: hle: Integrate new KConditionVariable and KAddressArbiter implementations.bunnei1-100/+127
2021-01-11hle: kernel: thread: Replace ThreadStatus/ThreadSchedStatus with a single ThreadState.bunnei1-51/+30
- This is how the real kernel works, and is more accurate and simpler.
2021-01-11core: hle: kernel: Update KSynchronizationObject.bunnei1-47/+19
2020-12-06hle: kernel: Migrate to KScopedSchedulerLock.bunnei1-9/+8
2020-12-06hle: kernel: Separate KScopedSchedulerLockAndSleep from k_scheduler.bunnei1-1/+2
2020-12-06hle: kernel: Rewrite scheduler implementation based on Mesopshere.bunnei1-37/+13
2020-12-06hle: kernel: Port KAffinityMask from Mesosphere.bunnei1-5/+6
2020-11-29hle: kernel: thread: Remove unused "Running" state.bunnei1-5/+0
2020-11-29hle: kernel: multicore: Replace n-JITs impl. with 4 JITs.bunnei1-25/+2
2020-11-04core: Remove usage of unicornLioncash1-14/+3
Unicorn long-since lost most of its use, due to dynarmic gaining support for handling most instructions. At this point any further issues encountered should be used to make dynarmic better. This also allows us to remove our dependency on Python.
2020-10-21Revert "core: Fix clang build"bunnei1-1/+1
2020-10-18core: Fix clang buildLioncash1-1/+1
Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795
2020-07-16cpu_manager: Mark function getters as staticLioncash1-1/+1
All these do are return std::function instances of static functions, so these can be used without an instance of the CPU manager.
2020-07-15kernel/thread: Remove global GetCurrentThread()Lioncash1-17/+5
This is only used in one place, so we can fold it into the calling code, eliminating a place for the global system instance to be used.
2020-06-27Kernel: Correct Host Context on Threads and Scheduler.Fernando Sahmkow1-1/+1
2020-06-27General: Cleanup legacy code.Fernando Sahmkow1-34/+0
2020-06-27SingleCore: Use Cycle Timing instead of Host Timing.Fernando Sahmkow1-4/+8
2020-06-27Thread: Release the ARM Interface on exitting.Fernando Sahmkow1-0/+2
2020-06-27General: Move ARM_Interface into Threads.Fernando Sahmkow1-0/+35
2020-06-27General: Fix Stop functionFernando Sahmkow1-3/+5
2020-06-27Kernel: Preempt Single core on redudant yields.Fernando Sahmkow1-9/+12
2020-06-27Scheduler: Set last running time on thread.Fernando Sahmkow1-4/+0
2020-06-27ARM/Memory: Correct Exclusive Monitor and Implement Exclusive Memory Writes.Fernando Sahmkow1-3/+3
2020-06-27SVC: Correct SetThreadActivity.Fernando Sahmkow1-21/+40
2020-06-27SCC: Small corrections to CancelSynchronizationFernando Sahmkow1-2/+3
2020-06-27Kernel: Correct Signal on Thread Death and Setup Sync Objects on Thread for DebuggingFernando Sahmkow1-8/+7
2020-06-27Core: Correct HLE Event Callbacks and other issues.Fernando Sahmkow1-18/+17
2020-06-27SVC: Correct WaitSynchronization, WaitProcessWideKey, SignalProcessWideKey.Fernando Sahmkow1-1/+1
2020-06-27SVC: Correct SendSyncRequest.Fernando Sahmkow1-4/+10
2020-06-27SVC: Correct ArbitrateUnlockFernando Sahmkow1-1/+1
2020-06-27SVC: Correct SignalEvent, ClearEvent, ResetSignal, WaitSynchronization, CancelSynchronization, ArbitrateLockFernando Sahmkow1-5/+9
2020-06-27SVC: Correct GetThreadPriority, SetThreadPriority, GetThreadCoreMask, SetThreadCoreMask, GetCurrentProcessorNumberFernando Sahmkow1-4/+2
2020-06-27SVC: Correct CreateThread, StartThread, ExitThread, SleepThread.Fernando Sahmkow1-20/+18
2020-06-27General: Recover Prometheus project from harddrive failure Fernando Sahmkow1-136/+96
This commit: Implements CPU Interrupts, Replaces Cycle Timing for Host Timing, Reworks the Kernel's Scheduler, Introduce Idle State and Suspended State, Recreates the bootmanager, Initializes Multicore system.
2020-04-29kernel: Don't fail silentlyDavid Marcec1-0/+2
2020-04-19thread: FPCR.FZ is likely not 1MerryMage1-2/+1
2020-04-15kernel/thread: Resolve -Wswitch warningsLioncash1-0/+2
2020-03-03core: Implement separate A32/A64 ARM interfaces.bunnei1-14/+17
2020-02-22Kernel: Rename ThreadCallbackHandleTable and Setup Thread Ids on Kernel.Fernando Sahmkow1-6/+6
2020-02-12kernel/thread: Remove trivial usages of the global system accessorLioncash1-2/+2
We can just use the kernel member variable directly instead of going through the system to obtain the same thing.
2020-02-12Core: Set all hardware emulation constants in a single file.Fernando Sahmkow1-7/+8
2020-02-11Kernel: Refactor synchronization to better match REFernando Sahmkow1-1/+5
2020-02-11Kernel: Change WaitObject to Synchronization object. In order to better reflect RE.Fernando Sahmkow1-7/+9
2020-01-26Kernel: Remove a few global instances from the kernel.Fernando Sahmkow1-1/+1
2020-01-26Core: Refactor CpuCoreManager to CpuManager and Cpu to Core Manager.Fernando Sahmkow1-2/+1
This commit instends on better naming the new purpose of this classes.
2019-11-27core/memory: Migrate over address checking functions to the new Memory classLioncash1-2/+2
A fairly straightforward migration. These member functions can just be mostly moved verbatim with minor changes. We already have the necessary plumbing in places that they're used. IsKernelVirtualAddress() can remain a non-member function, since it doesn't rely on class state in any form.
2019-11-25kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. (#3154)bunnei1-19/+20
* kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. - See https://github.com/citra-emu/citra/pull/4710 for details.
2019-11-21Kernel: Correct behavior of Condition Variables to be more similar to real hardware.Fernando Sahmkow1-0/+8
This commit ensures cond var threads act exactly as they do in the real console. The original implementation uses an RBTree and the behavior of cond var threads is that at the same priority level they act like a FIFO.
2019-11-16Kernel: Correct Cancel Synchronization.Fernando Sahmkow1-2/+5
This commit corrects the behavior of cancel synchronization when the thread is running/ready and ensures the next wait is cancelled as it's suppose to.
2019-11-12kernel: Resolve sign conversion warningsLioncash1-30/+18
Uncovered a bug within Thread's SetCoreAndAffinityMask() where an unsigned variable (ideal_core) was being compared against "< 0", which would always be a false condition. We can also get rid of an unused function (GetNextProcessorId) which contained a sign mismatch warning.
2019-10-15Kernel Thread: Cleanup THREADPROCESSORID_DONT_UPDATE.Fernando Sahmkow1-1/+1
2019-10-15Kernel: Address Feedback 2Fernando Sahmkow1-3/+3
2019-10-15Kernel: Clang FormatFernando Sahmkow1-4/+4
2019-10-15Kernel: Reverse global accessor removal.Fernando Sahmkow1-8/+8
2019-10-15Kernel: Address Feedback.Fernando Sahmkow1-9/+8
2019-10-15Kernel_Thread: Eliminate most global accessors.Fernando Sahmkow1-11/+11
2019-10-15Kernel: Correct Paused schedulingFernando Sahmkow1-3/+1
2019-10-15Kernel: Corrections to Wait Objects clearing in which a thread could still be signalled after a timeout or a cancel.Fernando Sahmkow1-0/+1
2019-10-15Scheduler: Add protections for Yield bombingFernando Sahmkow1-6/+6
In case of redundant yields, the scheduler will now idle the core for it's timeslice, in order to avoid continuously yielding the same thing over and over.
2019-10-15Kernel: Style and CorrectionsFernando Sahmkow1-24/+30
2019-10-15Addapt thread class to the new SchedulerFernando Sahmkow1-59/+183
2019-07-04kernel/process: Decouple TLS handling from threadsLioncash1-2/+2
Extracts out all of the thread local storage management from thread instances themselves and makes the owning process handle the management of the memory. This brings the memory management slightly more in line with how the kernel handles these allocations. Furthermore, this also makes the TLS page management a little more readable compared to the lingering implementation that was carried over from Citra.
2019-06-16Core_Timing: Make core_timing threadsafe by default.Fernando Sahmkow1-3/+3
The old implementation had faulty Threadsafe methods where events could be missing. This implementation unifies unsafe/safe methods and makes core timing thread safe overall.
2019-06-05core/core_timing_util: Use std::chrono types for specifying time unitsLioncash1-2/+2
Makes the interface more type-safe and consistent in terms of return values.
2019-04-17kernel/thread: Unify wait synchronization typesLioncash1-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).
2019-04-17kernel/svc: Migrate svcCancelSynchronization behavior to a thread functionLioncash1-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.
2019-04-15kernel/thread: Remove BoostPriority()Lioncash1-5/+0
This is a holdover from Citra that currently remains unused, so it can be removed from the Thread interface.
2019-04-02kernel/svc: Implement svcGetThreadListLioncash1-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.
2019-04-02kernel/thread: Make AllWaitObjectsReady() a const qualified member functionLioncash1-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().
2019-04-02kernel/wait_object: Make ShouldWait() take thread members by pointer-to-constLioncash1-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.
2019-04-01kernel/thread: Avoid sign conversion within GetCommandBufferAddress()Lioncash1-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.
2019-04-01kernel/thread: Make parameter of GetWaitObjectIndex() const qualifiedLioncash1-2/+2
The pointed to member is never actually modified, so it can be made const.
2019-03-30kernel/scheduler: Remove unused parameter to AddThread()Lioncash1-2/+2
This was made unused in b404fcdf1443b91ac9994c05ad1fe039fcd9675e, but the parameter itself wasn't removed.
2019-03-20Fix crash caused by 2238.Fernando Sahmkow1-1/+2
2019-03-20Add CondVar Thread State.Fernando Sahmkow1-0/+1
2019-03-16kernel/thread: Actually remove the definition of ExitCurrentThread()Lioncash1-6/+0
This was intended to be removed in 51d7f6bffcc0498a47abc7de27bf0906fc523dae, but I guess I forgot to actually save the file like a dingus.
2019-03-16kernel/thread: Migrate WaitCurrentThread_Sleep into the Thread interfaceLioncash1-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.
2019-03-16kernel/thread: Expand documentation of nominal_priority and current_priorityLioncash1-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().
2019-03-16kernel/thread: Make bracing consistent within UpdatePriority()Lioncash1-2/+4
2019-03-16kernel/thread: Amend condition within UpdatePriority()Lioncash1-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).
2019-03-16kernel/thread: Maintain priority ordering of added mutex waiting threadsLioncash1-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.
2019-03-05kernel/thread: Remove obsolete TODO in Create()Lioncash1-2/+0
This is a TODO carried over from Citra that doesn't apply here.
2019-02-16core_timing: Convert core timing into a classLioncash1-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.
2019-02-12core_timing: Rename CoreTiming namespace to Core::TimingLioncash1-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.
2018-12-28kernel/thread: Move process thread initialization into process.cppLioncash1-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.
2018-12-19Moved backtrace to ArmInterfaceDavid Marcec1-4/+0
2018-12-18kernel/thread: Set default fpcrMerryMage1-0/+3
2018-12-04svc: Implement SetThreadActivity (thread suspension)Luke Street1-1/+23
2018-12-03Moved backtrace to ArmInterfaceDavid Marcec1-14/+1
Added to both dynarmic and unicorn
2018-12-03Print backtrace on svcBreakDavid Marcec1-0/+17
When we get an svcBreak we get a backtrace now
2018-11-22scheduler: Add explanations for YieldWith and WithoutLoadBalancingZach Hilman1-60/+0
2018-11-19svc: Implement yield types 0 and -1Zach Hilman1-0/+60
2018-11-14kernel/thread: Deduplicate scheduler switching codeLioncash1-37/+11
The code in both places was the same verbatim, so we can extract it to a function to deduplicate the logic.
2018-10-30global: Use std::optional instead of boost::optional (#1578)Frederic L1-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
2018-10-20kernel/process: Make the handle table per-processLioncash1-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.
2018-10-15core_cpu: Make Cpu scheduler instances unique_ptrs instead of shared_ptrsLioncash1-8/+8
2018-10-12thread: Remove unnecessary memset from ResetThreadContext()Lioncash1-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.
2018-10-10kernel/thread: Use a regular pointer for the owner/current processLioncash1-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).
2018-10-05thread: Make the scheduler pointer a regular pointerbalika0111-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.
2018-10-04kernel/thread: Make all instance variables privateLioncash1-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.
2018-09-30kernel/process: Make data member variables privateLioncash1-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.
2018-09-25memory: Dehardcode the use of fixed memory range constantsLioncash1-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.
2018-09-21thread/process: Move TLS slot marking/freeing to the process classLioncash1-56/+2
Allows making several members of the process class private, it also avoids going through Core::CurrentProcess() just to retrieve the owning process.
2018-09-21kernel/thread: Use owner_process when setting the page table in SetupMainThread()Lioncash1-3/+3
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.
2018-09-18arm_interface: Remove ARM11-isms from the CPU interfaceLioncash1-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.
2018-09-15Port #4182 from Citra: "Prefix all size_t with std::"fearlessTobi1-1/+1
2018-09-12kernel/errors: Correct error codes for invalid thread priority and invalid processor IDLioncash1-2/+2
2018-08-31core/core: Replace includes with forward declarations where applicableLioncash1-1/+2
The follow-up to e2457418dae19b889b2ad85255bb95d4cd0e4bff, 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.
2018-08-29kernel: Eliminate kernel global stateLioncash1-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.
2018-08-25core: Namespace all code in the arm subdirectory under the Core namespaceLioncash1-2/+2
Gets all of these types and interfaces out of the global namespace.
2018-08-13Core::CoreTiming: add UnscheduleEventThreadsafeB3n301-1/+1
2018-08-13Kernel/Threads: Lock the HLE mutex when executing the wakeup callback.Subv1-0/+5
Another thread might be in the middle of a reschedule, thus altering the state of the schedulers.
2018-08-13Kernel/Thread: Always use the threadsafe option when scheduling wakeups.Subv1-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.
2018-08-12Kernel/Mutex: Don't duplicate threads in the mutex waiter list.Subv1-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.
2018-08-04kernel/thread: Fix potential crashes introduced in 26de4bb521b1ace7af76eff4f6956cb23ac0d58cLioncash1-0/+11
This amends cases where crashes can occur that were missed due to the odd way the previous code was set up (using 3DS memory regions that don't exist).
2018-08-03core/memory: Get rid of 3DS leftoversLioncash1-31/+2
Removes leftover code from citra that isn't needed.
2018-08-02kernel/thread: Make GetFreeThreadLocalSlot()'s loop indices size_tLioncash1-8/+5
Avoids using a u32 to compare against a range of size_t, which can be a source of warnings. While we're at it, compress a std::tie into a structured binding.
2018-08-02kernel/thread: Make GetFreeThreadLocalSlot() reference parameter a const referenceLioncash1-1/+2
This function only reads the data being referenced, it doesn't modify it, so we can turn the reference into a const reference.
2018-08-02kernel/thread: Make GetFreeThreadLocalSlot() internally linkedLioncash1-1/+1
This function isn't used outside of this translation unit, so we can make it internally linked.
2018-08-02kernel: Move object class to its own source filesLioncash1-1/+1
General moving to keep kernel object types separate from the direct kernel code. Also essentially a preliminary cleanup before eliminating global kernel state in the kernel code.
2018-07-31kernel: Remove unnecessary includesLioncash1-2/+4
Removes unnecessary direct dependencies in some headers and also gets rid of indirect dependencies that were being relied on to be included.
2018-07-24core_timing: Split off utility functions into core_timing_utilMerryMage1-0/+1
2018-07-21CPU: Save and restore the TPIDR_EL0 system register on every context switch.Subv1-0/+1
Note that there's currently a dynarmic bug preventing this register from being written.
2018-07-20thread: Convert ThreadStatus into an enum classLioncash1-24/+23
Makes the thread status strongly typed, so implicit conversions can't happen. It also makes it easier to catch mistakes at compile time.
2018-07-19core/memory, core/hle/kernel: Use std::move where applicableLioncash1-1/+1
Avoids pointless copies
2018-07-19core: Don't construct instance of Core::System, just to access its live instanceLioncash1-6/+6
This would result in a lot of allocations and related object construction, just to toss it all away immediately after the call. These are definitely not intentional, and it was intended that all of these should have been accessing the static function GetInstance() through the name itself, not constructed instances.
2018-07-03Update clang formatJames Rowe1-1/+1
2018-07-03Rename logging macro back to LOG_*James Rowe1-5/+5
2018-06-21Kernel/Arbiters: Implement WaitForAddressMichael Scire1-0/+6
2018-06-02Kernel/Threads: A thread waking up by timeout from a WaitProcessWideKey may already have an assigned lock owner.Subv1-2/+5
This situation may happen like so: Thread 1 with low priority calls WaitProcessWideKey with timeout. Thread 2 with high priority calls WaitProcessWideKey without timeout. Thread 3 calls SignalProcessWideKey - Thread 2 acquires the lock and awakens. - Thread 1 can't acquire the lock and is put to sleep with the lock owner being Thread 2. Thread 1's timeout expires, with the lock owner still being set to Thread 2.
2018-05-31Kernel/Thread: Corrected a typo that caused the affinity mask to never be changed.Subv1-2/+2
2018-05-30Kernel/Thread: Corrected a typo in an assert about the processor id.Subv1-1/+1
2018-05-11thread: Rename mask to affinity_masks.bunnei1-2/+2
2018-05-11thread: Support core change on ResumeFromWait and improve ChangeCore.bunnei1-37/+68
2018-05-11thread: Initialize ideal_core and mask members.bunnei1-0/+2
2018-05-11threading: Reschedule only on cores that are necessary.bunnei1-1/+1
2018-05-11thread: Implement ChangeCore function.bunnei1-1/+52
2018-05-11core: Implement multicore support.bunnei1-8/+8
2018-04-30core_timing: Namespace all functions and constants in core_timing's headerLioncash1-1/+2
All of these variables and functions are related to timings and should be within the namespace.
2018-04-27general: Convert assertion macros over to be fmt-compatibleLioncash1-2/+2
2018-04-26kernel: Migrate logging macros to fmt-compatible onesLioncash1-7/+8
2018-04-23Kernel: Implemented mutex priority inheritance.Subv1-2/+39
Verified with a hwtest and implemented based on reverse engineering. Thread A's priority will get bumped to the highest priority among all the threads that are waiting for a mutex that A holds. Once A releases the mutex and ownership is transferred to B, A's priority will return to normal and B's priority will be bumped.
2018-04-21Kernel: Remove unused ConditionVariable class.Subv1-9/+0
2018-04-21Kernel: Remove old and unused Mutex code.Subv1-3/+0
2018-04-21Kernel: Corrected the implementation of svcArbitrateLock and svcArbitrateUnlock.Subv1-1/+12
Switch mutexes are no longer kernel objects, they are managed in userland and only use the kernel to handle the contention case. Mutex addresses store a special flag value (0x40000000) to notify the guest code that there are still some threads waiting for the mutex to be released. This flag is updated when a thread calls ArbitrateUnlock. TODO: * Fix svcWaitProcessWideKey * Fix svcSignalProcessWideKey * Remove the Mutex class.
2018-03-31memory: Fix stack region.bunnei1-1/+1
2018-03-19thread: Add THREADSTATUS_WAIT_HLE_EVENT, remove THREADSTATUS_WAIT_ARB.bunnei1-18/+3
2018-03-16kernel: Move stack region outside of application heap.bunnei1-1/+1
2018-03-16MemoryState: Add additional memory states and improve naming.bunnei1-1/+1
2018-03-14core: Move process creation out of global state.bunnei1-2/+2
2018-02-27thread: Clear the process list on shutdown.Jules Blok1-1/+3
2018-02-18kernel: Use Scheduler class for threading.bunnei1-155/+14
2018-02-18kernel: Remove unused address_arbiter code.bunnei1-34/+0
2018-02-18 Kernel/IPC: Add a small delay after each SyncRequest to prevent thread starvation.Subv1-0/+1
Ported from citra PR #3091 The delay specified here is from a Nintendo 3DS, and should be measured in a Nintendo Switch. This change is enough to prevent Puyo Puyo Tetris's main thread starvation.
2018-02-14thread: Silence formatting specifier warningsLioncash1-2/+3
2018-01-09Kernel: Allow chaining WaitSynchronization calls inside a wakeup callback.Subv1-8/+17
2018-01-09CoreTiming: Reworked CoreTiming (cherry-picked from Citra #3119)B3n301-3/+2
* CoreTiming: New CoreTiming; Add Test for CoreTiming
2018-01-03arm: Remove SkyEye/Dyncom code that is ARMv6-only.bunnei1-4/+2
2017-12-31thread: Keep track of the initially created handle.bunnei1-1/+2
This is kinda crufty, but we need it for now to update guest state variables.
2017-12-30thread: Main thread should set thread handle to reg 1.bunnei1-1/+4
2017-12-30thread: Remove THUMB mode flag.bunnei1-1/+1
2017-12-30thread: Main thread should be ready by default, all others dormant.bunnei1-4/+3
2017-12-29kernel: Various 64-bit fixes in memory/process/threadbunnei1-5/+5
2017-11-01hle: Use Switch formatted result codes.bunnei1-3/+2
2017-10-20hle: Fix QueryMemory response for MemoryInfo.bunnei1-1/+1
2017-10-10loader: Various improvements for NSO/NRO loaders.bunnei1-1/+1
2017-10-01Kernel/Thread: Added a helper function to get a thread's command buffer VAddr.Subv1-0/+6
2017-09-30kernel: Various threading fixes to support 64-bit addressing.bunnei1-3/+3
2017-09-30Fixed type conversion ambiguityHuw Pascoe1-9/+9
2017-09-28Kernel/Threads: When putting a thread to wait, specify a function to execute when it is awoken.Subv1-3/+10
This change makes for a clearer (less confusing) path of execution in the scheduler, now the code to execute when a thread awakes is closer to the code that puts the thread to sleep (WaitSynch1, WaitSynchN). It also allows us to implement the special wake up behavior of ReplyAndReceive without hacking up WaitObject::WakeupAllWaitingThreads. If savestates are desired in the future, we can change this implementation to one similar to the CoreTiming event system, where we first register the callback functions at startup and assign their identifiers to the Thread callback variable instead of directly assigning a lambda to the wake up callback variable.
2017-09-27Kernel/Thread: Allow specifying which process a thread belongs to when creating it.Subv1-8/+9
Don't automatically assume that Thread::Create will only be called when the parent process is currently scheduled. This assumption will be broken when applets or system modules are loaded.
2017-09-24memory: Add GetCurrentPageTable/SetCurrentPageTableMerryMage1-7/+4
Don't expose Memory::current_page_table as a global.
2017-09-15Kernel/Threads: Don't clear the CPU instruction cache when performing a context switch from an idle thread into a thread in the same process.Subv1-1/+3
We were unnecessarily clearing the cache when going from Process A -> Idle -> Process A, this caused extreme performance regressions.
2017-09-10Kernel/Memory: Switch the current page table when a new process is scheduled.Subv1-0/+10
2017-08-22Kernel/Threads: Don't immediately switch to the new main thread when loading a new process.Subv1-5/+1
This is necessary for loading multiple processes at the same time. The main thread will be automatically scheduled when necessary once the scheduler runs.
2017-06-19ResultVal: Remove MoveFrom()Yuri Kunde Schlesner1-2/+2
Replace it with std::move(result_val).Unwrap(), or Foo().Unwrap() in case you already have an rvalue.
2017-05-30Kernel: Move HandleTable to a separate fileYuri Kunde Schlesner1-0/+1
2017-05-25Kernel: Centralize error definitions in errors.hYuri Kunde Schlesner1-8/+16
2017-01-11Threads: Check the process' resource limit for the max allowed priority when creating a thread and remove the priority clamping code.Subv1-8/+2
2017-01-11Thread: Added priority range checking to svcSetThreadPriority and removed priority clamping code from Thread::SetPriority.Subv1-18/+2
2017-01-06Kernel: Don't attempt to yield execution in SleepThread(0) if there are no available threads to run.Subv1-0/+4
With this we avoid an useless temporary deschedule of the current thread.
2017-01-05Kernel: Remove some unused functions.Subv1-23/+0
2017-01-05Kernel: Removed the priority boost code for starved threads.Subv1-27/+0
After hwtesting and reverse engineering the kernel, it was found that the CTROS scheduler performs no priority boosting for threads like this, although some other forms of scheduling priority-starved threads might take place. For example, it was found that hardware interrupts might cause low-priority threads to run if the CPU is preempted in the middle of an SVC handler that deschedules the current (high priority) thread before scheduling it again.
2017-01-05Kernel: Add some asserts to enforce the invariants in the scheduler.Subv1-2/+5
2017-01-05Kernel: Remove Thread::wait_objects_index and use wait_objects to hold all the objects that a thread is waiting on.Subv1-0/+5
2017-01-04Kernel: Use different thread statuses when a thread calls WaitSynchronization1 and WaitSynchronizationN with wait_all = true.Subv1-4/+7
This commit removes the overly general THREADSTATUS_WAIT_SYNCH and replaces it with two more granular statuses: THREADSTATUS_WAIT_SYNCH_ANY when a thread waits on objects via WaitSynchronization1 or WaitSynchronizationN with wait_all = false. THREADSTATUS_WAIT_SYNCH_ALL when a thread waits on objects via WaitSynchronizationN with wait_all = true.
2017-01-04Kernel/Mutex: Propagate thread priority changes to other threads inheriting the priority via mutexesSubv1-4/+17
2017-01-04Kernel/Mutex: Implemented priority inheritance.Subv1-3/+3
The implementation is based on reverse engineering of the 3DS's kernel. A mutex holder's priority will be temporarily boosted to the best priority among any threads that want to acquire any of its held mutexes. When the holder releases the mutex, it's priority will be boosted to the best priority among the threads that want to acquire any of its remaining held mutexes.
2017-01-04Kernel: Object ShouldWait and Acquire calls now take a thread as a parameter.Subv1-3/+3
This will be useful when implementing mutex priority inheritance.
2016-12-22ThreadContext: Move from "core" to "arm_interface".bunnei1-3/+3
2016-12-22core: Replace "AppCore" nomenclature with just "CPU".bunnei1-3/+3
2016-12-22core: Remove HLE module, consolidate code & various cleanups.bunnei1-4/+1
2016-12-22core: Consolidate core and system state, remove system module & cleanups.bunnei1-3/+3
2016-12-17Thread: remove the thread from the thread list when exitingwwylele1-2/+9
2016-12-10Properly remove a thread from its wait_objects' waitlist when it is awoken by a timeout.Subv1-0/+4
2016-12-04Threading: Reworked the way our scheduler works.Subv1-94/+3
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.
2016-10-20Fix typosRicardo de Almeida Gonzaga1-1/+1
2016-09-22implement wait tree widgetwwylele1-0/+4
2016-09-21Use negative priorities to avoid special-casing the self-includeYuri Kunde Schlesner1-1/+1
2016-09-21Remove empty newlines in #include blocks.Emmanuel Gil Peyrot1-3/+1
This makes clang-format useful on those. Also add a bunch of forgotten transitive includes, which otherwise prevented compilation.
2016-09-19Manually tweak source formatting and then re-run clang-formatYuri Kunde Schlesner1-4/+2
2016-09-18Sources: Run clang-format on everything.Emmanuel Gil Peyrot1-49/+65
2016-09-15arm: ResetContext shouldn't be part of ARM_Interface.bunnei1-1/+17
2016-06-04Thread: update timeout when rerunning WaitSynchwwylele1-0/+49
2016-05-30Switch context on the same thread if necessarywwylele1-2/+6
2016-05-21Kernel/Thread: Remove use of Memory::GetPointerMerryMage1-1/+1
2016-05-17Set fpscr for new threadsJannik Vogel1-0/+2
2016-05-07Kernel/Threads: Dynamically allocate the TLS region for threads in the BASE region of the linear heap.Subv1-17/+67
Each thread gets a 0x200-byte area from the 0x1000-sized page, when all 8 thread slots in a single page are used up, the kernel allocates a new page to hold another 8 entries. This is consistent with what the real kernel does.
2016-03-21hle: Get rid of global access to g_rescheduleLioncash1-1/+2
This shouldn't be directly exposed if there's already a partial API that operates on it. We can just provide the rest of that API.
2015-12-28SVC: Fixed ArbitrateAddress to behave as it does on hardware.Subv1-1/+1
This was verified with hwtests that i plan to upload later on.
2015-12-01Kernel: Implement svcGetSystemInfoYuri Kunde Schlesner1-0/+3
This makes smealum/ctrulib@b96dd51d3349961189d4ab1bc2a5c45deff21c09 work with Citra.
2015-10-07Silence -Wsign-compare warnings.Rohit Nirmal1-1/+1
2015-08-16Kernel: Implement svcGetProcessInfo in a basic wayYuri Kunde Schlesner1-1/+3
This also adds some basic memory usage accounting. These two types are used by Super Smash Bros. during startup.
2015-07-26dyncom: Rename armdefs.h to armstate.hLioncash1-1/+1
2015-07-21Kernel/Scheduling: Clean up a thread's wait_objects when its scheduled.Subv1-0/+8
They'll be reset if needed during the next svcWaitSynchronization call (if there's any pending)
2015-07-17Ensure all kernel objects are released during shutdownYuri Kunde Schlesner1-7/+14
This commit fixes several kernel object leaks. The most severe of them was threads not being removed from the private handle table used for CoreTiming events. This resulted in Threads never being released, which in turn held references to Process, causing CodeSets to never be freed when loading other applications.
2015-06-17kernel: Fix svcWaitSynch to always acquire requested wait objects.bunnei1-50/+26
2015-05-29Remove every trailing whitespace from the project (but externals).Emmanuel Gil Peyrot1-4/+4
2015-05-21Kernel: Move reschedules from SVCs to actual mechanisms that reschedule.bunnei1-0/+6
2015-05-15Memmap: Re-organize memory function in two filesYuri Kunde Schlesner1-1/+1
memory.cpp/h contains definitions related to acessing memory and configuring the address space mem_map.cpp/h contains higher-level definitions related to configuring the address space accoording to the kernel and allocating memory.
2015-05-14thread: Fix a conditional check in RescheduleLioncash1-1/+1
2015-05-12Thread: Remove the idle threadYuri Kunde Schlesner1-27/+19
Instead just use nullptr to represent no thread is active.
2015-05-12Core/Memory: Add TLS support for creating up to 300 threadsSubv1-6/+15
2015-05-12Core/Scheduling: Prepare the new priority in the thread queue when svcSetPriority is calledSubv1-0/+2
2015-05-11Core/HLE: Implemented the SVCs GetProcessId and GetProcessIdOfThreadSubv1-0/+2
2015-05-11Thread: Correctly set main thread initial stack positionYuri Kunde Schlesner1-2/+2
2015-05-11fixup! Set the TLS address in the schedulerSubv1-2/+5
2015-05-11Core/Memory: Give every emulated thread it's own TLS area.Subv1-1/+9
The TLS area for thread T with id Ti is located at TLS_AREA_VADDR + (Ti - 1) * 0x200. This allows some games like Mario Kart 7 to continue further.
2015-05-09Memory: Re-organize and rename memory area address constantsYuri Kunde Schlesner1-2/+3
2015-05-07Common: Remove common.hYuri Kunde Schlesner1-1/+3
2015-05-02Kernel: Properly initialize and shutdown all modules.bunnei1-2/+8
2015-04-10Kernel: Implemented priority inheritance for mutexes.bunnei1-3/+7
2015-04-10Thread: Implement priority boost for starved threads.bunnei1-12/+36
SVC: Return correct error code on invalid CreateThread processor ID. SVC: Assert when creating a thread with an invalid userland priority.
2015-02-20Misc cleanup of common and related functionsarchshift1-2/+3
2015-02-11Asserts: break/crash program, fit to style guide; log.h->assert.harchshift1-8/+6
Involves making asserts use printf instead of the log functions (log functions are asynchronous and, as such, the log won't be printed in time) As such, the log type argument was removed (printf obviously can't use it, and it's made obsolete by the file and line printing) Also removed some GEKKO cruft.
2015-02-10Scheduler refactor Pt. 1Kevin Hartman1-185/+175
* Simplifies scheduling logic, specifically regarding thread status. It should be much clearer which statuses are valid for a thread at any given point in the system. * Removes dead code from thread.cpp. * Moves the implementation of resetting a ThreadContext to the corresponding core's implementation. Other changes: * Fixed comments in arm interfaces. * Updated comments in thread.cpp * Removed confusing, useless, functions like MakeReady() and ChangeStatus() from thread.cpp. * Removed stack_size from Thread. In the CTR kernel, the thread's stack would be allocated before thread creation.
2015-02-02Kernel: Stop creating useless Handles during object creationYuri Kunde Schlesner1-8/+0
They're finally unnecessary, and will stop cluttering the application's handle table.
2015-02-02Kernel: Make WaitObjects share ownership of Threads waiting on themYuri Kunde Schlesner1-0/+3
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.)
2015-02-02Explicitly instantiate constructors/destructors for Kernel objectsYuri Kunde Schlesner1-2/+2
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.)
2015-02-02Mutex: Replace g_mutex_held_locks with a set inside ThreadYuri Kunde Schlesner1-0/+3
2015-02-02Kernel: Introduce unique Object ids for debuggingYuri Kunde Schlesner1-5/+5
2015-02-02Kernel: Use separate Handle tables for CoreTiming userdataYuri Kunde Schlesner1-11/+11
This is to support the removal of GetHandle soon
2015-02-02Thread: Modernize two functions that slipped through previous rebasesYuri Kunde Schlesner1-5/+4
2015-02-01arm: Clean up ARMul_StateLioncash1-1/+1
Remove unnecessary/unused struct variables.
2015-01-22Thread: Fix WaitSynchronization1 to not set register 1 on thread wakeup.bunnei1-15/+28
2015-01-22Thread: Use std::find in CheckWait_WaitObject.bunnei1-4/+5
2015-01-22Mutex: Cleanup and remove redundant code.bunnei1-1/+1
2015-01-22Kernel: Renamed some functions for clarity.bunnei1-1/+1
- ReleaseNextThread->WakeupNextThread - ReleaseAllWaitingThreads->WakeupAllWaitingThreads.
2015-01-22Kernel: Changed "ShouldWait" to return bool and "Acquire" to return void.bunnei1-7/+5
2015-01-22WaitObject: Renamed "Wait" to "ShouldWait", made "ShouldWait" and "Acquire" pure virtual.bunnei1-2/+2
2015-01-22Kernel: Moved Wait and Acquire to WaitObject, added way to retrieve a WaitObject safely.bunnei1-1/+1
2015-01-22AddressArbiter: Changed to Kernel::Object, big cleanup, removed code that made no sense.bunnei1-17/+25
2015-01-22Kernel: Get rid of WaitTypes and simplify lots of code, removing hacks.bunnei1-46/+19
2015-01-22WaitSynchronizationN: Refactor to fix several bugsbunnei1-33/+28
- Separate wait checking from waiting the current thread - Resume thread when wait_all=true only if all objects are available at once - Set output to correct wait object index when there are duplicate handles
2015-01-22Kernel: Separate WaitSynchronization into Wait and Acquire methods.bunnei1-1/+5
2015-01-22WaitSynchronizationN: Implement return valuesbunnei1-19/+75
2015-01-22Thread: Keep track of multiple wait objects.bunnei1-11/+24
2015-01-22Kernel: Added WaitObject and changed "waitable" objects inherit from it.bunnei1-9/+2
2015-01-11Thread: Prevent waking a thread multiple times.Subv1-0/+3
If a thread was woken up by something, cancel the wakeup timeout.
2015-01-09Kernel: Start using boost::intrusive_ptr for lifetime managementYuri Kunde Schlesner1-33/+30
2015-01-09Thread: Fix nullptr access in a logging functionYuri Kunde Schlesner1-1/+2
2015-01-09Thread: Rename thread_queue => thread_listYuri Kunde Schlesner1-6/+6
2015-01-09Thread: Reduce use of Handles and move some funcs to inside the class.Yuri Kunde Schlesner1-213/+127
2015-01-09Kernel: Move Thread's definition to the header fileYuri Kunde Schlesner1-51/+9
2015-01-09Move ThreadContext to core/core.h and deal with the falloutYuri Kunde Schlesner1-4/+5
2015-01-09SVC: Fixed SleepThread.Subv1-8/+32
It will now properly wait the specified number of nanoseconds and then wake up the thread.
2015-01-08Threads: Use a dummy idle thread when no other are ready.Subv1-1/+22
This thread will not actually execute instructions, it will only advance the timing/events and try to yield immediately to the next ready thread, if there aren't any ready threads then it will be rescheduled and start its job again.
2015-01-07Common: Clean up ThreadQueueListYuri Kunde Schlesner1-1/+1
Replace all the C-style complicated buffer management with a std::deque. In addition to making the code easier to understand it also adds support for non-POD IdTypes. Also clean the rest of the code to follow our code style.
2014-12-28Kernel: New handle managerYuri Kunde Schlesner1-1/+2
This handle manager more closely mirrors the behaviour of the CTR-OS one. In addition object ref-counts and support for DuplicateHandle have been added. Note that support for DuplicateHandle is still experimental, since parts of the kernel still use Handles internally, which will likely cause troubles if two different handles to the same object are used to e.g. wait on a synchronization primitive.
2014-12-28Kernel: Replace GetStaticHandleType by HANDLE_TYPE constantsYuri Kunde Schlesner1-2/+2
2014-12-28Rename ObjectPool to HandleTableYuri Kunde Schlesner1-11/+11
2014-12-21License changepurpasmart961-1/+1
2014-12-21Thread: Wait current thread on svc_SleepThreadbunnei1-20/+33
- Removed unused VBLANK sleep mode - Added error log for bad context switch - Renamed VerifyWait to CheckWaitType to be more clear
2014-12-20Kernel: Implement support for current thread pseudo-handleYuri Kunde Schlesner1-2/+1
This boots a few (mostly Nintendo 1st party) games further.
2014-12-13Convert old logging calls to new logging macrosYuri Kunde Schlesner1-12/+12
2014-12-09Thread: Fixed to wait on address when in arbitration.bunnei1-10/+19
2014-12-07Mutex: Release all held mutexes when a thread exits.Subv1-0/+4
2014-12-04Threads: Remove a redundant function.Subv1-9/+1
Use the next_thread_id variable directly.
2014-12-04Threads: Implemented a sequential thread idSubv1-3/+13
2014-12-04SVC: Implemented GetThreadId.Subv1-0/+16
For now threads are using their Handle value as their Id, it should not really cause any problems because Handle values are unique in Citra, but it should be changed. I left a ToDo there because this is not correct behavior as per hardware.
2014-11-26Thread: Check that thread is actually in "wait state" when verifying wait.bunnei1-1/+1
2014-11-24Use pointers instead of passing handles around in some functions.Yuri Kunde Schlesner1-19/+15
2014-11-24Remove duplicated docs/update them for changed parameters.Yuri Kunde Schlesner1-5/+0
2014-11-24HLE: Revamp error handling throrough the HLE codeYuri Kunde Schlesner1-21/+30
All service calls in the CTR OS return result codes indicating the success or failure of the call. Previous to this commit, Citra's HLE emulation of services and the kernel universally either ignored errors or returned dummy -1 error codes. This commit makes an initial effort to provide an infrastructure for error reporting and propagation which can be use going forward to make HLE calls accurately return errors as the original system. A few parts of the code have been updated to use the new system where applicable. One part of this effort is the definition of the `ResultCode` type, which provides facilities for constructing and parsing error codes in the structured format used by the CTR. The `ResultVal` type builds on `ResultCode` by providing a container for values returned by function that can report errors. It enforces that correct error checking will be done on function returns by preventing the use of the return value if the function returned an error code. Currently this change is mostly internal since errors are still suppressed on the ARM<->HLE border, as a temporary compatibility hack. As functionality is implemented and tested this hack can be eventually removed.
2014-11-19Remove trailing spaces in every file but the ones imported from SkyEye, AOSP or generatedEmmanuel Gil Peyrot1-19/+19
2014-11-19Add static to some variablesLioncash1-22/+22
2014-10-26Add `override` keyword through the code.Yuri Kunde Schlesner1-4/+4
This was automated using `clang-modernize`.
2014-09-09core: Prune redundant includesarchshift1-3/+0
2014-08-31Threading: Fix thread starting to execute first instruction correctly.bunnei1-0/+5
2014-08-28Threading: Fix thread starting to execute first instruction correctly.bunnei1-0/+5
2014-08-18Core: Alter the kernel string functions to use std::string instead of const char*.Lioncash1-10/+7
Most functions already operate on std::strings. This also removes the need to manually null terminate thread names.
2014-08-07Thread: Added more descriptive comment to WaitCurrentThread.bunnei1-1/+5
2014-07-09Thread: Added functions to resume threads from address arbitration.bunnei1-0/+37
Thread: Cleaned up arbitrate address functions. Thread: Cleaned up ArbitrateAllThreads function.
2014-06-13Thread: Renamed occurrences of "t" to "thread" to improve readability.bunnei1-48/+45
2014-06-13Thread: Cleaned up VerifyWait, fixed issue where nullptr msg could unnecessarily be logged.bunnei1-9/+7
2014-06-13HLE: Removed usnused EatCycles function.bunnei1-9/+0
2014-06-13Thread: Moved position of * in arguments.bunnei1-2/+2
2014-06-13Thread: Updated VerifyWait to be more readable (but functionally the same).bunnei1-4/+3
2014-06-13HLE: Updated all uses of NULL to nullptr (to be C++11 compliant)bunnei1-7/+7
2014-06-13HLE: Updated various handle debug assertions to be more clear.bunnei1-2/+2
2014-06-13Kernel: Updated several member functions to be constbunnei1-3/+3
2014-06-13Thread: Fixed bug with ResetThread where cpu_registers[15] was being incorrectly setbunnei1-1/+1
2014-06-13Kernel: Made SyncRequest not pure virtual, with a default implementation of error (as this is not required for all kernel objects)bunnei1-10/+0
2014-06-13Kernel: Added real support for thread and event blockingbunnei1-33/+88
- SVC: Added ExitThread support - SVC: Added SignalEvent support - Thread: Added WAITTYPE_EVENT for waiting threads for event signals - Thread: Added support for blocking on other threads to finish (e.g. Thread::Join) - Thread: Added debug function for printing current threads ready for execution - Thread: Removed hack/broken thread ready state code from Kernel::Reschedule - Mutex: Moved WaitCurrentThread from SVC to Mutex::WaitSynchronization - Event: Added support for blocking threads on event signalling Kernel: Added missing algorithm #include for use of std::find on non-Windows platforms.
2014-06-02svc: added GetThreadPriority and SetThreadPriority, added (incomplete) DuplicateHandle supportbunnei1-0/+45
2014-06-02kernel: changed main thread priority to default, updated Kernel::Reschedule to use PrepareReschedulebunnei1-3/+3
2014-06-01thread: updated Reschedule to sit at a synchronization barrier when no other threads are ready for executionbunnei1-0/+18
2014-05-27kernel: added WaitSynchronization method to Kernel::Objectbunnei1-0/+11
2014-05-27kernel: updated SyncRequest to take boolean thread wait result as a parameterbunnei1-2/+6
2014-05-27kernel: add a SyncRequest method to KernelObject for use with svcSendSyncRequestbunnei1-0/+5
2014-05-23thread: renamed "WaitCurThread" to "WaitCurrentThread", removed unused "reason" argumentbunnei1-2/+2
2014-05-23thread: removed unused SwitchContext/Reschedule reason field, added missing arg parameter to SVC CreateThreadbunnei1-3/+3
2014-05-23kernel: refactored function naming to remove "__" prefixbunnei1-39/+39
2014-05-23thread: moved ThreadStatus/WaitType to header, added support for arg on CreateThread, added correct CPSR resetbunnei1-34/+15
2014-05-22thread: fixed bug where result of __NextThread was not being properly checked when NULLbunnei1-1/+1
2014-05-21thread: added correct lowest thread priority, added a thread priority check, and added some commentsbunnei1-0/+3
2014-05-21thread: exposed ResumeThreadFromWait function for use in other kernel modulesbunnei1-8/+8
2014-05-21thread: moved threading calls to the Kernel namespacebunnei1-89/+95
2014-05-21ARM_Interface: added SaveContext and LoadContext functions for HLE thread switchingbunnei1-36/+2
2014-05-21renamed "syscall" module to "svc" (more accurate naming)bunnei1-1/+1
2014-05-21thread: whitespace change - fixed * and & placementbunnei1-25/+25
2014-05-21- created a Kernel namespacebunnei1-9/+9
- cleaned up Kernel code a bit (moved stuff into namespace, fixed whitespace issues) - added handle types for all different CTROS handles
2014-05-19- moved Handle/Result definitions to kernel.hbunnei1-2/+0
- added ResetType enum
2014-05-17changed a commentbunnei1-1/+1
2014-05-17- added enum ThreadProcessorIdbunnei1-51/+90
- reorganized some kernel thread functions - added placeholder __KernelWaitThread_Synchronization function
2014-05-17- replaced KERNELOBJECT_MAX_NAME_LENGTH with KERNEL_MAX_NAME_LENGTHbunnei1-4/+5
- added KERNEL_DEFAULT_STACK_SIZE definition (0x4000)
2014-05-16completely gutted/refactored threading code to be simplerbunnei1-616/+228
2014-05-15- added helper function for __KernelCreateThreadbunnei1-4/+70
- added __KernelSwitchToThread for enabling a thread - added __KernelRotateThreadReadyQueue
2014-05-14fixed thread reset to not set stack addressbunnei1-1/+1
2014-05-14various cleanups / remove unused codebunnei1-65/+28
2014-05-14added a bunch of threading code, recycled from PPSSPP, with lots of hacks in for 3DS... doesn't really do much yet. Just a jumping off pointbunnei1-64/+524
2014-05-10added initial kernel/thread modulesbunnei1-0/+228