sleep thread after panicking

This commit is contained in:
jacob 2024-04-15 20:59:42 -05:00
parent 228bef5a68
commit 3f1d714e7b
2 changed files with 12 additions and 2 deletions

View File

@ -109,8 +109,9 @@ void _log_panic(struct string msg)
if (!atomic_i32_eval(&G.initialized)) { return; } if (!atomic_i32_eval(&G.initialized)) { return; }
if (G.file_valid) { if (G.file_valid) {
sys_file_write(G.file, BUFFER_FROM_STRING(STR("** PANICKING **\n"))); sys_file_write(G.file, BUFFER_FROM_STRING(STR("******** PANICKING ********\n")));
sys_file_write(G.file, BUFFER_FROM_STRING(msg)); sys_file_write(G.file, BUFFER_FROM_STRING(msg));
sys_file_write(G.file, BUFFER_FROM_STRING(STR("\n***************************\n")));
} }
} }

View File

@ -101,6 +101,7 @@ GLOBAL struct {
LARGE_INTEGER timer_start; LARGE_INTEGER timer_start;
i32 scheduler_period_ms; i32 scheduler_period_ms;
DWORD thread_tls_index; DWORD thread_tls_index;
u32 main_thread_id;
/* Panic */ /* Panic */
struct atomic_i32 panicking; struct atomic_i32 panicking;
@ -1859,6 +1860,11 @@ void sys_panic(struct string msg)
WRITE_BARRIER(); WRITE_BARRIER();
SetEvent(G.panic_event); SetEvent(G.panic_event);
/* Wait for thread to be terminated */
if (GetCurrentThreadId() != G.main_thread_id) {
Sleep(INFINITE);
}
} }
} }
@ -1995,6 +2001,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
* Win32 setup * Win32 setup
* ========================== */ * ========================== */
G.main_thread_id = GetCurrentThreadId();
SetThreadDescription(GetCurrentThread(), L"Main thread"); SetThreadDescription(GetCurrentThread(), L"Main thread");
/* Set up panic event */ /* Set up panic event */
@ -2085,8 +2092,10 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
/* Call app thread and wait for return */ /* Call app thread and wait for return */
{ {
/* Start app thread */
struct sys_thread app_thread = sys_thread_alloc(&app_thread_entry_point, NULL, STR("[P9] App thread")); struct sys_thread app_thread = sys_thread_alloc(&app_thread_entry_point, NULL, STR("[P9] App thread"));
/* Get app thread handle */
HANDLE app_thread_handle = 0; HANDLE app_thread_handle = 0;
sys_rw_mutex_lock_shared(&G.threads_rw_mutex); sys_rw_mutex_lock_shared(&G.threads_rw_mutex);
{ {
@ -2095,7 +2104,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
} }
sys_rw_mutex_unlock_shared(&G.threads_rw_mutex); sys_rw_mutex_unlock_shared(&G.threads_rw_mutex);
/* Wait for thread exit or panic */ /* Wait for either app thread exit or panic */
if (app_thread_handle) { if (app_thread_handle) {
HANDLE wait_handles[] = { HANDLE wait_handles[] = {
app_thread_handle, app_thread_handle,