convert sys thread & watch structs to opaque ptrs

This commit is contained in:
jacob 2025-06-17 23:06:42 -05:00
parent 0055626fe6
commit 04f4c3a180
10 changed files with 60 additions and 80 deletions

View File

@ -275,7 +275,7 @@ void app_entry_point(struct string args_str)
} }
/* Create window */ /* Create window */
struct sys_window window = sys_window_alloc(); struct sys_window *window = sys_window_alloc();
/* Read window settings from file */ /* Read window settings from file */
{ {
@ -310,10 +310,10 @@ void app_entry_point(struct string args_str)
window_settings = *res; window_settings = *res;
} else { } else {
logf_info("Settings file not found, loading default"); logf_info("Settings file not found, loading default");
window_settings = default_window_settings(&window); window_settings = default_window_settings(window);
} }
string_copy_to_string(STRING_FROM_ARRAY(window_settings.title), LIT(WINDOW_TITLE)); string_copy_to_string(STRING_FROM_ARRAY(window_settings.title), LIT(WINDOW_TITLE));
sys_window_update_settings(&window, &window_settings); sys_window_update_settings(window, &window_settings);
arena_temp_end(temp); arena_temp_end(temp);
} }
@ -323,7 +323,7 @@ void app_entry_point(struct string args_str)
struct host_startup_receipt host_sr = host_startup(&sock_sr); struct host_startup_receipt host_sr = host_startup(&sock_sr);
struct resource_startup_receipt resource_sr = resource_startup(); struct resource_startup_receipt resource_sr = resource_startup();
struct work_startup_receipt work_sr = work_startup(worker_count); struct work_startup_receipt work_sr = work_startup(worker_count);
struct gpu_startup_receipt gpu_sr = gpu_startup(&work_sr, &window); struct gpu_startup_receipt gpu_sr = gpu_startup(&work_sr, window);
struct asset_cache_startup_receipt asset_cache_sr = asset_cache_startup(&work_sr); struct asset_cache_startup_receipt asset_cache_sr = asset_cache_startup(&work_sr);
struct ttf_startup_receipt ttf_sr = ttf_startup(); struct ttf_startup_receipt ttf_sr = ttf_startup();
struct font_startup_receipt font_sr = font_startup(&work_sr, &gpu_sr, &asset_cache_sr, &ttf_sr, &resource_sr); struct font_startup_receipt font_sr = font_startup(&work_sr, &gpu_sr, &asset_cache_sr, &ttf_sr, &resource_sr);
@ -332,14 +332,14 @@ void app_entry_point(struct string args_str)
struct sound_startup_receipt sound_sr = sound_startup(&work_sr, &asset_cache_sr, &resource_sr); struct sound_startup_receipt sound_sr = sound_startup(&work_sr, &asset_cache_sr, &resource_sr);
struct draw_startup_receipt draw_sr = draw_startup(&gpu_sr, &font_sr); struct draw_startup_receipt draw_sr = draw_startup(&gpu_sr, &font_sr);
struct sim_startup_receipt sim_sr = sim_startup(); struct sim_startup_receipt sim_sr = sim_startup();
struct user_startup_receipt user_sr = user_startup(&work_sr, &gpu_sr, &font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &host_sr, &sim_sr, connect_address, &window); struct user_startup_receipt user_sr = user_startup(&work_sr, &gpu_sr, &font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &host_sr, &sim_sr, connect_address, window);
struct playback_startup_receipt playback_sr = playback_startup(&mixer_sr); struct playback_startup_receipt playback_sr = playback_startup(&mixer_sr);
(UNUSED)user_sr; (UNUSED)user_sr;
(UNUSED)playback_sr; (UNUSED)playback_sr;
/* Show window */ /* Show window */
sys_window_show(&window); sys_window_show(window);
/* Wait for app_exit() */ /* Wait for app_exit() */
sync_flag_wait(&G.exit_sf); sync_flag_wait(&G.exit_sf);
@ -364,7 +364,7 @@ void app_entry_point(struct string args_str)
struct string window_settings_path = app_write_path_cat(temp.arena, settings_file_name); struct string window_settings_path = app_write_path_cat(temp.arena, settings_file_name);
struct sys_window_settings settings = sys_window_get_settings(&window); struct sys_window_settings settings = sys_window_get_settings(window);
struct string str = settings_serialize(temp.arena, &settings); struct string str = settings_serialize(temp.arena, &settings);
logf_info("Serialized window settings: %F", FMT_STR(str)); logf_info("Serialized window settings: %F", FMT_STR(str));
@ -377,7 +377,7 @@ void app_entry_point(struct string args_str)
arena_temp_end(temp); arena_temp_end(temp);
} }
sys_window_release(&window); sys_window_release(window);
logf_info("Program exited normally"); logf_info("Program exited normally");
scratch_end(scratch); scratch_end(scratch);

View File

@ -209,7 +209,7 @@ void host_release(struct host *host)
{ {
atomic_i32_eval_exchange(&host->receiver_thread_shutdown_flag, 1); atomic_i32_eval_exchange(&host->receiver_thread_shutdown_flag, 1);
sock_wake(host->sock); sock_wake(host->sock);
while (!sys_thread_try_release(&host->receiver_thread, 0.001f)) { while (!sys_thread_try_release(host->receiver_thread, 0.001f)) {
sock_wake(host->sock); sock_wake(host->sock);
} }
sys_mutex_release(&host->rcv_buffer_write_mutex); sys_mutex_release(&host->rcv_buffer_write_mutex);

View File

@ -98,7 +98,7 @@ struct host {
u64 bytes_sent; u64 bytes_sent;
struct atomic_i32 receiver_thread_shutdown_flag; struct atomic_i32 receiver_thread_shutdown_flag;
struct sys_thread receiver_thread; struct sys_thread *receiver_thread;
}; };
/* ========================== * /* ========================== *

View File

@ -38,7 +38,7 @@ struct wasapi_buffer {
GLOBAL struct { GLOBAL struct {
struct atomic_i32 playback_thread_shutdown; struct atomic_i32 playback_thread_shutdown;
struct sys_thread playback_thread; struct sys_thread *playback_thread;
IAudioClient *client; IAudioClient *client;
HANDLE event; HANDLE event;
IAudioRenderClient *playback; IAudioRenderClient *playback;
@ -70,7 +70,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(playback_shutdown)
{ {
__prof; __prof;
atomic_i32_eval_exchange(&G.playback_thread_shutdown, true); atomic_i32_eval_exchange(&G.playback_thread_shutdown, true);
sys_thread_wait_release(&G.playback_thread); sys_thread_wait_release(G.playback_thread);
} }
/* ========================== * /* ========================== *

View File

@ -23,10 +23,10 @@ GLOBAL struct {
#endif #endif
#if RESOURCE_RELOADING #if RESOURCE_RELOADING
struct sys_thread resource_watch_monitor_thread; struct sys_thread *resource_watch_monitor_thread;
struct sys_thread resource_watch_dispatch_thread; struct sys_thread *resource_watch_dispatch_thread;
struct sys_watch watch; struct sys_watch *watch;
struct atomic_i32 watch_shutdown; struct atomic_i32 watch_shutdown;
struct sys_mutex watch_dispatcher_mutex; struct sys_mutex watch_dispatcher_mutex;
@ -163,10 +163,10 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(resource_shutdown)
atomic_i32_eval_exchange(&G.watch_shutdown, 1); atomic_i32_eval_exchange(&G.watch_shutdown, 1);
sys_condition_variable_broadcast(&G.watch_dispatcher_cv); sys_condition_variable_broadcast(&G.watch_dispatcher_cv);
sys_watch_wake(&G.watch); sys_watch_wake(G.watch);
sys_thread_wait_release(&G.resource_watch_dispatch_thread); sys_thread_wait_release(G.resource_watch_dispatch_thread);
sys_thread_wait_release(&G.resource_watch_monitor_thread); sys_thread_wait_release(G.resource_watch_monitor_thread);
} }
void resource_register_watch_callback(resource_watch_callback *callback) void resource_register_watch_callback(resource_watch_callback *callback)
@ -189,7 +189,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(resource_watch_monitor_thread_entry_poi
while (!atomic_i32_eval(&G.watch_shutdown)) { while (!atomic_i32_eval(&G.watch_shutdown)) {
struct arena_temp temp = arena_temp_begin(scratch.arena); struct arena_temp temp = arena_temp_begin(scratch.arena);
struct sys_watch_info_list res = sys_watch_wait(temp.arena, &G.watch); struct sys_watch_info_list res = sys_watch_wait(temp.arena, G.watch);
if (res.first && !atomic_i32_eval(&G.watch_shutdown)) { if (res.first && !atomic_i32_eval(&G.watch_shutdown)) {
struct sys_lock lock = sys_mutex_lock_e(&G.watch_dispatcher_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.watch_dispatcher_mutex);
{ {

View File

@ -157,7 +157,7 @@ GLOBAL struct {
struct sys_mutex evictor_mutex; struct sys_mutex evictor_mutex;
struct sys_condition_variable evictor_cv; struct sys_condition_variable evictor_cv;
struct sys_thread evictor_thread; struct sys_thread *evictor_thread;
} G = ZI, DEBUG_ALIAS(G, G_sprite); } G = ZI, DEBUG_ALIAS(G, G_sprite);
/* ========================== * /* ========================== *
@ -277,7 +277,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(sprite_shutdown)
sys_condition_variable_broadcast(&G.evictor_cv); sys_condition_variable_broadcast(&G.evictor_cv);
sys_mutex_unlock(&lock); sys_mutex_unlock(&lock);
} }
sys_thread_wait_release(&G.evictor_thread); sys_thread_wait_release(G.evictor_thread);
} }
/* ========================== * /* ========================== *

View File

@ -272,10 +272,6 @@ enum sys_watch_info_kind {
}; };
struct sys_watch {
u64 handle;
};
struct sys_watch_info { struct sys_watch_info {
enum sys_watch_info_kind kind; enum sys_watch_info_kind kind;
struct string name; struct string name;
@ -288,7 +284,7 @@ struct sys_watch_info_list {
struct sys_watch_info *last; struct sys_watch_info *last;
}; };
struct sys_watch sys_watch_alloc(struct string path); struct sys_watch *sys_watch_alloc(struct string path);
void sys_watch_release(struct sys_watch *dw); void sys_watch_release(struct sys_watch *dw);
struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch *dw); struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch *dw);
void sys_watch_wake(struct sys_watch *dw); void sys_watch_wake(struct sys_watch *dw);
@ -338,11 +334,7 @@ struct sys_window_settings {
i32 floating_height; i32 floating_height;
}; };
struct sys_window { struct sys_window *sys_window_alloc(void);
u64 handle;
};
struct sys_window sys_window_alloc(void);
void sys_window_release(struct sys_window *sys_window); void sys_window_release(struct sys_window *sys_window);
void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func); void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func);
@ -432,12 +424,8 @@ struct thread_local_store *sys_thread_get_thread_local_store(void);
#define SYS_THREAD_ENTRY_POINT_FUNC_DEF(name, arg_name) void name(void *arg_name) #define SYS_THREAD_ENTRY_POINT_FUNC_DEF(name, arg_name) void name(void *arg_name)
typedef SYS_THREAD_ENTRY_POINT_FUNC_DEF(sys_thread_entry_point_func, data); typedef SYS_THREAD_ENTRY_POINT_FUNC_DEF(sys_thread_entry_point_func, data);
struct sys_thread {
u64 handle;
};
/* Creates a new thread running in the supplied `entry_point` */ /* Creates a new thread running in the supplied `entry_point` */
struct sys_thread sys_thread_alloc( struct sys_thread *sys_thread_alloc(
sys_thread_entry_point_func *entry_point, sys_thread_entry_point_func *entry_point,
void *thread_data, /* Passed as arg to `entry_point` */ void *thread_data, /* Passed as arg to `entry_point` */
struct string thread_name struct string thread_name

View File

@ -84,7 +84,7 @@ struct win32_window {
struct rect cursor_clip_bounds; struct rect cursor_clip_bounds;
struct atomic_i32 event_thread_shutdown; struct atomic_i32 event_thread_shutdown;
struct sys_thread event_thread; struct sys_thread *event_thread;
struct sys_mutex event_callbacks_mutex; struct sys_mutex event_callbacks_mutex;
sys_window_event_callback_func *event_callbacks[SYS_WINDOW_EVENT_LISTENERS_MAX]; sys_window_event_callback_func *event_callbacks[SYS_WINDOW_EVENT_LISTENERS_MAX];
@ -686,7 +686,7 @@ struct win32_watch {
u8 results_buff[KILOBYTE(64)]; u8 results_buff[KILOBYTE(64)];
}; };
struct sys_watch sys_watch_alloc(struct string dir_path) struct sys_watch *sys_watch_alloc(struct string dir_path)
{ {
struct arena_temp scratch = scratch_begin_no_conflict(); struct arena_temp scratch = scratch_begin_no_conflict();
@ -719,15 +719,12 @@ struct sys_watch sys_watch_alloc(struct string dir_path)
w32_watch->wake_handle = CreateEventW(NULL, FALSE, FALSE, NULL); w32_watch->wake_handle = CreateEventW(NULL, FALSE, FALSE, NULL);
scratch_end(scratch); scratch_end(scratch);
return (struct sys_watch *)w32_watch;
struct sys_watch watch = ZI;
watch.handle = (u64)w32_watch;
return watch;
} }
void sys_watch_release(struct sys_watch *dw) void sys_watch_release(struct sys_watch *dw)
{ {
struct win32_watch *w32_watch = (struct win32_watch *)dw->handle; struct win32_watch *w32_watch = (struct win32_watch *)dw;
CloseHandle(w32_watch->dir_handle); CloseHandle(w32_watch->dir_handle);
CloseHandle(w32_watch->wake_handle); CloseHandle(w32_watch->wake_handle);
@ -742,7 +739,7 @@ void sys_watch_release(struct sys_watch *dw)
struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch *dw) struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch *dw)
{ {
__prof; __prof;
struct win32_watch *w32_watch = (struct win32_watch *)dw->handle; struct win32_watch *w32_watch = (struct win32_watch *)dw;
struct sys_watch_info_list list = ZI; struct sys_watch_info_list list = ZI;
DWORD filter = FILE_NOTIFY_CHANGE_FILE_NAME | DWORD filter = FILE_NOTIFY_CHANGE_FILE_NAME |
@ -849,7 +846,7 @@ struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch
void sys_watch_wake(struct sys_watch *dw) void sys_watch_wake(struct sys_watch *dw)
{ {
struct win32_watch *w32_watch = (struct win32_watch *)dw->handle; struct win32_watch *w32_watch = (struct win32_watch *)dw;
SetEvent(w32_watch->wake_handle); SetEvent(w32_watch->wake_handle);
} }
@ -1050,7 +1047,7 @@ INTERNAL void win32_window_release(struct win32_window *window)
/* Stop window thread */ /* Stop window thread */
atomic_i32_eval_exchange(&window->event_thread_shutdown, 1); atomic_i32_eval_exchange(&window->event_thread_shutdown, 1);
win32_window_wake(window); win32_window_wake(window);
sys_thread_wait_release(&window->event_thread); sys_thread_wait_release(window->event_thread);
/* Release mutexes */ /* Release mutexes */
sys_mutex_release(&window->event_callbacks_mutex); sys_mutex_release(&window->event_callbacks_mutex);
@ -1414,25 +1411,22 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
return result; return result;
} }
struct sys_window sys_window_alloc(void) struct sys_window *sys_window_alloc(void)
{ {
__prof; __prof;
struct sys_window w = { return (struct sys_window *)win32_window_alloc();
.handle = (u64)win32_window_alloc()
};
return w;
} }
void sys_window_release(struct sys_window *sys_window) void sys_window_release(struct sys_window *sys_window)
{ {
__prof; __prof;
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
win32_window_release(window); win32_window_release(window);
} }
void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func) void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
struct sys_lock lock = sys_mutex_lock_e(&window->event_callbacks_mutex); struct sys_lock lock = sys_mutex_lock_e(&window->event_callbacks_mutex);
{ {
if (window->event_callbacks_count + 1 > ARRAY_COUNT(window->event_callbacks)) { if (window->event_callbacks_count + 1 > ARRAY_COUNT(window->event_callbacks)) {
@ -1446,7 +1440,7 @@ void sys_window_register_event_callback(struct sys_window *sys_window, sys_windo
void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func) void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
struct sys_lock lock = sys_mutex_lock_e(&window->event_callbacks_mutex); struct sys_lock lock = sys_mutex_lock_e(&window->event_callbacks_mutex);
{ {
@ -1469,7 +1463,7 @@ void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_win
void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings) void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings)
{ {
__prof; __prof;
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
struct sys_lock lock = sys_mutex_lock_e(&window->settings_mutex); struct sys_lock lock = sys_mutex_lock_e(&window->settings_mutex);
{ {
win32_update_window_from_settings(window, settings); win32_update_window_from_settings(window, settings);
@ -1481,13 +1475,13 @@ void sys_window_update_settings(struct sys_window *sys_window, struct sys_window
struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window) struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
return window->settings; return window->settings;
} }
void sys_window_show(struct sys_window *sys_window) void sys_window_show(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
HWND hwnd = window->hwnd; HWND hwnd = window->hwnd;
struct sys_lock lock = sys_mutex_lock_e(&window->settings_mutex); struct sys_lock lock = sys_mutex_lock_e(&window->settings_mutex);
{ {
@ -1507,25 +1501,25 @@ void sys_window_show(struct sys_window *sys_window)
struct v2 sys_window_get_size(struct sys_window *sys_window) struct v2 sys_window_get_size(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
return V2((f32)window->width, (f32)window->height); return V2((f32)window->width, (f32)window->height);
} }
struct v2 sys_window_get_monitor_size(struct sys_window *sys_window) struct v2 sys_window_get_monitor_size(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
return V2((f32)window->monitor_width, (f32)window->monitor_height); return V2((f32)window->monitor_width, (f32)window->monitor_height);
} }
u64 sys_window_get_internal_handle(struct sys_window *sys_window) u64 sys_window_get_internal_handle(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
return (u64)window->hwnd; return (u64)window->hwnd;
} }
void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos) void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
window->cursor_set_position = pos; window->cursor_set_position = pos;
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_POSITION; window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_POSITION;
win32_window_wake(window); win32_window_wake(window);
@ -1533,21 +1527,21 @@ void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos)
void sys_window_cursor_show(struct sys_window *sys_window) void sys_window_cursor_show(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_SHOW; window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_SHOW;
win32_window_wake(window); win32_window_wake(window);
} }
void sys_window_cursor_hide(struct sys_window *sys_window) void sys_window_cursor_hide(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_HIDE; window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_HIDE;
win32_window_wake(window); win32_window_wake(window);
} }
void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bounds) void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bounds)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
window->cursor_clip_bounds = bounds; window->cursor_clip_bounds = bounds;
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP; window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP;
win32_window_wake(window); win32_window_wake(window);
@ -1555,7 +1549,7 @@ void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bo
void sys_window_cursor_disable_clip(struct sys_window *sys_window) void sys_window_cursor_disable_clip(struct sys_window *sys_window)
{ {
struct win32_window *window = (struct win32_window *)sys_window->handle; struct win32_window *window = (struct win32_window *)sys_window;
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP; window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP;
win32_window_wake(window); win32_window_wake(window);
} }
@ -1915,14 +1909,13 @@ INTERNAL DWORD WINAPI win32_thread_proc(LPVOID vt)
return 0; return 0;
} }
struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, void *thread_data, struct string thread_name) struct sys_thread *sys_thread_alloc(sys_thread_entry_point_func *entry_point, void *thread_data, struct string thread_name)
{ {
__prof; __prof;
struct arena_temp scratch = scratch_begin_no_conflict(); struct arena_temp scratch = scratch_begin_no_conflict();
ASSERT(entry_point != NULL); ASSERT(entry_point != NULL);
logf_info("Creating thread \"%F\"", FMT_STR(thread_name)); logf_info("Creating thread \"%F\"", FMT_STR(thread_name));
struct sys_thread res = ZI;
/* Allocate thread object */ /* Allocate thread object */
struct win32_thread *t = win32_thread_alloc(); struct win32_thread *t = win32_thread_alloc();
@ -1955,9 +1948,8 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi
sys_panic(LIT("Failed to create thread")); sys_panic(LIT("Failed to create thread"));
} }
res.handle = (u64)t;
scratch_end(scratch); scratch_end(scratch);
return res; return (struct sys_thread *)t;
} }
void sys_thread_wait_release(struct sys_thread *thread) void sys_thread_wait_release(struct sys_thread *thread)
@ -1972,7 +1964,7 @@ b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds)
{ {
__prof; __prof;
b32 success = false; b32 success = false;
struct win32_thread *t = (struct win32_thread *)thread->handle; struct win32_thread *t = (struct win32_thread *)thread;
HANDLE handle = t->handle; HANDLE handle = t->handle;
/* Wait for thread to stop */ /* Wait for thread to stop */
@ -1992,7 +1984,7 @@ b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds)
void sys_thread_force_release(struct sys_thread *thread) void sys_thread_force_release(struct sys_thread *thread)
{ {
__prof; __prof;
struct win32_thread *t = (struct win32_thread *)thread->handle; struct win32_thread *t = (struct win32_thread *)thread;
HANDLE handle = t->handle; HANDLE handle = t->handle;
/* Wait for thread to stop */ /* Wait for thread to stop */
@ -2409,13 +2401,13 @@ 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 */ /* Start app thread */
struct sys_thread app_thread = sys_thread_alloc(&win32_app_thread_entry_point, NULL, LIT("[P0] App thread")); struct sys_thread *app_thread = sys_thread_alloc(&win32_app_thread_entry_point, NULL, LIT("[P0] App thread"));
/* Get app thread handle */ /* Get app thread handle */
HANDLE app_thread_handle = 0; HANDLE app_thread_handle = 0;
struct sys_lock lock = sys_mutex_lock_s(&G.threads_mutex); struct sys_lock lock = sys_mutex_lock_s(&G.threads_mutex);
{ {
struct win32_thread *wt = (struct win32_thread *)app_thread.handle; struct win32_thread *wt = (struct win32_thread *)app_thread;
app_thread_handle = wt->handle; app_thread_handle = wt->handle;
} }
sys_mutex_unlock(&lock); sys_mutex_unlock(&lock);
@ -2428,7 +2420,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
}; };
DWORD res = WaitForMultipleObjects(ARRAY_COUNT(wait_handles), wait_handles, false, INFINITE); DWORD res = WaitForMultipleObjects(ARRAY_COUNT(wait_handles), wait_handles, false, INFINITE);
if (res == WAIT_OBJECT_0) { if (res == WAIT_OBJECT_0) {
sys_thread_force_release(&app_thread); sys_thread_force_release(app_thread);
} }
ASSERT(res != WAIT_FAILED); ASSERT(res != WAIT_FAILED);
(UNUSED)res; (UNUSED)res;

View File

@ -50,10 +50,10 @@ struct console_log {
GLOBAL struct { GLOBAL struct {
struct atomic_i32 user_thread_shutdown; struct atomic_i32 user_thread_shutdown;
struct sys_thread user_thread; struct sys_thread *user_thread;
struct atomic_i32 local_sim_thread_shutdown; struct atomic_i32 local_sim_thread_shutdown;
struct sys_thread local_sim_thread; struct sys_thread *local_sim_thread;
struct sim_ctx *local_sim_ctx; struct sim_ctx *local_sim_ctx;
struct arena *arena; struct arena *arena;
@ -281,7 +281,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(user_shutdown)
sys_window_unregister_event_callback(G.window, &window_event_callback); sys_window_unregister_event_callback(G.window, &window_event_callback);
atomic_i32_eval_exchange(&G.user_thread_shutdown, true); atomic_i32_eval_exchange(&G.user_thread_shutdown, true);
sys_thread_wait_release(&G.user_thread); sys_thread_wait_release(G.user_thread);
#if 0 #if 0
if (G.local_sim_ctx) { if (G.local_sim_ctx) {
@ -291,7 +291,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(user_shutdown)
} }
#else #else
atomic_i32_eval_exchange(&G.local_sim_thread_shutdown, true); atomic_i32_eval_exchange(&G.local_sim_thread_shutdown, true);
sys_thread_wait_release(&G.local_sim_thread); sys_thread_wait_release(G.local_sim_thread);
#endif #endif
} }

View File

@ -25,7 +25,7 @@
*/ */
struct worker { struct worker {
struct sys_thread thread; struct sys_thread *thread;
struct worker *next; struct worker *next;
}; };
@ -154,7 +154,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(work_shutdown)
sys_mutex_unlock(&lock); sys_mutex_unlock(&lock);
for (struct worker *worker = G.worker_head; worker; worker = worker->next) { for (struct worker *worker = G.worker_head; worker; worker = worker->next) {
sys_thread_wait_release(&worker->thread); sys_thread_wait_release(worker->thread);
} }
} }