mirror of
https://github.com/Mr-Wiseguy/Zelda64Recomp.git
synced 2024-11-07 15:15:05 +01:00
Removed most remaining platform-specific code
This commit is contained in:
parent
e4dc4526f2
commit
73308e3500
@ -178,7 +178,6 @@ XCOPY "$(ProjectDir)lib\SDL2-2.24.0\lib\$(Platform)\SDL2.dll" "$(TargetDir)" /S
|
|||||||
<ClCompile Include="portultra\misc_ultra.cpp" />
|
<ClCompile Include="portultra\misc_ultra.cpp" />
|
||||||
<ClCompile Include="portultra\port_main.c" />
|
<ClCompile Include="portultra\port_main.c" />
|
||||||
<ClCompile Include="portultra\scheduler.cpp" />
|
<ClCompile Include="portultra\scheduler.cpp" />
|
||||||
<ClCompile Include="portultra\task_pthreads.cpp" />
|
|
||||||
<ClCompile Include="portultra\task_win32.cpp" />
|
<ClCompile Include="portultra\task_win32.cpp" />
|
||||||
<ClCompile Include="portultra\threads.cpp" />
|
<ClCompile Include="portultra\threads.cpp" />
|
||||||
<ClCompile Include="portultra\timer.cpp" />
|
<ClCompile Include="portultra\timer.cpp" />
|
||||||
@ -223,7 +222,6 @@ XCOPY "$(ProjectDir)lib\SDL2-2.24.0\lib\$(Platform)\SDL2.dll" "$(TargetDir)" /S
|
|||||||
<ClInclude Include="include\rt64_layer.h" />
|
<ClInclude Include="include\rt64_layer.h" />
|
||||||
<ClInclude Include="include\sections.h" />
|
<ClInclude Include="include\sections.h" />
|
||||||
<ClInclude Include="portultra\multilibultra.hpp" />
|
<ClInclude Include="portultra\multilibultra.hpp" />
|
||||||
<ClInclude Include="portultra\platform_specific.h" />
|
|
||||||
<ClInclude Include="portultra\ultra64.h" />
|
<ClInclude Include="portultra\ultra64.h" />
|
||||||
<ClInclude Include="src\euc-jp.h" />
|
<ClInclude Include="src\euc-jp.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -75,9 +75,6 @@
|
|||||||
<ClCompile Include="portultra\scheduler.cpp">
|
<ClCompile Include="portultra\scheduler.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="portultra\task_pthreads.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="portultra\task_win32.cpp">
|
<ClCompile Include="portultra\task_win32.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -131,9 +128,6 @@
|
|||||||
<ClInclude Include="portultra\multilibultra.hpp">
|
<ClInclude Include="portultra\multilibultra.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="portultra\platform_specific.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="portultra\ultra64.h">
|
<ClInclude Include="portultra\ultra64.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -242,7 +242,6 @@ void run_rsp_microcode(uint8_t* rdram, const OSTask* task, RspUcodeFunc* ucode_f
|
|||||||
RspExitReason exit_reason = ucode_func(rdram);
|
RspExitReason exit_reason = ucode_func(rdram);
|
||||||
// Ensure that the ucode exited correctly
|
// Ensure that the ucode exited correctly
|
||||||
assert(exit_reason == RspExitReason::Broke);
|
assert(exit_reason == RspExitReason::Broke);
|
||||||
sp_complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "ultra64.h"
|
#include "ultra64.h"
|
||||||
#include "platform_specific.h"
|
|
||||||
|
|
||||||
struct UltraThreadContext {
|
struct UltraThreadContext {
|
||||||
std::thread host_thread;
|
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 preinit(uint8_t* rdram, uint8_t* rom);
|
||||||
void save_init();
|
void save_init();
|
||||||
void native_init();
|
|
||||||
void init_scheduler();
|
void init_scheduler();
|
||||||
void init_events(uint8_t* rdram, uint8_t* rom);
|
void init_events(uint8_t* rdram, uint8_t* rom);
|
||||||
void init_timers(RDRAM_ARG1);
|
void init_timers(RDRAM_ARG1);
|
||||||
void native_thread_init(OSThread *t);
|
|
||||||
void set_self_paused(RDRAM_ARG1);
|
void set_self_paused(RDRAM_ARG1);
|
||||||
void wait_for_resumed(RDRAM_ARG1);
|
void wait_for_resumed(RDRAM_ARG1);
|
||||||
void swap_to_thread(RDRAM_ARG OSThread *to);
|
void swap_to_thread(RDRAM_ARG OSThread *to);
|
||||||
void pause_thread_impl(OSThread *t);
|
void pause_thread_impl(OSThread *t);
|
||||||
void pause_thread_native_impl(OSThread *t);
|
|
||||||
void resume_thread_impl(OSThread *t);
|
void resume_thread_impl(OSThread *t);
|
||||||
void resume_thread_native_impl(OSThread *t);
|
|
||||||
void schedule_running_thread(OSThread *t);
|
void schedule_running_thread(OSThread *t);
|
||||||
void stop_thread(OSThread *t);
|
|
||||||
void pause_self(RDRAM_ARG1);
|
void pause_self(RDRAM_ARG1);
|
||||||
void cleanup_thread(OSThread *t);
|
void cleanup_thread(OSThread *t);
|
||||||
PTR(OSThread) this_thread();
|
PTR(OSThread) this_thread();
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
#ifndef __PLATFORM_SPECIFIC_H__
|
|
||||||
#define __PLATFORM_SPECIFIC_H__
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
|
||||||
|
|
||||||
//#include <pthread.h>
|
|
||||||
//
|
|
||||||
//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 <pthread.h>
|
|
||||||
//
|
|
||||||
//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
|
|
@ -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) {
|
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);
|
debug_printf("[Scheduler] Need to wait for thread %d to pause itself\n", cur_running_thread->id);
|
||||||
return;
|
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 {
|
} else {
|
||||||
debug_printf("[Scheduler] Switching execution to thread %d (%d)\n", new_running_thread->id, new_running_thread->priority);
|
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);
|
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) {
|
void cleanup_thread(OSThread *t) {
|
||||||
std::lock_guard lock{scheduler_context.mutex};
|
std::lock_guard lock{scheduler_context.mutex};
|
||||||
scheduler_context.to_cleanup.push_back(t);
|
scheduler_context.to_cleanup.push_back(t);
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
#ifndef _WIN32
|
|
||||||
|
|
||||||
// #include <thread>
|
|
||||||
// #include <stdexcept>
|
|
||||||
// #include <atomic>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#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
|
|
@ -7,26 +7,3 @@ extern "C" unsigned int sleep(unsigned int seconds) {
|
|||||||
Sleep(seconds * 1000);
|
Sleep(seconds * 1000);
|
||||||
return 0;
|
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());
|
|
||||||
}
|
|
||||||
|
@ -59,9 +59,6 @@ static void _thread_func(RDRAM_ARG PTR(OSThread) self_, PTR(thread_func_t) entry
|
|||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Perform any necessary native thread initialization.
|
|
||||||
Multilibultra::native_thread_init(self);
|
|
||||||
|
|
||||||
// Set initialized to false to indicate that this thread can be started.
|
// Set initialized to false to indicate that this thread can be started.
|
||||||
self->context->initialized.store(true);
|
self->context->initialized.store(true);
|
||||||
self->context->initialized.notify_all();
|
self->context->initialized.notify_all();
|
||||||
@ -200,12 +197,11 @@ void Multilibultra::pause_thread_impl(OSThread* t) {
|
|||||||
t->state = OSThreadState::PREEMPTED;
|
t->state = OSThreadState::PREEMPTED;
|
||||||
t->context->running.store(false);
|
t->context->running.store(false);
|
||||||
t->context->running.notify_all();
|
t->context->running.notify_all();
|
||||||
Multilibultra::pause_thread_native_impl(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Multilibultra::resume_thread_impl(OSThread *t) {
|
void Multilibultra::resume_thread_impl(OSThread *t) {
|
||||||
if (t->state == OSThreadState::PREEMPTED) {
|
if (t->state == OSThreadState::PREEMPTED) {
|
||||||
Multilibultra::resume_thread_native_impl(t);
|
// Nothing to do here
|
||||||
}
|
}
|
||||||
t->state = OSThreadState::RUNNING;
|
t->state = OSThreadState::RUNNING;
|
||||||
t->context->running.store(true);
|
t->context->running.store(true);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define __ULTRA64_MULTILIBULTRA_H__
|
#define __ULTRA64_MULTILIBULTRA_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "platform_specific.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
@ -11,5 +11,5 @@ void Multilibultra::preinit(uint8_t* rdram, uint8_t* rom) {
|
|||||||
|
|
||||||
extern "C" void osInitialize() {
|
extern "C" void osInitialize() {
|
||||||
Multilibultra::init_scheduler();
|
Multilibultra::init_scheduler();
|
||||||
Multilibultra::native_init();
|
//Multilibultra::native_init();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user