2
0
forked from Ivasoft/DSView

When a memory block decoding is completed, free it

This commit is contained in:
dreamsourcelabTAI
2023-05-31 17:12:44 +08:00
parent 680c1611d7
commit 4c21b1b5c5
3 changed files with 47 additions and 5 deletions

View File

@@ -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),

View File

@@ -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<std::mutex> 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<std::mutex> 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

View File

@@ -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);