From: Joel Holdsworth Date: Mon, 10 Dec 2012 20:37:23 +0000 (+0000) Subject: Mutex protected snapshot data X-Git-Tag: pulseview-0.1.0~202 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7d29656f1e4de945eee3a9ea5dbc0ef88c4a7e30;p=pulseview.git Mutex protected snapshot data --- diff --git a/pv/datasnapshot.cpp b/pv/datasnapshot.cpp index 31acca16..040d506a 100644 --- a/pv/datasnapshot.cpp +++ b/pv/datasnapshot.cpp @@ -24,6 +24,8 @@ #include #include +using namespace boost; + namespace pv { DataSnapshot::DataSnapshot(int unit_size) : @@ -31,21 +33,25 @@ DataSnapshot::DataSnapshot(int unit_size) : _sample_count(0), _unit_size(unit_size) { + lock_guard lock(_mutex); assert(_unit_size > 0); } DataSnapshot::~DataSnapshot() { + lock_guard lock(_mutex); free(_data); } uint64_t DataSnapshot::get_sample_count() { + lock_guard lock(_mutex); return _sample_count; } void DataSnapshot::append_data(void *data, uint64_t samples) { + lock_guard lock(_mutex); _data = realloc(_data, (_sample_count + samples) * _unit_size); memcpy((uint8_t*)_data + _sample_count * _unit_size, data, samples * _unit_size); diff --git a/pv/datasnapshot.h b/pv/datasnapshot.h index 9c0866d4..2a6651e8 100644 --- a/pv/datasnapshot.h +++ b/pv/datasnapshot.h @@ -25,6 +25,8 @@ extern "C" { #include } +#include + namespace pv { class DataSnapshot @@ -40,6 +42,7 @@ protected: void append_data(void *data, uint64_t samples); protected: + mutable boost::recursive_mutex _mutex; void *_data; uint64_t _sample_count; int _unit_size; diff --git a/pv/logicdatasnapshot.cpp b/pv/logicdatasnapshot.cpp index 1799c2f4..b264980b 100644 --- a/pv/logicdatasnapshot.cpp +++ b/pv/logicdatasnapshot.cpp @@ -29,6 +29,7 @@ #include "logicdatasnapshot.h" +using namespace boost; using namespace std; namespace pv { @@ -43,12 +44,14 @@ LogicDataSnapshot::LogicDataSnapshot( DataSnapshot(logic.unitsize), _last_append_sample(0) { + lock_guard lock(_mutex); memset(_mip_map, 0, sizeof(_mip_map)); append_payload(logic); } LogicDataSnapshot::~LogicDataSnapshot() { + lock_guard lock(_mutex); BOOST_FOREACH(MipMapLevel &l, _mip_map) free(l.data); } @@ -58,6 +61,8 @@ void LogicDataSnapshot::append_payload( { assert(_unit_size == logic.unitsize); + lock_guard lock(_mutex); + append_data(logic.data, logic.length); // Generate the first mip-map from the data @@ -184,6 +189,8 @@ void LogicDataSnapshot::get_subsampled_edges( assert(sig_index >= 0); assert(sig_index < SR_MAX_NUM_PROBES); + lock_guard lock(_mutex); + const uint64_t block_length = (uint64_t)max(min_length, 1.0f); const unsigned int min_level = max((int)floorf(logf(min_length) / LogMipMapScaleFactor) - 1, 0);