Skip to content

Commit

Permalink
fix: add missing mutex locks
Browse files Browse the repository at this point in the history
  • Loading branch information
vtx22 committed Mar 6, 2025
1 parent 0015a96 commit 27dbc27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/DataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ DataHandler::DataHandler(Serial *sp, ConsoleWindow *console_window) : _sp(sp), _
_serial_buffer.reserve(SPARQ_MAX_MESSAGE_LENGTH * 2);

_receive_thread = std::thread(&DataHandler::receiver_loop, this);
std::cout << "Starting receiver thread\n";
}

DataHandler::~DataHandler()
Expand Down Expand Up @@ -348,7 +349,7 @@ std::vector<sparq_marker_t> &DataHandler::get_markers()

void DataHandler::export_data_csv()
{

std::lock_guard<std::mutex> lock(_data_mutex);
std::cout << "Exporting data to csv...\n";

if (_datasets.size() == 0)
Expand Down Expand Up @@ -419,13 +420,15 @@ uint8_t DataHandler::xor8_cs(const uint8_t *data, uint32_t length)
return cs;
}

double DataHandler::get_max_sample() const
double DataHandler::get_max_sample()
{
std::lock_guard<std::mutex> lock(_data_mutex);
return current_absolute_sample;
}

double DataHandler::get_max_rel_time() const
double DataHandler::get_max_rel_time()
{
std::lock_guard<std::mutex> lock(_data_mutex);
double max_rel_time = 0;

for (const auto &ds : _datasets)
Expand All @@ -439,8 +442,9 @@ double DataHandler::get_max_rel_time() const
return max_rel_time;
}

double DataHandler::get_max_abs_time() const
double DataHandler::get_max_abs_time()
{
std::lock_guard<std::mutex> lock(_data_mutex);
double max_abs_time = 0;

for (const auto &ds : _datasets)
Expand Down
6 changes: 3 additions & 3 deletions src/DataHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class DataHandler

void export_data_csv();

double get_max_sample() const;
double get_max_rel_time() const;
double get_max_abs_time() const;
double get_max_sample();
double get_max_rel_time();
double get_max_abs_time();

sparq_plot_settings_t plot_settings;

Expand Down

0 comments on commit 27dbc27

Please sign in to comment.