Improve thread code
This commit is contained in:
parent
5540d80d34
commit
4e95d7b6b2
|
@ -1,12 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <PSX/System/threads.hpp>
|
#include "threads.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace Callback {
|
namespace Callback {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
static void execute_thread(SysCall::ThreadHandle thread_handle) {
|
static void execute_callback(Thread::Handle thread_handle) {
|
||||||
MainThread::prepare_if_main(thread_handle);
|
if(CurrentThread::is_me(MainThread::Handle)) {
|
||||||
Thread::execute_next();
|
CurrentThread::replace_with(thread_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SysCall::ReturnFromException();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace VSync {
|
namespace VSync {
|
||||||
|
@ -17,7 +20,7 @@ namespace JabyEngine {
|
||||||
void routine();
|
void routine();
|
||||||
|
|
||||||
static void [[deprecated("Currently not in use")]] execute() {
|
static void [[deprecated("Currently not in use")]] execute() {
|
||||||
execute_thread(VSync::thread_handle);
|
execute_callback(VSync::thread_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +31,7 @@ namespace JabyEngine {
|
||||||
extern uint32_t stack[StackSize];
|
extern uint32_t stack[StackSize];
|
||||||
|
|
||||||
static void execute() {
|
static void execute() {
|
||||||
execute_thread(CD::thread_handle);
|
execute_callback(CD::thread_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "syscalls.hpp"
|
#include <PSX/System/syscalls.hpp>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct Thread {
|
struct Thread {
|
||||||
static uintptr_t get_pic() {
|
using Handle = SysCall::ThreadHandle;
|
||||||
return table_of_tables.processes->current_tcb->epc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr uint32_t idx_from_handle(SysCall::ThreadHandle thread) {
|
static constexpr uint32_t idx_from_handle(SysCall::ThreadHandle thread) {
|
||||||
return thread & 0xFFFF;
|
return thread & 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_next(SysCall::ThreadHandle thread) {
|
static uintptr_t get_pic_of(Handle handle) {
|
||||||
table_of_tables.processes->current_tcb = &table_of_tables.threads[idx_from_handle(thread)];
|
return table_of_tables.threads[idx_from_handle(handle)].epc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void execute_next() {
|
template<size_t N>
|
||||||
SysCall::ReturnFromException();
|
static Handle create(void(*function)(), uint32_t(&stack)[N]) {
|
||||||
|
return SysCall::OpenThread(function, &stack[N - 1], SysCall::get_gp());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_kernel_mode_for(SysCall::ThreadHandle handle) {
|
static void set_kernel_mode_for(SysCall::ThreadHandle handle) {
|
||||||
|
@ -28,25 +27,25 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CurrentThread {
|
||||||
|
static uintptr_t get_pic() {
|
||||||
|
return table_of_tables.processes->current_tcb->epc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_me(Thread::Handle handle) {
|
||||||
|
return table_of_tables.processes->current_tcb == &table_of_tables.threads[Thread::idx_from_handle(handle)];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void replace_with(Thread::Handle handle) {
|
||||||
|
table_of_tables.processes->current_tcb = &table_of_tables.threads[Thread::idx_from_handle(handle)];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct MainThread {
|
struct MainThread {
|
||||||
|
static constexpr const Thread::Handle Handle = 0xFF000000;
|
||||||
|
|
||||||
static uintptr_t get_pic() {
|
static uintptr_t get_pic() {
|
||||||
return table_of_tables.threads[0].epc;
|
return table_of_tables.threads[0].epc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_if_main(SysCall::ThreadHandle handle) {
|
|
||||||
if(table_of_tables.processes->current_tcb == &table_of_tables.threads[0]) {
|
|
||||||
Thread::prepare_next(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prepare_restore() {
|
|
||||||
Thread::prepare_next(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void restore() {
|
|
||||||
SysCall::EnterCriticalSection();
|
|
||||||
MainThread::prepare_restore();
|
|
||||||
Thread::execute_next();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -16,11 +16,9 @@ namespace JabyEngine {
|
||||||
);
|
);
|
||||||
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/
|
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/
|
||||||
|
|
||||||
InternalCallback::CD::thread_handle = SysCall::OpenThread(
|
InternalCallback::CD::thread_handle = Thread::create(
|
||||||
reinterpret_cast<void(*)()>(JabyEngine::CD::internal::IRQ::data_ready_handler),
|
reinterpret_cast<void(*)()>(JabyEngine::CD::internal::IRQ::data_ready_handler),
|
||||||
&InternalCallback::CD::stack[InternalCallback::CD::StackSize - 1],
|
InternalCallback::CD::stack);
|
||||||
SysCall::get_gp()
|
|
||||||
);
|
|
||||||
Thread::set_user_mode_for(InternalCallback::CD::thread_handle);
|
Thread::set_user_mode_for(InternalCallback::CD::thread_handle);
|
||||||
SysCall::ExitCriticalSection();
|
SysCall::ExitCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace JabyEngine {
|
||||||
void data_ready_handler(uint32_t data) {
|
void data_ready_handler(uint32_t data) {
|
||||||
while(true) {
|
while(true) {
|
||||||
printf("Data: %i\n", data);
|
printf("Data: %i\n", data);
|
||||||
SysCall::ChangeThread(0xFF000000);
|
SysCall::ChangeThread(MainThread::Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace JabyEngine {
|
||||||
/*if(VSyncCallback::callback) {
|
/*if(VSyncCallback::callback) {
|
||||||
VSyncCallback::callback();
|
VSyncCallback::callback();
|
||||||
}*/
|
}*/
|
||||||
MainThread::restore();
|
SysCall::ChangeThread(MainThread::Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue