Commit Graph

99 Commits (a13ab958cbba75bc9abd1ca50f3030a10a75784e)

Author SHA1 Message Date
Huw Pascoe a13ab958cb Fixed type conversion ambiguity 8 years ago
Subv 3165466b66 Kernel/Thread: Allow specifying which process a thread belongs to when creating it.
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.
8 years ago
Yuri Kunde Schlesner 64ecf81a3c Kernel: Move WaitObject to a separate file
Now that HandleTable doesn't directly depend on WaitObject anymore, this
can be separated from the main kernel.h header.
8 years ago
Yuri Kunde Schlesner 2cdb40d709 Kernel: Centralize error definitions in errors.h 8 years ago
Yuri Kunde Schlesner 441f8b5a4b Core: Remove unnecessary include in thread.h 8 years ago
bunnei b5eac78b43 Merge pull request #2410 from Subv/sleepthread
Don't yield execution in SleepThread(0) if there are no available threads to run
9 years ago
Subv fc2266130b Kernel: Don't attempt to yield execution in SleepThread(0) if there are no available threads to run.
With this we avoid an useless temporary deschedule of the current thread.
9 years ago
Subv 5e2a8ebabf Kernel: Remove some unused functions. 9 years ago
Subv fd95b6ee26 Kernel: Remove Thread::wait_objects_index and use wait_objects to hold all the objects that a thread is waiting on. 9 years ago
Subv cef5f45de2 Kernel: Use different thread statuses when a thread calls WaitSynchronization1 and WaitSynchronizationN with wait_all = true.
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.
9 years ago
Subv d3ff5b91e1 Kernel/Mutex: Propagate thread priority changes to other threads inheriting the priority via mutexes 9 years ago
Subv e6a7723f2f Kernel: Object ShouldWait and Acquire calls now take a thread as a parameter.
This will be useful when implementing mutex priority inheritance.
9 years ago
bunnei 8b1e269e58 ThreadContext: Move from "core" to "arm_interface". 9 years ago
bunnei 4fc8b8229e core: Remove HLE module, consolidate code & various cleanups. 9 years ago
wwylele 5728e42634 Thread: remove the thread from the thread list when exiting 9 years ago
Subv 5b1edc6ae7 Fixed the codestyle to match our clang-format rules. 9 years ago
Subv 17b29d8865 WaitSynch: Removed unused variables and reduced SharedPtr copies.
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.
9 years ago
Subv bdad00c73f Threading: Added some utility functions and const correctness. 9 years ago
Subv 8634b8cb83 Threading: Reworked the way our scheduler works.
Threads will now be awakened when the objects they're waiting on are signaled, instead of repeating the WaitSynchronization call every now and then.

The scheduler is now called once after every SVC call, and once after a thread is awakened from sleep by its timeout callback.

This new implementation is based off reverse-engineering of the real kernel.

See https://gist.github.com/Subv/02f29bd9f1e5deb7aceea1e8f019c8f4 for a more detailed description of how the real kernel handles rescheduling.
9 years ago
wwylele f69a543110 implement wait tree widget 9 years ago
Emmanuel Gil Peyrot ebdae19fd2 Remove empty newlines in #include blocks.
This makes clang-format useful on those.

Also add a bunch of forgotten transitive includes, which otherwise
prevented compilation.
9 years ago
Emmanuel Gil Peyrot dc8479928c Sources: Run clang-format on everything. 9 years ago
Subv d192fb066d Kernel/Threads: Dynamically allocate the TLS region for threads in the BASE region of the linear heap.
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.
9 years ago
Lioncash d3efa637b4 General: Fix up doxygen comments 10 years ago
Emmanuel Gil Peyrot 596b7c4f63 Common: Cleanup key_map includes. 10 years ago
bunnei 71e8822d23 kernel: Fix svcWaitSynch to always acquire requested wait objects. 10 years ago
Emmanuel Gil Peyrot b1503b2020 Remove every trailing whitespace from the project (but externals). 10 years ago
Yuri Kunde Schlesner 7ada357b2d Memmap: Re-organize memory function in two files
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.
10 years ago
bunnei cb2b2071a8 Merge pull request #748 from Subv/tls_max
Core/Memory: Add TLS support for creating up to 300 threads
10 years ago
bunnei ee8da4c356 Merge pull request #751 from yuriks/idle-thread
Thread: Remove the idle thread
10 years ago
Yuri Kunde Schlesner 4f7a055081 Thread: Remove the idle thread
Instead just use nullptr to represent no thread is active.
10 years ago
Subv dda94e56dd Core/Memory: Add TLS support for creating up to 300 threads 10 years ago
Yuri Kunde Schlesner 820b97787c Merge pull request #750 from Subv/process_svc
Core/HLE: Implemented the SVCs GetProcessId and GetProcessIdOfThread
10 years ago
Subv 41f74a16fd Core/HLE: Implemented the SVCs GetProcessId and GetProcessIdOfThread 10 years ago
Yuri Kunde Schlesner d16c2bd956 Thread: Correctly set main thread initial stack position 10 years ago
Subv 115ad8e16a fixup! Set the TLS address in the scheduler 10 years ago
Subv 000876858d Core/Memory: Give every emulated thread it's own TLS area.
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.
10 years ago
Yuri Kunde Schlesner 7c50b999fa Kernel: Remove unused g_main_thread variable 10 years ago
bunnei 9c3419ebcc Kernel: Implemented priority inheritance for mutexes. 10 years ago
bunnei 7b9f428b23 Thread: Implement priority boost for starved threads.
SVC: Return correct error code on invalid CreateThread processor ID.

SVC: Assert when creating a thread with an invalid userland priority.
10 years ago
bunnei e08f55b1a7 Kernel: Fixed default thread priority. 10 years ago
Kevin Hartman 5fcbfc06eb Scheduler refactor Pt. 1
* 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.
11 years ago
Yuri Kunde Schlesner 52f58e64ef Kernel: Make WaitObjects share ownership of Threads waiting on them
During normal operation, a thread waiting on an WaitObject and the
object hold mutual references to each other for the duration of the
wait.

If a process is forcefully terminated (The CTR kernel has a SVC to do
this, TerminateProcess, though no equivalent exists for threads.) its
threads would also be stopped and destroyed, leaving dangling pointers
in the WaitObjects.

The solution is to simply have the Thread remove itself from WaitObjects
when it is stopped. The vector of Threads in WaitObject has also been
changed to hold SharedPtrs, just in case. (Better to have a reference
cycle than a crash.)
11 years ago
Yuri Kunde Schlesner 7725256f64 Explicitly instantiate constructors/destructors for Kernel objects
This should speed up compile times a bit, as well as enable more liberal
use of forward declarations. (Due to SharedPtr not trying to emit the
destructor anymore.)
11 years ago
Yuri Kunde Schlesner 4e84df8be3 Mutex: Replace g_mutex_held_locks with a set inside Thread 11 years ago
Yuri Kunde Schlesner a9b86db3cf Kernel: Use separate Handle tables for CoreTiming userdata
This is to support the removal of GetHandle soon
11 years ago
Yuri Kunde Schlesner 664c79ff47 Thread: Modernize two functions that slipped through previous rebases 11 years ago
Yuri Kunde Schlesner d917a9bf77 Kernel: Mark all appropriate kernel objects as "final" 11 years ago
bunnei 68ddaaa2f5 Thread: Fix WaitSynchronization1 to not set register 1 on thread wakeup. 11 years ago
bunnei 15b6a4d9ad Kernel: Changed "ShouldWait" to return bool and "Acquire" to return void. 11 years ago