make published tick id atomic

This commit is contained in:
jacob 2024-03-15 23:16:39 -05:00
parent 3b0cdfd1f4
commit ba7769fba9
3 changed files with 11 additions and 22 deletions

View File

@ -8,6 +8,7 @@
#include "mixer.h"
#include "math.h"
#include "scratch.h"
#include "atomic.h"
GLOBAL struct {
b32 shutdown;
@ -22,6 +23,7 @@ GLOBAL struct {
/* Game thread output */
struct sys_mutex published_tick_mutex;
struct world published_tick;
struct atomic_u64 published_tick_id;
} L = { 0 }, DEBUG_LVAR(L_game);
/* ========================== *
@ -66,6 +68,7 @@ INTERNAL void publish_game_tick(void)
sys_mutex_lock(&L.published_tick_mutex);
{
world_copy_replace(&L.published_tick, &L.world);
atomic_u64_eval_exchange(&L.published_tick_id, L.published_tick.tick_id);
}
sys_mutex_unlock(&L.published_tick_mutex);
}
@ -577,7 +580,7 @@ void game_get_latest_tick(struct world *dest)
u64 game_get_latest_tick_id(void)
{
return L.published_tick.tick_id;
return atomic_u64_eval(&L.published_tick_id);
}
void game_push_cmds(struct game_cmd_array cmd_array)

View File

@ -59,6 +59,8 @@ struct win32_window {
* their pre-minimized values) */
i32 x, y, width, height;
/* FIXME: Use a cmd buffer for updating cursor (and maybe also settings).
* Current setup means cursor_set calls can be applied out of order */
u32 cursor_set_flags;
struct v2 cursor_set_position;
struct rect cursor_clip_bounds;
@ -767,25 +769,6 @@ INTERNAL void win32_update_window_from_settings(struct win32_window *window, str
SWP_NOZORDER | SWP_NOOWNERZORDER
);
#if 0
if (settings->flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED) {
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
window->flags |= SYS_WINDOW_FLAG_SHOWING;
}
if (settings->flags & SYS_WINDOW_SETTINGS_FLAG_MINIMIZED) {
ShowWindow(hwnd, SW_MINIMIZE);
window->flags |= SYS_WINDOW_FLAG_SHOWING;
}
if (!(window->flags & SYS_WINDOW_FLAG_SHOWING)) {
/* Open window for first time */
ShowWindow(hwnd, SW_NORMAL);
window->flags |= SYS_WINDOW_FLAG_SHOWING;
}
BringWindowToTop(hwnd);
#endif
SetWindowTextA(hwnd, settings->title);
}
@ -1052,7 +1035,7 @@ void sys_window_update_settings(struct sys_window *sys_window, struct sys_window
sys_rw_mutex_unlock_exclusive(&window->settings_rw_mutex);
}
/* TODO: Lock settings mutex for these functions */
/* FIXME: Lock settings mutex for these functions */
struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window)
{

View File

@ -169,8 +169,11 @@ INLINE void sync_flag_wait(struct sync_flag *sf)
__prof;
while (atomic_i32_eval(&sf->flag) == 0) {
sys_mutex_lock(&sf->mutex);
{
sys_condition_variable_wait(&sf->cv, &sf->mutex);
}
sys_mutex_unlock(&sf->mutex);
}
}
/* ========================== *