diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index d6109928..91dc6789 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -529,6 +529,12 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod _progress = 0; uint64_t sended_len = 0; _is_decoding = true; + + void* lbp_array[35]; + + for (int j =0 ; j < logic_di->dec_num_channels; j++){ + lbp_array[j] = NULL; + } while(i < end_index && !_no_memory && !status->_bStop) { @@ -559,10 +565,11 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod break; } - uint64_t chunk_end = end_index; + uint64_t chunk_end = end_index; for (int j =0 ; j < logic_di->dec_num_channels; j++) { int sig_index = logic_di->dec_channelmap[j]; + void *lbp = NULL; if (sig_index == -1) { chunk.push_back(NULL); @@ -570,9 +577,18 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod } else { if (_snapshot->has_data(sig_index)) { - auto data_ptr = _snapshot->get_samples(i, chunk_end, sig_index); + const uint8_t *data_ptr = _snapshot->get_samples(i, chunk_end, sig_index, &lbp); chunk.push_back(data_ptr); chunk_const.push_back(_snapshot->get_sample(i, sig_index)); + + if (_snapshot->is_able_free() == false) + { + if (lbp_array[j] != lbp){ + if (lbp_array[j] != NULL) + _snapshot->free_decode_lpb(lbp_array[j]); + lbp_array[j] = lbp; + } + } } else { _error_message = L_S(STR_PAGE_MSG, S_ID(IDS_MSG_DECODERSTACK_DECODE_DATA_ERROR), diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index 7648f0c5..9b059ef5 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -560,7 +560,7 @@ void LogicSnapshot::calc_mipmap(unsigned int order, uint8_t index0, uint8_t inde _last_calc_count[order] = samples; } -const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_sample, int sig_index) +const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_sample, int sig_index, void **lbp) { std::lock_guard lock(_mutex); @@ -593,8 +593,12 @@ const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_s if (order == -1 || _ch_data[order][index0].lbp[index1] == NULL) return NULL; - else + else{ + if (lbp != NULL) + *lbp = _ch_data[order][index0].lbp[index1]; + return (uint8_t*)_ch_data[order][index0].lbp[index1] + offset; + } } bool LogicSnapshot::get_sample(uint64_t index, int sig_index) @@ -1243,5 +1247,21 @@ void LogicSnapshot::decode_end() _free_block_list.clear(); } +void LogicSnapshot::free_decode_lpb(void *lbp) +{ + assert(lbp); + + std::lock_guard lock(_mutex); + + for (auto it = _free_block_list.begin(); it != _free_block_list.end(); it++) + { + if ((*it) == lbp){ + _free_block_list.erase(it); + free(lbp); + break; + } + } +} + } // namespace data } // namespace pv diff --git a/DSView/pv/data/logicsnapshot.h b/DSView/pv/data/logicsnapshot.h index 5e64f1cf..1389d8b9 100644 --- a/DSView/pv/data/logicsnapshot.h +++ b/DSView/pv/data/logicsnapshot.h @@ -94,7 +94,7 @@ public: void append_payload(const sr_datafeed_logic &logic); - const uint8_t * get_samples(uint64_t start_sample, uint64_t& end_sample, int sig_index); + const uint8_t * get_samples(uint64_t start_sample, uint64_t& end_sample, int sig_index, void **lbp=NULL); bool get_sample(uint64_t index, int sig_index); @@ -130,6 +130,12 @@ public: void decode_end(); + void free_decode_lpb(void *lbp); + + inline bool is_able_free(){ + return _able_free; + } + private: bool get_sample_unlock(uint64_t index, int sig_index); bool get_sample_self(uint64_t index, int sig_index);