From ad7477ed83028f33399b5dfa23186802033e89cf Mon Sep 17 00:00:00 2001 From: Stefan Mertl Date: Wed, 31 Jan 2018 17:28:31 +0100 Subject: [PATCH] Make the last_timestamp access thread save. --- software/c++/ruwaicom/include/recorder.h | 1 + software/c++/ruwaicom/src/recorder.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/software/c++/ruwaicom/include/recorder.h b/software/c++/ruwaicom/include/recorder.h index e6ae4e7..09b7d3b 100644 --- a/software/c++/ruwaicom/include/recorder.h +++ b/software/c++/ruwaicom/include/recorder.h @@ -96,6 +96,7 @@ class Recorder { std::mutex mut_sample_buffer; std::mutex mut_timestamps; + std::mutex mut_last_timestamp; diff --git a/software/c++/ruwaicom/src/recorder.cpp b/software/c++/ruwaicom/src/recorder.cpp index b6e0603..aa9282b 100644 --- a/software/c++/ruwaicom/src/recorder.cpp +++ b/software/c++/ruwaicom/src/recorder.cpp @@ -301,8 +301,10 @@ Recorder::handle_timestamp_sample(rw_smp_24bit_tsp_t paket) } // Store the current timestamp. + mut_last_timestamp.lock(); last_timestamp = cur_timestamp; - + mut_last_timestamp.unlock(); + if (!state_first_timestamp_received) { state_first_timestamp_received = true; @@ -821,11 +823,14 @@ Recorder::copy_files(std::vector files) } - + timestamp_t Recorder::get_last_timestamp(void) { - return last_timestamp; + mut_last_timestamp.lock(); + timestamp_t return_val = last_timestamp; + mut_last_timestamp.unlock(); + return return_val; } -- 2.11.4.GIT