summaryrefslogtreecommitdiff
path: root/firehose.c
diff options
context:
space:
mode:
authorGravatar moon <moon@coffin.ir> 2025-09-12 19:29:17 +0330
committerGravatar moon <moon@coffin.ir> 2025-09-12 19:29:17 +0330
commitcad89335a2d03921a0f349673114e0f69adc54d4 (patch)
tree570e84d433abe4b91254f9d5fa15e94b3baa065f /firehose.c
parentstarting commit (diff)
bug fixes
Diffstat (limited to 'firehose.c')
-rw-r--r--firehose.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/firehose.c b/firehose.c
index 240dfd8..67d62c8 100644
--- a/firehose.c
+++ b/firehose.c
@@ -62,6 +62,8 @@ void firehose_push(hash new_hash, uint64_t storage_index) {
uint16_t firehose_get_count() { return firehose_buffer.count; }
uint64_t firehose_get_total_packets() { return firehose_buffer.total_packets; }
+pthread_mutex_t packet_storage_mutex;
+
uint16_t firehose_get_packets(uint64_t offset, uint16_t count, water_splash* output_entries) {
pthread_mutex_lock(&firehose_buffer.mutex);
@@ -80,6 +82,7 @@ uint16_t firehose_get_packets(uint64_t offset, uint16_t count, water_splash* out
}
uint16_t start_index = (firehose_buffer.head + relative_offset) % FIREHOSE_BUFFER_SIZE;
+ pthread_mutex_lock(&packet_storage_mutex);
for (int i = 0; i < count; i++) {
if (relative_offset + i >= firehose_buffer.count) { break; }
@@ -88,6 +91,7 @@ uint16_t firehose_get_packets(uint64_t offset, uint16_t count, water_splash* out
&output_entries[ i ], &firehose_buffer.entries[ current_index ], sizeof(water_splash));
copied_count++;
}
+ pthread_mutex_unlock(&packet_storage_mutex);
pthread_mutex_unlock(&firehose_buffer.mutex);
return copied_count;