Commit: a96be2de9b6ffc5d7349b23c0598b74c2cb49e68
Parent: 02758349963bb84edced94d529b462316c77ae6e
Author: Randy Palamar
Date: Thu, 3 Oct 2024 08:57:34 -0600
remove os specific file stats structure
Diffstat:
4 files changed, 23 insertions(+), 52 deletions(-)
diff --git a/beamformer.h b/beamformer.h
@@ -100,6 +100,12 @@ typedef struct {
b32 upload;
} BeamformerParametersFull;
+typedef struct {
+ size filesize;
+ u64 timestamp;
+} FileStats;
+#define ERROR_FILE_STATS (FileStats){.filesize = -1}
+
#if defined(__unix__)
#include "os_unix.c"
@@ -149,7 +155,7 @@ typedef CUDA_HILBERT_FN(cuda_hilbert_fn);
typedef struct {
os_library_handle lib;
- os_filetime timestamp;
+ u64 timestamp;
init_cuda_configuration_fn *init_cuda_configuration;
register_cuda_buffers_fn *register_cuda_buffers;
cuda_decode_fn *cuda_decode;
diff --git a/main.c b/main.c
@@ -24,9 +24,9 @@ static do_beamformer_fn *do_beamformer;
static void
do_debug(void)
{
- static os_filetime updated_time;
- os_file_stats test_stats = os_get_file_stats(OS_DEBUG_LIB_NAME);
- if (test_stats.filesize > 32 && os_filetime_is_newer(test_stats.timestamp, updated_time)) {
+ static f32 updated_time;
+ FileStats test_stats = os_get_file_stats(OS_DEBUG_LIB_NAME);
+ if (test_stats.filesize > 32 && test_stats.timestamp > updated_time) {
os_unload_library(libhandle);
libhandle = os_load_library(OS_DEBUG_LIB_NAME, OS_DEBUG_LIB_TEMP_NAME);
do_beamformer = os_lookup_dynamic_symbol(libhandle, "do_beamformer");
@@ -154,9 +154,9 @@ reload_shaders(BeamformerCtx *ctx, Arena a)
continue;
Arena tmp = a;
- os_file_stats fs = os_get_file_stats(compute_shader_paths[i]);
- s8 shader_text = os_read_file(&tmp, compute_shader_paths[i], fs.filesize);
- u32 shader_id = compile_shader(tmp, GL_COMPUTE_SHADER, shader_text);
+ FileStats fs = os_get_file_stats(compute_shader_paths[i]);
+ s8 shader_text = os_read_file(&tmp, compute_shader_paths[i], fs.filesize);
+ u32 shader_id = compile_shader(tmp, GL_COMPUTE_SHADER, shader_text);
if (shader_id) {
glDeleteProgram(csctx->programs[i]);
@@ -200,8 +200,8 @@ validate_cuda_lib(CudaLib *cl)
static void
check_and_load_cuda_lib(CudaLib *cl)
{
- os_file_stats current = os_get_file_stats(OS_CUDA_LIB_NAME);
- if (!os_filetime_is_newer(current.timestamp, cl->timestamp) || current.filesize < 32)
+ FileStats current = os_get_file_stats(OS_CUDA_LIB_NAME);
+ if (cl->timestamp == current.timestamp || current.filesize < 32)
return;
TraceLog(LOG_INFO, "Loading CUDA lib: %s", OS_CUDA_LIB_NAME);
diff --git a/os_unix.c b/os_unix.c
@@ -12,16 +12,8 @@ typedef struct {
char *name;
} os_pipe;
-typedef struct timespec os_filetime;
-
typedef void *os_library_handle;
-#define ERROR_FILE_STATS (os_file_stats){.timestamp = (os_filetime){0}, .filesize = -1}
-typedef struct {
- size filesize;
- os_filetime timestamp;
-} os_file_stats;
-
static Arena
os_alloc_arena(Arena a, size capacity)
{
@@ -72,7 +64,7 @@ os_write_file(char *fname, s8 raw)
return wlen == raw.len;
}
-static os_file_stats
+static FileStats
os_get_file_stats(char *fname)
{
struct stat st;
@@ -81,9 +73,9 @@ os_get_file_stats(char *fname)
return ERROR_FILE_STATS;
}
- return (os_file_stats){
+ return (FileStats){
.filesize = st.st_size,
- .timestamp = st.st_mtim,
+ .timestamp = st.st_mtim.tv_sec + st.st_mtim.tv_nsec * 1e9,
};
}
@@ -214,16 +206,3 @@ os_unload_library(os_library_handle h)
if (h)
dlclose(h);
}
-
-static b32
-os_filetime_is_newer(os_filetime a, os_filetime b)
-{
- os_filetime result;
- result.tv_sec = a.tv_sec - b.tv_sec;
- result.tv_nsec = a.tv_nsec - b.tv_nsec;
- if (result.tv_nsec < 0) {
- result.tv_sec--;
- result.tv_nsec += 1000000000L;
- }
- return result.tv_sec + result.tv_nsec > 0;
-}
diff --git a/os_win32.c b/os_win32.c
@@ -18,15 +18,8 @@ typedef struct {
char *name;
} os_pipe;
-typedef FILETIME os_filetime;
typedef HANDLE os_library_handle;
-#define ERROR_FILE_STATS (os_file_stats){.timestamp = (os_filetime){0}, .filesize = -1}
-typedef struct {
- size filesize;
- os_filetime timestamp;
-} os_file_stats;
-
static Arena
os_alloc_arena(Arena a, size capacity)
{
@@ -89,7 +82,7 @@ os_write_file(char *fname, s8 raw)
return wlen == raw.len;
}
-static os_file_stats
+static FileStats
os_get_file_stats(char *fname)
{
HANDLE h = CreateFileA(fname, 0, 0, 0, OPEN_EXISTING, 0, 0);
@@ -107,10 +100,10 @@ os_get_file_stats(char *fname)
size filesize = (size)fileinfo.nFileSizeHigh << 32;
filesize |= (size)fileinfo.nFileSizeLow;
- return (os_file_stats){
- .filesize = filesize,
- .timestamp = fileinfo.ftLastWriteTime,
- };
+ u64 timestamp = (u64)fileinfo.ftLastWriteTime.dwHighDateTime << 32;
+ timestamp |= (u64)fileinfo.ftLastWriteTime.dwLowDateTime;
+
+ return (FileStats){.filesize = filesize, .timestamp = timestamp};
}
/* NOTE: win32 doesn't pollute the filesystem so no need to waste the user's time */
@@ -196,10 +189,3 @@ os_unload_library(os_library_handle h)
{
FreeLibrary(h);
}
-
-static b32
-os_filetime_is_newer(os_filetime a, os_filetime b)
-{
- b32 result = CompareFileTime(&a, &b) > 0;
- return result;
-}