Commit: 61dff5f151e6b31211a1ad349c992880bbfea9c3
Parent: fecdf9e1bae62c4807bbbfeafea40d8426765f75
Author: Randy Palamar
Date: Tue, 8 Oct 2024 14:55:45 -0600
use X macro to simplify some definitions
Diffstat:
4 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/beamformer.h b/beamformer.h
@@ -81,13 +81,18 @@ CUDA_DECODE_FN(cuda_decode_stub) {}
typedef CUDA_HILBERT_FN(cuda_hilbert_fn);
CUDA_HILBERT_FN(cuda_hilbert_stub) {}
+#define CUDA_LIB_FNS \
+ X(cuda_decode) \
+ X(cuda_hilbert) \
+ X(init_cuda_configuration) \
+ X(register_cuda_buffers)
+
typedef struct {
void *lib;
u64 timestamp;
- init_cuda_configuration_fn *init_cuda_configuration;
- register_cuda_buffers_fn *register_cuda_buffers;
- cuda_decode_fn *cuda_decode;
- cuda_hilbert_fn *cuda_hilbert;
+ #define X(name) name ## _fn *name;
+ CUDA_LIB_FNS
+ #undef X
} CudaLib;
#include "beamformer_parameters.h"
diff --git a/main_generic.c b/main_generic.c
@@ -35,12 +35,11 @@ main(void)
{
BeamformerCtx ctx = {0};
Arena temp_memory = os_alloc_arena((Arena){0}, 16 * MEGABYTE);
+ ctx.error_stream = stream_alloc(&temp_memory, 1 * MEGABYTE);
- ctx.error_stream = stream_alloc(&temp_memory, 1 * MEGABYTE);
- ctx.platform.alloc_arena = os_alloc_arena;
- ctx.platform.poll_pipe = os_poll_pipe;
- ctx.platform.read_pipe = os_read_pipe;
- ctx.platform.write_new_file = os_write_new_file;
+ #define X(name) ctx.platform.name = os_ ## name;
+ PLATFORM_FNS
+ #undef X
setup_beamformer(&ctx, temp_memory);
diff --git a/static.c b/static.c
@@ -212,10 +212,9 @@ reload_shaders(BeamformerCtx *ctx, Arena a)
static void
validate_cuda_lib(CudaLib *cl)
{
- if (!cl->init_cuda_configuration) cl->init_cuda_configuration = init_cuda_configuration_stub;
- if (!cl->register_cuda_buffers) cl->register_cuda_buffers = register_cuda_buffers_stub;
- if (!cl->cuda_decode) cl->cuda_decode = cuda_decode_stub;
- if (!cl->cuda_hilbert) cl->cuda_hilbert = cuda_hilbert_stub;
+ #define X(name) if (!cl->name) cl->name = name ## _stub;
+ CUDA_LIB_FNS
+ #undef X
}
static void
@@ -230,12 +229,9 @@ check_and_load_cuda_lib(CudaLib *cl, Stream *error_stream)
cl->timestamp = current.timestamp;
os_unload_library(cl->lib);
cl->lib = os_load_library(OS_CUDA_LIB_NAME, OS_CUDA_LIB_TEMP_NAME, error_stream);
-
- cl->init_cuda_configuration = os_lookup_dynamic_symbol(cl->lib, "init_cuda_configuration", error_stream);
- cl->register_cuda_buffers = os_lookup_dynamic_symbol(cl->lib, "register_cuda_buffers", error_stream);
- cl->cuda_decode = os_lookup_dynamic_symbol(cl->lib, "cuda_decode", error_stream);
- cl->cuda_hilbert = os_lookup_dynamic_symbol(cl->lib, "cuda_hilbert", error_stream);
-
+ #define X(name) cl->name = os_lookup_dynamic_symbol(cl->lib, #name, error_stream);
+ CUDA_LIB_FNS
+ #undef X
validate_cuda_lib(cl);
}
diff --git a/util.h b/util.h
@@ -153,12 +153,15 @@ typedef PLATFORM_READ_PIPE_FN(platform_read_pipe_fn);
#define PLATFORM_WRITE_NEW_FILE_FN(name) b32 name(char *fname, s8 raw)
typedef PLATFORM_WRITE_NEW_FILE_FN(platform_write_new_file_fn);
-typedef struct {
- platform_alloc_arena_fn *alloc_arena;
- platform_poll_pipe_fn *poll_pipe;
- platform_read_pipe_fn *read_pipe;
- platform_write_new_file_fn *write_new_file;
-} Platform;
+#define PLATFORM_FNS \
+ X(alloc_arena) \
+ X(poll_pipe) \
+ X(read_pipe) \
+ X(write_new_file)
+
+#define X(name) platform_ ## name ## _fn *name;
+typedef struct { PLATFORM_FNS } Platform;
+#undef X
#include "util.c"