From 73308e350098650010ed598fd694833edc7976af Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Thu, 27 Apr 2023 18:16:27 -0400 Subject: [PATCH] Removed most remaining platform-specific code --- MMRecomp.vcxproj | 2 -- MMRecomp.vcxproj.filters | 6 ---- portultra/events.cpp | 1 - portultra/multilibultra.hpp | 6 ---- portultra/platform_specific.h | 32 ------------------- portultra/scheduler.cpp | 15 --------- portultra/task_pthreads.cpp | 60 ----------------------------------- portultra/task_win32.cpp | 23 -------------- portultra/threads.cpp | 6 +--- portultra/ultra64.h | 1 - portultra/ultrainit.cpp | 2 +- 11 files changed, 2 insertions(+), 152 deletions(-) delete mode 100644 portultra/platform_specific.h delete mode 100644 portultra/task_pthreads.cpp diff --git a/MMRecomp.vcxproj b/MMRecomp.vcxproj index 6629324..d3b303c 100644 --- a/MMRecomp.vcxproj +++ b/MMRecomp.vcxproj @@ -178,7 +178,6 @@ XCOPY "$(ProjectDir)lib\SDL2-2.24.0\lib\$(Platform)\SDL2.dll" "$(TargetDir)" /S - @@ -223,7 +222,6 @@ XCOPY "$(ProjectDir)lib\SDL2-2.24.0\lib\$(Platform)\SDL2.dll" "$(TargetDir)" /S - diff --git a/MMRecomp.vcxproj.filters b/MMRecomp.vcxproj.filters index 0c0a0e6..0a09252 100644 --- a/MMRecomp.vcxproj.filters +++ b/MMRecomp.vcxproj.filters @@ -75,9 +75,6 @@ Source Files - - Source Files - Source Files @@ -131,9 +128,6 @@ Header Files - - Header Files - Header Files diff --git a/portultra/events.cpp b/portultra/events.cpp index 13de280..988698b 100644 --- a/portultra/events.cpp +++ b/portultra/events.cpp @@ -242,7 +242,6 @@ void run_rsp_microcode(uint8_t* rdram, const OSTask* task, RspUcodeFunc* ucode_f RspExitReason exit_reason = ucode_func(rdram); // Ensure that the ucode exited correctly assert(exit_reason == RspExitReason::Broke); - sp_complete(); } diff --git a/portultra/multilibultra.hpp b/portultra/multilibultra.hpp index c1470c2..b694a6c 100644 --- a/portultra/multilibultra.hpp +++ b/portultra/multilibultra.hpp @@ -7,7 +7,6 @@ #include #include "ultra64.h" -#include "platform_specific.h" struct UltraThreadContext { std::thread host_thread; @@ -24,20 +23,15 @@ constexpr uint32_t save_size = 1024 * 1024 / 8; // Maximum save size, 1Mbit for void preinit(uint8_t* rdram, uint8_t* rom); void save_init(); -void native_init(); void init_scheduler(); void init_events(uint8_t* rdram, uint8_t* rom); void init_timers(RDRAM_ARG1); -void native_thread_init(OSThread *t); void set_self_paused(RDRAM_ARG1); void wait_for_resumed(RDRAM_ARG1); void swap_to_thread(RDRAM_ARG OSThread *to); void pause_thread_impl(OSThread *t); -void pause_thread_native_impl(OSThread *t); void resume_thread_impl(OSThread *t); -void resume_thread_native_impl(OSThread *t); void schedule_running_thread(OSThread *t); -void stop_thread(OSThread *t); void pause_self(RDRAM_ARG1); void cleanup_thread(OSThread *t); PTR(OSThread) this_thread(); diff --git a/portultra/platform_specific.h b/portultra/platform_specific.h deleted file mode 100644 index b9d1823..0000000 --- a/portultra/platform_specific.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __PLATFORM_SPECIFIC_H__ -#define __PLATFORM_SPECIFIC_H__ - -#if defined(__linux__) - -//#include -// -//typedef struct { -// pthread_t t; -// pthread_barrier_t pause_barrier; -// pthread_mutex_t pause_mutex; -// pthread_cond_t pause_cond; -// void (*entrypoint)(void *); -// void *arg; -//} OSThreadNative; - -#elif defined(_WIN32) - -//#include -// -//typedef struct { -// pthread_t t; -// pthread_barrier_t pause_barrier; -// pthread_mutex_t pause_mutex; -// pthread_cond_t pause_cond; -// void (*entrypoint)(void*); -// void* arg; -//} OSThreadNative; - -#endif - -#endif \ No newline at end of file diff --git a/portultra/scheduler.cpp b/portultra/scheduler.cpp index 6bb003f..f4d7a87 100644 --- a/portultra/scheduler.cpp +++ b/portultra/scheduler.cpp @@ -131,10 +131,6 @@ void swap_running_thread(thread_queue_t& running_thread_queue, OSThread*& cur_ru if (cur_running_thread && cur_running_thread->state == OSThreadState::RUNNING) { debug_printf("[Scheduler] Need to wait for thread %d to pause itself\n", cur_running_thread->id); return; - //debug_printf("[Scheduler] Switching execution from thread %d (%d) to thread %d (%d)\n", - // cur_running_thread->id, cur_running_thread->priority, - // new_running_thread->id, new_running_thread->priority); - //Multilibultra::pause_thread_impl(cur_running_thread); } else { debug_printf("[Scheduler] Switching execution to thread %d (%d)\n", new_running_thread->id, new_running_thread->priority); } @@ -238,17 +234,6 @@ void pause_self(RDRAM_ARG1) { Multilibultra::wait_for_resumed(PASS_RDRAM1); } -void stop_thread(OSThread *t) { - debug_printf("[Scheduler] Queuing Thread %d to be stopped\n", t->id); - { - std::lock_guard lock{scheduler_context.mutex}; - scheduler_context.to_stop.push_back(t); - scheduler_context.action_count.fetch_add(1); - scheduler_context.action_count.notify_all(); - } - Multilibultra::pause_thread_impl(t); -} - void cleanup_thread(OSThread *t) { std::lock_guard lock{scheduler_context.mutex}; scheduler_context.to_cleanup.push_back(t); diff --git a/portultra/task_pthreads.cpp b/portultra/task_pthreads.cpp deleted file mode 100644 index 667f022..0000000 --- a/portultra/task_pthreads.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _WIN32 - -// #include -// #include -// #include - -#include -#include -#include - -#include "ultra64.h" -#include "multilibultra.hpp" - -constexpr int pause_thread_signum = SIGUSR1; - -// void cleanup_current_thread(OSThread *t) { -// debug_printf("Thread cleanup %d\n", t->id); - -// // delete t->context; -// } - -void sig_handler(int signum, siginfo_t *info, void *context) { - if (signum == pause_thread_signum) { - OSThread *t = Multilibultra::this_thread(); - - debug_printf("[Sig] Thread %d paused\n", t->id); - - // Wait until the thread is marked as running again - t->context->running.wait(false); - - debug_printf("[Sig] Thread %d resumed\n", t->id); - } -} - -void Multilibultra::native_init(void) { - // Set up a signal handler to capture pause signals - struct sigaction sigact; - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO | SA_RESTART; - sigact.sa_sigaction = sig_handler; - - sigaction(pause_thread_signum, &sigact, nullptr); -} - -void Multilibultra::native_thread_init(OSThread *t) { - debug_printf("[Native] Init thread %d\n", t->id); -} - -void Multilibultra::pause_thread_native_impl(OSThread *t) { - debug_printf("[Native] Pause thread %d\n", t->id); - // Send a pause signal to the thread, which will trigger it to wait on its pause barrier in the signal handler - pthread_kill(t->context->host_thread.native_handle(), pause_thread_signum); -} - -void Multilibultra::resume_thread_native_impl(UNUSED OSThread *t) { - debug_printf("[Native] Resume thread %d\n", t->id); - // Nothing to do here -} - -#endif \ No newline at end of file diff --git a/portultra/task_win32.cpp b/portultra/task_win32.cpp index 06079ac..86159a9 100644 --- a/portultra/task_win32.cpp +++ b/portultra/task_win32.cpp @@ -7,26 +7,3 @@ extern "C" unsigned int sleep(unsigned int seconds) { Sleep(seconds * 1000); return 0; } - -void Multilibultra::native_init(void) { -} - -void Multilibultra::native_thread_init(OSThread *t) { - debug_printf("[Native] Init thread %d\n", t->id); -} - -void Multilibultra::pause_thread_native_impl(OSThread *t) { - debug_printf("[Native] Pause thread %d\n", t->id); - // Pause the thread via the win32 API - SuspendThread(t->context->host_thread.native_handle()); - // Perform a synchronous action to ensure that the thread is suspended - // see: https://devblogs.microsoft.com/oldnewthing/20150205-00/?p=44743 - CONTEXT threadContext{}; - GetThreadContext(t->context->host_thread.native_handle(), &threadContext); -} - -void Multilibultra::resume_thread_native_impl(UNUSED OSThread *t) { - debug_printf("[Native] Resume thread %d\n", t->id); - // Resume the thread - ResumeThread(t->context->host_thread.native_handle()); -} diff --git a/portultra/threads.cpp b/portultra/threads.cpp index 63cdea6..663ff44 100644 --- a/portultra/threads.cpp +++ b/portultra/threads.cpp @@ -59,9 +59,6 @@ static void _thread_func(RDRAM_ARG PTR(OSThread) self_, PTR(thread_func_t) entry ); #endif - // Perform any necessary native thread initialization. - Multilibultra::native_thread_init(self); - // Set initialized to false to indicate that this thread can be started. self->context->initialized.store(true); self->context->initialized.notify_all(); @@ -200,12 +197,11 @@ void Multilibultra::pause_thread_impl(OSThread* t) { t->state = OSThreadState::PREEMPTED; t->context->running.store(false); t->context->running.notify_all(); - Multilibultra::pause_thread_native_impl(t); } void Multilibultra::resume_thread_impl(OSThread *t) { if (t->state == OSThreadState::PREEMPTED) { - Multilibultra::resume_thread_native_impl(t); + // Nothing to do here } t->state = OSThreadState::RUNNING; t->context->running.store(true); diff --git a/portultra/ultra64.h b/portultra/ultra64.h index c9122cc..5587004 100644 --- a/portultra/ultra64.h +++ b/portultra/ultra64.h @@ -2,7 +2,6 @@ #define __ULTRA64_MULTILIBULTRA_H__ #include -#include "platform_specific.h" #ifdef __cplusplus #include diff --git a/portultra/ultrainit.cpp b/portultra/ultrainit.cpp index a95c06c..7d23675 100644 --- a/portultra/ultrainit.cpp +++ b/portultra/ultrainit.cpp @@ -11,5 +11,5 @@ void Multilibultra::preinit(uint8_t* rdram, uint8_t* rom) { extern "C" void osInitialize() { Multilibultra::init_scheduler(); - Multilibultra::native_init(); + //Multilibultra::native_init(); }