Revision ea068cf1 src/timestamped_list.cpp
src/timestamped_list.cpp | ||
---|---|---|
35 | 35 |
TimestampedList::TimestampedList(unsigned int s) { |
36 | 36 |
// initialize the list to its desired size: |
37 | 37 |
TimestampedFloat now; |
38 |
tsf_list.resize(s, now); |
|
38 |
tsf_list_.resize(s, now);
|
|
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
TimestampedList::TimestampedList(TimestampedList const &l) { |
42 | 42 |
// lock the tsf_list for this access. by doing this we assure |
43 | 43 |
// that no other thread accessing this element can diturb the |
44 | 44 |
// following atomic instructions: |
45 |
mutex::scoped_lock scoped_lock(l.access_mutex); |
|
45 |
mutex::scoped_lock scoped_lock(l.access_mutex_);
|
|
46 | 46 |
|
47 | 47 |
// now do a deep copy with locking! |
48 |
tsf_list = l.tsf_list;
|
|
48 |
tsf_list_ = l.tsf_list_;
|
|
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
void TimestampedList::copy_tsf_list_to(timestamped_float_list_t *target) { |
52 | 52 |
// lock the tsf_list for this access. by doing this we assure |
53 | 53 |
// that no other thread accessing this element can diturb the |
54 | 54 |
// following atomic instructions: |
55 |
mutex::scoped_lock scoped_lock(access_mutex); |
|
55 |
mutex::scoped_lock scoped_lock(access_mutex_);
|
|
56 | 56 |
|
57 |
*target = tsf_list; |
|
57 |
*target = tsf_list_;
|
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
|
... | ... | |
62 | 62 |
// lock the tsf_list for this access. by doing this we assure |
63 | 63 |
// that no other thread accessing this element can diturb the |
64 | 64 |
// following atomic instructions: |
65 |
mutex::scoped_lock scoped_lock(access_mutex); |
|
65 |
mutex::scoped_lock scoped_lock(access_mutex_);
|
|
66 | 66 |
|
67 |
if (tsf_list.empty()) { |
|
67 |
if (tsf_list_.empty()) {
|
|
68 | 68 |
return Timestamp(0, 0); |
69 | 69 |
} |
70 | 70 |
|
71 |
timestamped_float_list_t::iterator it = tsf_list.begin(); |
|
71 |
timestamped_float_list_t::iterator it = tsf_list_.begin();
|
|
72 | 72 |
return it->timestamp; |
73 | 73 |
} |
74 | 74 |
|
... | ... | |
76 | 76 |
// lock the tsf_list for this access. by doing this we assure |
77 | 77 |
// that no other thread accessing this element can diturb the |
78 | 78 |
// following atomic instructions: |
79 |
mutex::scoped_lock scoped_lock(access_mutex); |
|
79 |
mutex::scoped_lock scoped_lock(access_mutex_);
|
|
80 | 80 |
|
81 |
if (tsf_list.empty()) { |
|
81 |
if (tsf_list_.empty()) {
|
|
82 | 82 |
return Timestamp(0, 0); |
83 | 83 |
} |
84 | 84 |
|
85 |
timestamped_float_list_t::iterator it = tsf_list.end(); |
|
85 |
timestamped_float_list_t::iterator it = tsf_list_.end();
|
|
86 | 86 |
it--; |
87 | 87 |
return it->timestamp; |
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
void TimestampedList::insert(Timestamp timestamp, float val) { |
91 | 91 |
// erase first element: |
92 |
tsf_list.pop_front(); |
|
93 |
tsf_list.push_back(TimestampedFloat(timestamp, val)); |
|
92 |
tsf_list_.pop_front();
|
|
93 |
tsf_list_.push_back(TimestampedFloat(timestamp, val));
|
|
94 | 94 |
// printf("insert [%5.3f] = %5.1f\n",timestamp,val); |
95 | 95 |
} |
96 | 96 |
|
... | ... | |
98 | 98 |
// lock the tsf_list for this access. by doing this we assure |
99 | 99 |
// that no other thread accessing this element can diturb the |
100 | 100 |
// following atomic instructions: |
101 |
mutex::scoped_lock scoped_lock(access_mutex); |
|
101 |
mutex::scoped_lock scoped_lock(access_mutex_);
|
|
102 | 102 |
|
103 |
if (tsf_list.empty()) { |
|
103 |
if (tsf_list_.empty()) {
|
|
104 | 104 |
printf("> WARNING: requested newest value from empty list, returning 0.0\n"); |
105 | 105 |
return 0.0; |
106 | 106 |
} |
107 | 107 |
|
108 |
timestamped_float_list_t::iterator it = tsf_list.end(); |
|
108 |
timestamped_float_list_t::iterator it = tsf_list_.end();
|
|
109 | 109 |
it--; |
110 | 110 |
return it->value; |
111 | 111 |
} |
... | ... | |
114 | 114 |
// lock the tsf_list for this access. by doing this we assure |
115 | 115 |
// that no other thread accessing this element can diturb the |
116 | 116 |
// following atomic instructions: |
117 |
mutex::scoped_lock scoped_lock(access_mutex); |
|
117 |
mutex::scoped_lock scoped_lock(access_mutex_);
|
|
118 | 118 |
|
119 | 119 |
TimestampedFloat previous; |
120 | 120 |
// printf("> latency %3.2fms\n", (Timestamped().to_seconds() - target_ts.to_seconds())*1000.0); |
121 | 121 |
|
122 |
for ( timestamped_float_list_t::iterator it = tsf_list.begin(); it != tsf_list.end(); ++it ) {
|
|
122 |
for ( timestamped_float_list_t::iterator it = tsf_list_.begin(); it != tsf_list_.end(); ++it ) {
|
|
123 | 123 |
if (it->timestamp >= target_ts) { |
124 | 124 |
// ok found close target |
125 |
if (it == tsf_list.begin()) { |
|
125 |
if (it == tsf_list_.begin()) {
|
|
126 | 126 |
// no preceding element |
127 | 127 |
printf("> warning, timestamp %6.3f smaller than first element %6.3f in timestamped" |
128 | 128 |
"list. this should not happen (increase ts buffer?)\n", |
129 |
target_ts.to_seconds(), tsf_list.begin()->timestamp.to_seconds()); |
|
129 |
target_ts.to_seconds(), tsf_list_.begin()->timestamp.to_seconds());
|
|
130 | 130 |
return it->value; |
131 | 131 |
} else { |
132 | 132 |
// do interpolation |
Also available in: Unified diff