Commit: 12f83e155798d5f4c2d40619a8dd7a16172568e5
Parent: 14210663e96d01a0342b675b2b0d03c2255a9c7c
Author: Randy Palamar
Date: Wed, 2 Oct 2024 10:18:42 -0600
close and reopen pipe after reading to avoid stale data
Diffstat:
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -398,18 +398,25 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
void *rf_data_buf = cs->raw_data_arena.beg + raw_index * rf_raw_size;
size rlen = os_read_pipe_data(ctx->data_pipe, rf_data_buf, rf_raw_size);
- switch (ctx->gl_vendor_id) {
- case GL_VENDOR_INTEL:
- /* TODO: intel complains about this buffer being busy even with
- * MAP_UNSYNCHRONIZED_BIT */
- case GL_VENDOR_AMD:
- break;
- case GL_VENDOR_NVIDIA:
- glNamedBufferSubData(cs->raw_data_ssbo, raw_index * rf_raw_size,
- rf_raw_size, rf_data_buf);
+ if (rlen != rf_raw_size) {
+ ctx->partial_transfer_count++;
+ } else {
+ ctx->flags |= DO_COMPUTE;
+ switch (ctx->gl_vendor_id) {
+ case GL_VENDOR_INTEL:
+ /* TODO: intel complains about this buffer being busy even with
+ * MAP_UNSYNCHRONIZED_BIT */
+ case GL_VENDOR_AMD:
+ break;
+ case GL_VENDOR_NVIDIA:
+ glNamedBufferSubData(cs->raw_data_ssbo, raw_index * rf_raw_size,
+ rf_raw_size, rf_data_buf);
+ }
}
- if (rlen == rf_raw_size) ctx->flags |= DO_COMPUTE;
- else ctx->partial_transfer_count++;
+ /* NOTE: close and reopen the pipe to avoid stale data */
+ /* TODO: performance!! */
+ os_close_named_pipe(ctx->data_pipe);
+ ctx->data_pipe = os_open_named_pipe(OS_PIPE_NAME);
}
/* NOTE: we are starting a volume computation on this frame so make some space */
diff --git a/helpers/ogl_beamformer_lib.c b/helpers/ogl_beamformer_lib.c
@@ -56,9 +56,9 @@ os_write_to_pipe(os_pipe p, void *data, size len)
}
static void
-os_close_pipe(void)
+os_close_pipe(os_pipe p)
{
- close(g_pipe.file);
+ close(p.file);
}
static BeamformerParametersFull *
@@ -96,9 +96,9 @@ os_write_to_pipe(os_pipe p, void *data, size len)
}
static void
-os_close_pipe(void)
+os_close_pipe(os_pipe p)
{
- CloseHandle(g_pipe.file);
+ CloseHandle(p.file);
}
static BeamformerParametersFull *
@@ -162,12 +162,10 @@ set_beamformer_pipeline(char *shm_name, i32 *stages, i32 stages_count)
void
send_data(char *pipe_name, char *shm_name, i16 *data, uv2 data_dim)
{
+ g_pipe = os_open_named_pipe(pipe_name);
if (g_pipe.file == OS_INVALID_FILE) {
- g_pipe = os_open_named_pipe(pipe_name);
- if (g_pipe.file == OS_INVALID_FILE) {
- mexErrMsgIdAndTxt("ogl_beamformer:pipe_error", "failed to open pipe");
- return;
- }
+ mexErrMsgIdAndTxt("ogl_beamformer:pipe_error", "failed to open pipe");
+ return;
}
check_shared_memory(shm_name);
@@ -179,6 +177,8 @@ send_data(char *pipe_name, char *shm_name, i16 *data, uv2 data_dim)
mexWarnMsgIdAndTxt("ogl_beamformer:write_error",
"failed to write full data to pipe: wrote: %ld", written);
g_bp->upload = 1;
+
+ os_close_pipe(g_pipe);
}
void
diff --git a/os_win32.c b/os_win32.c
@@ -113,10 +113,10 @@ os_get_file_stats(char *fname)
};
}
-/* NOTE: win32 doesn't pollute the filesystem so no need to waste the user's time */
static void
os_close_named_pipe(os_pipe p)
{
+ CloseHandle(p.file);
}
static os_pipe