mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-02-05 05:06:31 +00:00
* `RendererContext` abstract class * Delete rt64_layer * Implement renderer creation callback * Make `GraphicsConfig` an abstract class * Remove rt64 * Add renderer callback to `ultramodern::set_callbacks` * Fix rebase * Change setup_result's visibility to protected * Declare abstract `is_equal` method instead of operators * Various fixes * Fix issues * trigger_config_action * Move GraphicsConfig back to ultramodern * Change `update_config` to return if any changes were applied * Rename renderer_wrapper to renderer_context * Remove SDL2 and other libraries * Allow registering get_graphics_api_name * Move WindowHandle to renderer namespace * Comments explaining which callbacks are required * Fix CI * Update readme * `ULTRAMODERN_QUICK_EXIT` macro * Remove --config from readme * Add `add_compile_definitions(NOMINMAX)`
48 lines
2.1 KiB
C++
48 lines
2.1 KiB
C++
#include "ultramodern/ultramodern.hpp"
|
|
|
|
void ultramodern::schedule_running_thread(RDRAM_ARG PTR(OSThread) t_) {
|
|
debug_printf("[Scheduling] Adding thread %d to the running queue\n", TO_PTR(OSThread, t_)->id);
|
|
thread_queue_insert(PASS_RDRAM running_queue, t_);
|
|
TO_PTR(OSThread, t_)->state = OSThreadState::QUEUED;
|
|
}
|
|
|
|
void swap_to_thread(RDRAM_ARG OSThread *to) {
|
|
debug_printf("[Scheduling] Thread %d giving execution to thread %d\n", TO_PTR(OSThread, ultramodern::this_thread())->id, to->id);
|
|
// Insert this thread in the running queue.
|
|
ultramodern::thread_queue_insert(PASS_RDRAM ultramodern::running_queue, ultramodern::this_thread());
|
|
TO_PTR(OSThread, ultramodern::this_thread())->state = OSThreadState::QUEUED;
|
|
// Unpause the target thread and wait for this one to be unpaused.
|
|
ultramodern::resume_thread_and_wait(PASS_RDRAM to);
|
|
}
|
|
|
|
void ultramodern::check_running_queue(RDRAM_ARG1) {
|
|
// Check if there are any threads in the running queue.
|
|
if (!thread_queue_empty(PASS_RDRAM running_queue)) {
|
|
// Check if the highest priority thread in the queue is higher priority than the current thread.
|
|
OSThread* next_thread = TO_PTR(OSThread, ultramodern::thread_queue_peek(PASS_RDRAM running_queue));
|
|
OSThread* self = TO_PTR(OSThread, ultramodern::this_thread());
|
|
if (next_thread->priority > self->priority) {
|
|
ultramodern::thread_queue_pop(PASS_RDRAM running_queue);
|
|
// Swap to the higher priority thread.
|
|
swap_to_thread(PASS_RDRAM next_thread);
|
|
}
|
|
}
|
|
}
|
|
|
|
extern "C" void pause_self(RDRAM_ARG1) {
|
|
while (true) {
|
|
// Wait until an external message arrives, then allow the next thread to run.
|
|
ultramodern::wait_for_external_message(PASS_RDRAM1);
|
|
ultramodern::check_running_queue(PASS_RDRAM1);
|
|
}
|
|
}
|
|
|
|
extern "C" void yield_self(RDRAM_ARG1) {
|
|
ultramodern::wait_for_external_message(PASS_RDRAM1);
|
|
ultramodern::check_running_queue(PASS_RDRAM1);
|
|
}
|
|
|
|
extern "C" void yield_self_1ms(RDRAM_ARG1) {
|
|
ultramodern::wait_for_external_message_timed(PASS_RDRAM1, 1);
|
|
ultramodern::check_running_queue(PASS_RDRAM1);
|
|
}
|