mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-10 19:01:53 +00:00
Remove temporary and permanent threads
This commit is contained in:
parent
5a36cabf4b
commit
897f357e4b
3 changed files with 2 additions and 56 deletions
|
|
@ -7,32 +7,19 @@
|
||||||
|
|
||||||
namespace ultramodern {
|
namespace ultramodern {
|
||||||
namespace threads {
|
namespace threads {
|
||||||
enum class GameThreadType {
|
|
||||||
Normal,
|
|
||||||
Temporary,
|
|
||||||
Permanent
|
|
||||||
};
|
|
||||||
|
|
||||||
struct callbacks_t {
|
struct callbacks_t {
|
||||||
using get_game_thread_type_t = GameThreadType(OSThread* t);
|
|
||||||
using get_game_thread_name_t = std::string(OSThread* t);
|
using get_game_thread_name_t = std::string(OSThread* t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: document, I don't understand what this is used for.
|
* Allows to specifyin a custom name for each thread. Mainly for debugging purposes.
|
||||||
*/
|
|
||||||
get_game_thread_type_t *get_game_thread_type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows specifying a custom name for each thread.
|
|
||||||
*
|
*
|
||||||
* If this function is not provided then the thread id will be used as the name.
|
* If this function is not provided then the thread id will be used as the name of the thread.
|
||||||
*/
|
*/
|
||||||
get_game_thread_name_t *get_game_thread_name;
|
get_game_thread_name_t *get_game_thread_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_callbacks(const callbacks_t& callbacks);
|
void set_callbacks(const callbacks_t& callbacks);
|
||||||
|
|
||||||
GameThreadType get_game_thread_type(OSThread* t);
|
|
||||||
std::string get_game_thread_name(OSThread* t);
|
std::string get_game_thread_name(OSThread* t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,6 @@ void run_next_thread_and_wait(RDRAM_ARG1);
|
||||||
void resume_thread_and_wait(RDRAM_ARG OSThread* t);
|
void resume_thread_and_wait(RDRAM_ARG OSThread* t);
|
||||||
void schedule_running_thread(RDRAM_ARG PTR(OSThread) t);
|
void schedule_running_thread(RDRAM_ARG PTR(OSThread) t);
|
||||||
void cleanup_thread(UltraThreadContext* thread_context);
|
void cleanup_thread(UltraThreadContext* thread_context);
|
||||||
uint32_t permanent_thread_count();
|
|
||||||
uint32_t temporary_thread_count();
|
|
||||||
struct thread_terminated : std::exception {};
|
struct thread_terminated : std::exception {};
|
||||||
|
|
||||||
enum class ThreadPriority {
|
enum class ThreadPriority {
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,6 @@ void ultramodern::threads::set_callbacks(const callbacks_t& callbacks) {
|
||||||
threads_callbacks = callbacks;
|
threads_callbacks = callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
ultramodern::threads::GameThreadType ultramodern::threads::get_game_thread_type(OSThread* t) {
|
|
||||||
if (threads_callbacks.get_game_thread_type == nullptr) {
|
|
||||||
return GameThreadType::Normal;
|
|
||||||
}
|
|
||||||
return threads_callbacks.get_game_thread_type(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ultramodern::threads::get_game_thread_name(OSThread* t) {
|
std::string ultramodern::threads::get_game_thread_name(OSThread* t) {
|
||||||
if (threads_callbacks.get_game_thread_name == nullptr) {
|
if (threads_callbacks.get_game_thread_name == nullptr) {
|
||||||
return std::to_string(t->id);
|
return std::to_string(t->id);
|
||||||
|
|
@ -141,9 +134,6 @@ void ultramodern::set_native_thread_name(const std::string& name) {
|
||||||
void ultramodern::set_native_thread_priority(ThreadPriority pri) {}
|
void ultramodern::set_native_thread_priority(ThreadPriority pri) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::atomic_int temporary_threads = 0;
|
|
||||||
std::atomic_int permanent_threads = 0;
|
|
||||||
|
|
||||||
void wait_for_resumed(RDRAM_ARG UltraThreadContext* thread_context) {
|
void wait_for_resumed(RDRAM_ARG UltraThreadContext* thread_context) {
|
||||||
TO_PTR(OSThread, ultramodern::this_thread())->context->running.wait();
|
TO_PTR(OSThread, ultramodern::this_thread())->context->running.wait();
|
||||||
// If this thread's context was replaced by another thread or deleted, destroy it again from its own context.
|
// If this thread's context was replaced by another thread or deleted, destroy it again from its own context.
|
||||||
|
|
@ -190,17 +180,6 @@ static void _thread_func(RDRAM_ARG PTR(OSThread) self_, PTR(thread_func_t) entry
|
||||||
ultramodern::set_native_thread_name("Game Thread " + ultramodern::threads::get_game_thread_name(self));
|
ultramodern::set_native_thread_name("Game Thread " + ultramodern::threads::get_game_thread_name(self));
|
||||||
ultramodern::set_native_thread_priority(ultramodern::ThreadPriority::High);
|
ultramodern::set_native_thread_priority(ultramodern::ThreadPriority::High);
|
||||||
|
|
||||||
switch (ultramodern::threads::get_game_thread_type(self)) {
|
|
||||||
case ultramodern::threads::GameThreadType::Normal:
|
|
||||||
break;
|
|
||||||
case ultramodern::threads::GameThreadType::Temporary:
|
|
||||||
temporary_threads.fetch_add(1);
|
|
||||||
break;
|
|
||||||
case ultramodern::threads::GameThreadType::Permanent:
|
|
||||||
permanent_threads.fetch_add(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signal the initialized semaphore to indicate that this thread can be started.
|
// Signal the initialized semaphore to indicate that this thread can be started.
|
||||||
thread_context->initialized.signal();
|
thread_context->initialized.signal();
|
||||||
|
|
||||||
|
|
@ -231,24 +210,6 @@ static void _thread_func(RDRAM_ARG PTR(OSThread) self_, PTR(thread_func_t) entry
|
||||||
|
|
||||||
// Dispose of this thread now that it's completed or terminated.
|
// Dispose of this thread now that it's completed or terminated.
|
||||||
ultramodern::cleanup_thread(thread_context);
|
ultramodern::cleanup_thread(thread_context);
|
||||||
|
|
||||||
switch (ultramodern::threads::get_game_thread_type(self)) {
|
|
||||||
case ultramodern::threads::GameThreadType::Normal:
|
|
||||||
break;
|
|
||||||
case ultramodern::threads::GameThreadType::Temporary:
|
|
||||||
temporary_threads.fetch_sub(1);
|
|
||||||
break;
|
|
||||||
case ultramodern::threads::GameThreadType::Permanent:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ultramodern::permanent_thread_count() {
|
|
||||||
return permanent_threads.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ultramodern::temporary_thread_count() {
|
|
||||||
return temporary_threads.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osStartThread(RDRAM_ARG PTR(OSThread) t_) {
|
extern "C" void osStartThread(RDRAM_ARG PTR(OSThread) t_) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue