summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_thread.h (unfollow)
Commit message (Collapse)AuthorFilesLines
2022-11-04service_thread: register service threads to the logical owner processLiam1-1/+1
2022-10-25kernel: refactor dummy thread wakeupsLiam1-4/+4
2022-10-19core: hle: kernel: k_thread: Implement thread termination DPC.bunnei1-0/+4
2022-07-15kernel: fix single-core preemption pointsLiam1-1/+0
2022-07-15kernel: fix issues with single core modeLiam1-24/+0
2022-07-15kernel: use KScheduler from mesosphereLiam1-0/+5
2022-07-02common/fiber: make fibers easier to useLiam1-2/+1
2022-06-27core: Replace all instances of ResultCode with Resultgerman771-31/+30
2022-06-23kernel: make current thread pointer thread localLiam1-0/+1
2022-06-18kernel: wait for threads to stop on pauseLiam1-0/+2
2022-06-02core/debugger: Support reading guest thread namesLiam1-0/+10
2022-06-01core/debugger: Improved stepping mechanism and misc fixesLiam1-0/+15
2022-04-23general: Convert source file copyright comments over to SPDXMorph1-3/+2
This formats all copyright comments according to SPDX formatting guidelines. Additionally, this resolves the remaining GPLv2 only licensed files by relicensing them to GPLv2.0-or-later.
2022-04-12core: hle: kernel: k_thread: Rework dummy thread waiting.bunnei1-4/+6
2022-04-12hle: kernel: Use std::mutex instead of spin locks for most kernel locking.bunnei1-1/+2
2022-04-04k_thread: Fix data racelat9nq1-1/+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-15core: hle: kernel: k_thread: Update to reflect tree changes.bunnei1-3/+3
2022-01-22hle: kernel: KThread: Ensure host (dummy) threads block on locking.bunnei1-0/+13
- 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: Decrease DummyThread priority to ensure it is never scheduled.bunnei1-0/+1
2022-01-21hle: kernel: KThread: Rename thread_type_for_debugging -> thread_type.bunnei1-3/+3
- 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/+6
- 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-2/+2
- This makes our implementations of these more closely match HOS.
2021-12-31core: hle: kernel: Implement thread pinning.bunnei1-1/+5
- 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-07hle: kernel: k_thread: Rename sleeping_queue -> wait_queue.bunnei1-6/+2
2021-12-07hle: kernel: k_thread: Treat dummy threads as a special type.bunnei1-0/+1
2021-12-07hle: kernel: Add a flag for indicating that the kernel is currently shutting down.bunnei1-0/+4
2021-12-07hle: kernel: Cleanup to match coding style.bunnei1-2/+2
2021-12-07hle: kernel: KThread: Migrate to updated KThreadQueue (part 1).bunnei1-2/+2
2021-12-07hle: kernel: KThread: Remove tracking of sync object from threads.bunnei1-12/+0
2021-12-07hle: kernel: Update KThreadQueue and migrate KSynchronizationObject.bunnei1-0/+27
2021-12-07core: hle: kernel: Disable dispatch count tracking on single core.bunnei1-3/+8
- This would have limited value, and would be a mess to handle properly.
2021-12-07core: hle: kernel: k_thread: Mark KScopedDisableDispatch as nodiscard.bunnei1-1/+1
2021-12-07core: hle: kernel: k_thread: Add KScopedDisableDispatch.bunnei1-0/+31
2021-08-26Revert "kernel: Various improvements to scheduler"bunnei1-36/+0
2021-08-14core: hle: kernel: Disable dispatch count tracking on single core.bunnei1-3/+8
- This would have limited value, and would be a mess to handle properly.
2021-08-07core: hle: kernel: k_thread: Mark KScopedDisableDispatch as nodiscard.bunnei1-1/+1
2021-08-07core: hle: kernel: k_thread: Add KScopedDisableDispatch.bunnei1-0/+31
2021-06-02general: Replace RESULT_SUCCESS with ResultSuccessMorph1-1/+1
Transition to PascalCase for result names.
2021-05-29kernel: Add missing override specifiersLioncash1-5/+5
Over the course of the kernel refactoring a tiny bit of missing overrides slipped through review, so we can add these. While we're at it, we can remove redundant virtual keywords where applicable as well.
2021-05-08kernel: Eliminate variable shadowingLioncash1-3/+3
Now that the large kernel refactor is merged, we can eliminate the remaining variable shadowing cases.
2021-05-06hle: kernel: Rename Process to KProcess.bunnei1-8/+8
2021-05-06hle: kernel: Remove deprecated Object class.bunnei1-15/+0
2021-05-06hle: kernel: Migrate KThread to KAutoObject.bunnei1-57/+43
2021-04-12k_thread: Remove [[nodiscard]] attribute from ClearWaitCancelled()Lioncash1-1/+1
This function has a void return value, so this attribute doesn't apply to it.
2021-03-21hle: kernel: Migrate some code from Common::SpinLock to KSpinLock.bunnei1-2/+2
2021-03-06hle: kernel: KThread: Rework dummy threads & fix memory leak.bunnei1-4/+20
- 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-8/+2
2021-02-27core: Switch to unique_ptr for usage of Common::Fiber.bunnei1-2/+8
- 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-01-29yuzu: debugger: Ignore HLE threads.bunnei1-0/+5
2021-01-29hle: kernel: KScheduler: Introduce thread context_guard.bunnei1-0/+1
2021-01-29hle: kernel: Recode implementation of KThread to be more accurate.bunnei1-282/+308
2021-01-29hle: kernel: KThread: Clean up thread priorities.bunnei1-22/+0
2021-01-29hle: kernel: KThread: Reorganize thread priority defaults.bunnei1-9/+3
2021-01-29hle: kernel: KThread: Fix ThreadType definition.bunnei1-4/+7
2021-01-29hle: kernel: Move single core "phantom mode" out of KThread.bunnei1-9/+0
- This is a workaround that does not belong in a kernel primitive.
2021-01-29hle: kernel: KThread: Remove thread types that do not exist.bunnei1-13/+2
2021-01-29core: hle: kernel: Rename Thread to KThread.bunnei1-33/+32
2021-01-11hle: kernel: thread: Preserve thread wait reason for debugging only.bunnei1-0/+21
- This is decoupled from core functionality and used for debugging only.
2021-01-11core: hle: Integrate new KConditionVariable and KAddressArbiter implementations.bunnei1-121/+197
2021-01-11hle: kernel: thread: Replace ThreadStatus/ThreadSchedStatus with a single ThreadState.bunnei1-41/+34
- This is how the real kernel works, and is more accurate and simpler.
2021-01-11core: hle: kernel: Update KSynchronizationObject.bunnei1-85/+46
2020-12-06hle: kernel: Thread: Various style fixes based on code review feedback.bunnei1-22/+25
2020-12-06hle: kernel: Rewrite scheduler implementation based on Mesopshere.bunnei1-27/+80
2020-12-06hle: kernel: Port KAffinityMask from Mesosphere.bunnei1-3/+3
2020-11-29hle: kernel: thread: Remove unused "Running" state.bunnei1-1/+0
2020-11-29hle: kernel: multicore: Replace n-JITs impl. with 4 JITs.bunnei1-5/+0
2020-10-21Revert "core: Fix clang build"bunnei1-3/+3
2020-10-18core: Fix clang buildLioncash1-3/+3
Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795
2020-07-16kernel/thread: Remove unimplemented function prototypeLioncash1-2/+0
This isn't used, so it can be removed.
2020-07-15kernel/thread: Remove global GetCurrentThread()Lioncash1-5/+0
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-55/+1
2020-06-27HLE_IPC: Correct HLE Event behavior on timeout.Fernando Sahmkow1-0/+9
2020-06-27Thread: Release the ARM Interface on exitting.Fernando Sahmkow1-0/+5
2020-06-27General: Move ARM_Interface into Threads.Fernando Sahmkow1-1/+7
2020-06-27SingleCore: Move Host Timing from a sepparate thread to main cpu thread.Fernando Sahmkow1-0/+9
2020-06-27General: Fix microprofile on dynarmic/svc, fix wait tree showing which threads were running.Fernando Sahmkow1-0/+18
2020-06-27Kernel: Rewind on SVC change.Fernando Sahmkow1-0/+10
2020-06-27Kernel: Preempt Single core on redudant yields.Fernando Sahmkow1-4/+5
2020-06-27Scheduler: Correct yields.Fernando Sahmkow1-0/+4
2020-06-27SVC: Correct SetThreadActivity.Fernando Sahmkow1-8/+14
2020-06-27SCC: Small corrections to CancelSynchronizationFernando Sahmkow1-0/+9
2020-06-27SVC: Correct svcWaitForAddress and svcSignalToAddress.Fernando Sahmkow1-0/+9
2020-06-27Kernel: Correct Signal on Thread Death and Setup Sync Objects on Thread for DebuggingFernando Sahmkow1-7/+7
2020-06-27Core: Correct HLE Event Callbacks and other issues.Fernando Sahmkow1-7/+9
2020-06-27SVC: Correct SendSyncRequest.Fernando Sahmkow1-29/+53
2020-06-27SVC: Correct SignalEvent, ClearEvent, ResetSignal, WaitSynchronization, CancelSynchronization, ArbitrateLockFernando Sahmkow1-2/+15
2020-06-27SVC: Correct GetThreadPriority, SetThreadPriority, GetThreadCoreMask, SetThreadCoreMask, GetCurrentProcessorNumberFernando Sahmkow1-2/+1
2020-06-27SVC: Correct CreateThread, StartThread, ExitThread, SleepThread.Fernando Sahmkow1-4/+8
2020-06-27General: Recover Prometheus project from harddrive failure Fernando Sahmkow1-14/+67
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-03-03core: Implement separate A32/A64 ARM interfaces.bunnei1-6/+16
2020-02-22Kernel: Rename ThreadCallbackHandleTable and Setup Thread Ids on Kernel.Fernando Sahmkow1-1/+5
2020-02-11Kernel: Refactor synchronization to better match REFernando Sahmkow1-0/+1
2020-02-11Kernel: Change WaitObject to Synchronization object. In order to better reflect RE.Fernando Sahmkow1-11/+11
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-16Kernel: Correct Cancel Synchronization.Fernando Sahmkow1-0/+9
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-10-15Kernel Thread: Cleanup THREADPROCESSORID_DONT_UPDATE.Fernando Sahmkow1-3/+0
2019-10-15Kernel: Address Feedback 2Fernando Sahmkow1-6/+3
2019-10-15Kernel: Address Feedback.Fernando Sahmkow1-4/+12
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/+3
2019-10-15Kernel: Clang FormatFernando Sahmkow1-1/+1
2019-10-15Scheduler: Implement Yield Count and Core migration on Thread Preemption.Fernando Sahmkow1-0/+9
2019-10-15Scheduler: Add protections for Yield bombingFernando Sahmkow1-3/+3
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-5/+10
2019-10-15Addapt thread class to the new SchedulerFernando Sahmkow1-1/+54
2019-07-04kernel/process: Decouple TLS handling from threadsLioncash1-15/+1
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-04-29kernel/thread: Update thread processor ID flagsLioncash1-6/+15
Adds the missing flags to the enum and documents them.
2019-04-17kernel/thread: Unify wait synchronization typesLioncash1-15/+13
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-3/+9
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-15svc: Specify handle value in thread's nameLioncash1-0/+5
Allows the handle to be seen alongside the entry point.
2019-04-15kernel/thread: Remove BoostPriority()Lioncash1-6/+0
This is a holdover from Citra that currently remains unused, so it can be removed from the Thread interface.
2019-04-14kernel/thread: Remove unused guest_handle member variableLioncash1-7/+0
This member variable is entirely unused. It was only set but never actually utilized. Given that, we can remove it to get rid of noise in the thread interface.
2019-04-11kernel: Make handle type declarations constexprLioncash1-1/+1
Some objects declare their handle type as const, while others declare it as constexpr. This makes the const ones constexpr for consistency, and prevent unexpected compilation errors if these happen to be attempted to be used within a constexpr context.
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: Make parameter of GetWaitObjectIndex() const qualifiedLioncash1-1/+1
The pointed to member is never actually modified, so it can be made const.
2019-03-20Add CondVar Thread State.Fernando Sahmkow1-1/+2
2019-03-16kernel/thread: Move thread exiting logic from ExitCurrentThread to svcExitThreadLioncash1-5/+0
Puts the operation on global state in the same places as the rest of the svc calls.
2019-03-16kernel/thread: Migrate WaitCurrentThread_Sleep into the Thread interfaceLioncash1-5/+3
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-2/+8
Aims to disambiguate why each priority instance exists a little bit. While we're at it, also add an explanatory comment to UpdatePriority().
2018-12-28kernel: Rename 'default' CPU core to 'ideal' coreLioncash1-6/+6
This makes the naming more closely match its meaning. It's just a preferred core, not a required default core. This also makes the usages of this term consistent across the thread and process implementations.
2018-12-28kernel/thread: Move process thread initialization into process.cppLioncash1-11/+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-19kernel/thread: Make thread_id a 64-bit valueLioncash1-2/+2
The kernel uses a 64-bit value for the thread ID, so we shouldn't be using a 32-bit value.
2018-12-19Moved backtrace to ArmInterfaceDavid Marcec1-5/+0
2018-12-04svc: Implement SetThreadActivity (thread suspension)Luke Street1-0/+14
2018-12-03Print backtrace on svcBreakDavid Marcec1-0/+5
When we get an svcBreak we get a backtrace now
2018-11-22scheduler: Add explanations for YieldWith and WithoutLoadBalancingZach Hilman1-4/+0
2018-11-19svc: Implement yield types 0 and -1Zach Hilman1-0/+5
2018-11-14kernel/thread: Deduplicate scheduler switching codeLioncash1-0/+2
The code in both places was the same verbatim, so we can extract it to a function to deduplicate the logic.
2018-10-26svc: Implement svcGetInfo command 0xF0000002Lioncash1-1/+10
This retrieves: if (curr_thread == handle_thread) { result = total_thread_ticks + (hardware_tick_count - last_context_switch_ticks); } else if (curr_thread == handle_thread && sub_id == current_core_index) { result = hardware_tick_count - last_context_switch_ticks; }
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-1/+1
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-35/+181
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-21thread/process: Move TLS slot marking/freeing to the process classLioncash1-1/+12
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-1/+1
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-15Port #4182 from Citra: "Prefix all size_t with std::"fearlessTobi1-1/+1
2018-09-13kernel/thread: Include thread-related enums within the kernel namespaceLioncash1-6/+6
Previously, these were sitting outside of the Kernel namespace, which doesn't really make sense, given they're related to the Thread class which is within the Kernel namespace.
2018-08-29kernel: Eliminate kernel global stateLioncash1-14/+8
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-1/+1
Gets all of these types and interfaces out of the global namespace.
2018-08-04kernel/thread: Fix potential crashes introduced in 26de4bb521b1ace7af76eff4f6956cb23ac0d58cLioncash1-0/+2
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-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-08-01kernel/thread: Remove unimplemented function prototypeLioncash1-6/+0
Given there's no implementation, we may as well remove the code entirely.
2018-07-31kernel: Remove unnecessary includesLioncash1-3/+2
Removes unnecessary direct dependencies in some headers and also gets rid of indirect dependencies that were being relied on to be included.
2018-07-21CPU: Save and restore the TPIDR_EL0 system register on every context switch.Subv1-0/+9
Note that there's currently a dynarmic bug preventing this register from being written.
2018-07-20thread: Convert ThreadStatus into an enum classLioncash1-14/+14
Makes the thread status strongly typed, so implicit conversions can't happen. It also makes it easier to catch mistakes at compile time.
2018-06-22Run clang-format on PR.Michael Scire1-2/+2
2018-06-22Kernel/Arbiters: HLE is atomic, adjust code to reflect that.Michael Scire1-1/+0
2018-06-21Kernel/Arbiters: Initialize arb_wait_address in thread struct.Michael Scire1-1/+1
2018-06-21Kernel/Arbiters: Mostly implement SignalToAddressMichael Scire1-2/+4
2018-06-21Kernel/Arbiters: Implement WaitForAddressMichael Scire1-2/+4
2018-06-21Kernel/Arbiters: Add stubs for 4.x SignalToAddress/WaitForAddres SVCs.Michael Scire1-0/+1
2018-05-11thread: Rename mask to affinity_masks.bunnei1-1/+1
2018-05-11thread: Implement ChangeCore function.bunnei1-0/+6
2018-05-11core: Implement multicore support.bunnei1-0/+4
2018-04-23Kernel: Implemented mutex priority inheritance.Subv1-0/+15
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: Use 0x2C as default main thread priority for homebrew and lone NRO/NSOsSubv1-1/+1
2018-04-21Kernel: Remove unused ConditionVariable class.Subv1-6/+0
2018-04-21Kernel: Remove old and unused Mutex code.Subv1-7/+0
2018-04-21Kernel: Corrected the implementation of svcArbitrateLock and svcArbitrateUnlock.Subv1-1/+5
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-19thread: Add THREADSTATUS_WAIT_HLE_EVENT, remove THREADSTATUS_WAIT_ARB.bunnei1-1/+1
2018-02-18kernel: Use Scheduler class for threading.bunnei1-15/+0
2018-02-18kernel: Remove unused address_arbiter code.bunnei1-12/+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-01-10Threads: Added enum values for the Switch's 4 cpu cores and implemented svcGetInfo(AllowedCpuIdBitmask)Subv1-4/+9
2018-01-09Kernel: Allow chaining WaitSynchronization calls inside a wakeup callback.Subv1-3/+7
2017-12-31thread: Keep track of the initially created handle.bunnei1-0/+3
This is kinda crufty, but we need it for now to update guest state variables.
2017-12-29kernel: Various 64-bit fixes in memory/process/threadbunnei1-2/+2
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-5/+5
2017-09-30Fixed type conversion ambiguityHuw Pascoe1-7/+7
2017-09-28Kernel/Threads: When putting a thread to wait, specify a function to execute when it is awoken.Subv1-3/+12
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-6/+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-05-30Kernel: Move WaitObject to a separate fileYuri Kunde Schlesner1-0/+1
Now that HandleTable doesn't directly depend on WaitObject anymore, this can be separated from the main kernel.h header.
2017-05-25Kernel: Centralize error definitions in errors.hYuri Kunde Schlesner1-1/+1
2017-02-27Core: Remove unnecessary include in thread.hYuri Kunde Schlesner1-1/+0
2017-01-06Kernel: Don't attempt to yield execution in SleepThread(0) if there are no available threads to run.Subv1-0/+5
With this we avoid an useless temporary deschedule of the current thread.
2017-01-05Kernel: Remove some unused functions.Subv1-9/+0
2017-01-05Kernel: Remove Thread::wait_objects_index and use wait_objects to hold all the objects that a thread is waiting on.Subv1-9/+7
2017-01-04Kernel: Use different thread statuses when a thread calls WaitSynchronization1 and WaitSynchronizationN with wait_all = true.Subv1-9/+10
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-0/+9
2017-01-04Kernel: Object ShouldWait and Acquire calls now take a thread as a parameter.Subv1-2/+2
This will be useful when implementing mutex priority inheritance.
2016-12-22ThreadContext: Move from "core" to "arm_interface".bunnei1-1/+2
2016-12-22core: Remove HLE module, consolidate code & various cleanups.bunnei1-1/+0
2016-12-17Thread: remove the thread from the thread list when exitingwwylele1-0/+5
2016-12-14Fixed the codestyle to match our clang-format rules.Subv1-4/+6
2016-12-09WaitSynch: Removed unused variables and reduced SharedPtr copies.Subv1-2/+3
Define a variable with the value of the sync timeout error code. Use a boost::flat_map instead of an unordered_map to hold the equivalence of objects and wait indices in a WaitSynchN call.
2016-12-04Threading: Added some utility functions and const correctness.Subv1-3/+16
2016-12-04Threading: Reworked the way our scheduler works.Subv1-6/+16
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-09-22implement wait tree widgetwwylele1-0/+5
2016-09-21Remove empty newlines in #include blocks.Emmanuel Gil Peyrot1-4/+0
This makes clang-format useful on those. Also add a bunch of forgotten transitive includes, which otherwise prevented compilation.
2016-09-18Sources: Run clang-format on everything.Emmanuel Gil Peyrot1-32/+46
2016-05-07Kernel/Threads: Dynamically allocate the TLS region for threads in the BASE region of the linear heap.Subv1-2/+2
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.
2015-09-10General: Fix up doxygen commentsLioncash1-1/+0
2015-06-28Common: Cleanup key_map includes.Emmanuel Gil Peyrot1-0/+1
2015-06-17kernel: Fix svcWaitSynch to always acquire requested wait objects.bunnei1-9/+5
2015-05-29Remove every trailing whitespace from the project (but externals).Emmanuel Gil Peyrot1-1/+1
2015-05-15Memmap: Re-organize memory function in two filesYuri Kunde Schlesner1-1/+0
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-12Thread: Remove the idle threadYuri Kunde Schlesner1-17/+0
Instead just use nullptr to represent no thread is active.
2015-05-12Core/Memory: Add TLS support for creating up to 300 threadsSubv1-1/+1
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/+1
2015-05-11fixup! Set the TLS address in the schedulerSubv1-0/+2
2015-05-11Core/Memory: Give every emulated thread it's own TLS area.Subv1-0/+6
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-09Kernel: Remove unused g_main_thread variableYuri Kunde Schlesner1-2/+0
2015-04-10Kernel: Implemented priority inheritance for mutexes.bunnei1-0/+6
2015-04-10Thread: Implement priority boost for starved threads.bunnei1-10/+15
SVC: Return correct error code on invalid CreateThread processor ID. SVC: Assert when creating a thread with an invalid userland priority.
2015-04-10Kernel: Fixed default thread priority.bunnei1-4/+3
2015-02-10Scheduler refactor Pt. 1Kevin Hartman1-33/+82
* 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: Make WaitObjects share ownership of Threads waiting on themYuri Kunde Schlesner1-0/+2
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-0/+1
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-2/+8
2015-02-02Kernel: Use separate Handle tables for CoreTiming userdataYuri Kunde Schlesner1-0/+3
This is to support the removal of GetHandle soon
2015-02-02Thread: Modernize two functions that slipped through previous rebasesYuri Kunde Schlesner1-8/+7
2015-01-30Kernel: Mark all appropriate kernel objects as "final"Yuri Kunde Schlesner1-2/+1
2015-01-22Thread: Fix WaitSynchronization1 to not set register 1 on thread wakeup.bunnei1-7/+14
2015-01-22Kernel: Changed "ShouldWait" to return bool and "Acquire" to return void.bunnei1-2/+2
2015-01-22WaitObject: Renamed "Wait" to "ShouldWait", made "ShouldWait" and "Acquire" pure virtual.bunnei1-1/+1
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-9/+8
2015-01-22Kernel: Get rid of WaitTypes and simplify lots of code, removing hacks.bunnei1-31/+10
2015-01-22WaitSynchronizationN: Refactor to fix several bugsbunnei1-2/+2
- 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/+2
2015-01-22WaitSynchronizationN: Implement return valuesbunnei1-16/+42
2015-01-22Thread: Keep track of multiple wait objects.bunnei1-3/+3
2015-01-22Kernel: Added WaitObject and changed "waitable" objects inherit from it.bunnei1-3/+1
2015-01-20core: Fix a few docstringsLioncash1-1/+1
2015-01-09Kernel: Start using boost::intrusive_ptr for lifetime managementYuri Kunde Schlesner1-4/+4
2015-01-09Thread: Reduce use of Handles and move some funcs to inside the class.Yuri Kunde Schlesner1-46/+22
2015-01-09Kernel: Move Thread's definition to the header fileYuri Kunde Schlesner1-0/+57
2015-01-09SVC: Implemented the Timer service calls.Subv1-0/+1
2015-01-09SVC: Fixed SleepThread.Subv1-0/+7
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-0/+11
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.
2014-12-28Kernel: New handle managerYuri Kunde Schlesner1-3/+0
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-21License changepurpasmart961-1/+1
2014-12-21Thread: Wait current thread on svc_SleepThreadbunnei1-1/+0
- 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-0/+3
This boots a few (mostly Nintendo 1st party) games further.
2014-12-09Thread: Fixed to wait on address when in arbitration.bunnei1-0/+11
2014-12-04Threads: Implemented a sequential thread idSubv1-1/+6
2014-12-04SVC: Implemented GetThreadId.Subv1-0/+3
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-24HLE: Revamp error handling throrough the HLE codeYuri Kunde Schlesner1-3/+4
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-1/+1
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/+7
Thread: Cleaned up arbitrate address functions. Thread: Cleaned up ArbitrateAllThreads function.
2014-06-13Kernel: Added real support for thread and event blockingbunnei1-3/+6
- 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/+6
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-1/+1
2014-05-23kernel: refactored function naming to remove "__" prefixbunnei1-2/+2
2014-05-23thread: moved ThreadStatus/WaitType to header, added support for arg on CreateThread, added correct CPSR resetbunnei1-1/+25
2014-05-21thread: added correct lowest thread priority, added a thread priority check, and added some commentsbunnei1-6/+7
2014-05-21thread: exposed ResumeThreadFromWait function for use in other kernel modulesbunnei1-0/+3
2014-05-21thread: moved threading calls to the Kernel namespacebunnei1-9/+17
2014-05-21thread: whitespace change - fixed * and & placementbunnei1-2/+2
2014-05-21- created a Kernel namespacebunnei1-2/+2
- cleaned up Kernel code a bit (moved stuff into namespace, fixed whitespace issues) - added handle types for all different CTROS handles
2014-05-20thread: added declaration for __KernelReschedule to be used by syscall modulebunnei1-0/+3
2014-05-17changed a commentbunnei1-1/+1
2014-05-17- added enum ThreadProcessorIdbunnei1-2/+17
- reorganized some kernel thread functions - added placeholder __KernelWaitThread_Synchronization function
2014-05-17- replaced KERNELOBJECT_MAX_NAME_LENGTH with KERNEL_MAX_NAME_LENGTHbunnei1-1/+5
- added KERNEL_DEFAULT_STACK_SIZE definition (0x4000)
2014-05-16completely gutted/refactored threading code to be simplerbunnei1-42/+2
2014-05-15- added helper function for __KernelCreateThreadbunnei1-0/+6
- added __KernelSwitchToThread for enabling a thread - added __KernelRotateThreadReadyQueue
2014-05-14various cleanups / remove unused codebunnei1-0/+1
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-6/+19
2014-05-10added initial kernel/thread modulesbunnei1-0/+36