]> sigrok.org Git - pulseview.git/blame - pv/data/segment.hpp
Free unused segment memory after acquisition
[pulseview.git] / pv / data / segment.hpp
CommitLineData
28a4c9c5 1/*
b3f22de0 2 * This file is part of the PulseView project.
28a4c9c5 3 *
26a883ed 4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
28a4c9c5
JH
5 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
efdec55a 18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28a4c9c5
JH
19 */
20
a38268f0
SA
21#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22#define PULSEVIEW_PV_DATA_SEGMENT_HPP
640d091b 23
60d9b99a
JS
24#include "pv/util.hpp"
25
3b68d03d
JH
26#include <thread>
27#include <mutex>
c82c7e4e 28#include <vector>
7d29656f 29
26a883ed
SA
30namespace SegmentTest {
31struct SmallSize8Single;
32struct MediumSize8Single;
33struct MaxSize8Single;
34struct MediumSize24Single;
35struct MediumSize32Single;
36struct MaxSize32Single;
37struct MediumSize32Multi;
38struct MaxSize32Multi;
39struct MaxSize32MultiIterated;
40}
41
51e77110 42namespace pv {
1b1ec774 43namespace data {
51e77110 44
26a883ed
SA
45typedef struct {
46 uint64_t sample_index, chunk_num, chunk_offs;
47 uint8_t* chunk;
48 uint8_t* value;
49} SegmentRawDataIterator;
50
f3d66e52 51class Segment
28a4c9c5 52{
26a883ed
SA
53private:
54 static const uint64_t MaxChunkSize = 10*1024*1024; /* 10MiB */
55
28a4c9c5 56public:
f3d66e52 57 Segment(uint64_t samplerate, unsigned int unit_size);
f556bc6a 58
f3d66e52 59 virtual ~Segment();
28a4c9c5 60
e7c6e898 61 uint64_t get_sample_count() const;
28a4c9c5 62
60d9b99a 63 const pv::util::Timestamp& start_time() const;
7f4038d6 64
ff008de6
JH
65 double samplerate() const;
66 void set_samplerate(double samplerate);
67
5ad3b48b 68 unsigned int unit_size() const;
6fd14a32 69
5e6967cb
SA
70 void free_unused_memory();
71
28a4c9c5 72protected:
26a883ed
SA
73 void append_single_sample(void *data);
74 void append_samples(void *data, uint64_t samples);
75 uint8_t* get_raw_samples(uint64_t start, uint64_t count) const;
76
77 SegmentRawDataIterator* begin_raw_sample_iteration(uint64_t start) const;
78 void continue_raw_sample_iteration(SegmentRawDataIterator* it, uint64_t increase) const;
79 void end_raw_sample_iteration(SegmentRawDataIterator* it) const;
f556bc6a 80
8dbbc7f0 81 mutable std::recursive_mutex mutex_;
26a883ed
SA
82 std::vector<uint8_t*> data_chunks_;
83 uint8_t* current_chunk_;
84 uint64_t used_samples_, unused_samples_;
8dbbc7f0 85 uint64_t sample_count_;
60d9b99a 86 pv::util::Timestamp start_time_;
ff008de6 87 double samplerate_;
26a883ed 88 uint64_t chunk_size_;
8dbbc7f0 89 unsigned int unit_size_;
26a883ed
SA
90
91 friend struct SegmentTest::SmallSize8Single;
92 friend struct SegmentTest::MediumSize8Single;
93 friend struct SegmentTest::MaxSize8Single;
94 friend struct SegmentTest::MediumSize24Single;
95 friend struct SegmentTest::MediumSize32Single;
96 friend struct SegmentTest::MaxSize32Single;
97 friend struct SegmentTest::MediumSize32Multi;
98 friend struct SegmentTest::MaxSize32Multi;
99 friend struct SegmentTest::MaxSize32MultiIterated;
28a4c9c5 100};
51e77110 101
1b1ec774 102} // namespace data
51e77110 103} // namespace pv
640d091b 104
a38268f0 105#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP