···8787 os_mutex_lock(&rh->mutex);
8888 m_relation_history_result ret = M_RELATION_HISTORY_RESULT_INVALID;
89899090- if (rh->has_first_sample == 0) {
9090+ if (rh->has_first_sample == 0 || at_timestamp_ns == 0) {
9191 // Do nothing. You push nothing to the buffer you get nothing from the buffer.
9292 goto end;
9393 }
···156156 idx -= step;
157157 continue;
158158 }
159159+ if (ts_before == at_timestamp_ns || ts_after == at_timestamp_ns) {
160160+ // exact match
161161+ break;
162162+ }
159163 if ((ts_before < at_timestamp_ns) && (ts_after > at_timestamp_ns)) {
160160- // Found what we're looking for - at_timestamp_ns is between the reading before us and
161161- // the reading after us. Break out of the loop
164164+ // Found what we're looking for - at_timestamp_ns is between the reading before
165165+ // us and the reading after us. Break out of the loop
162166 break;
163167 }
164168···181185 // Do the thing.
182186 struct xrt_space_relation before = rh->impl[idx]->relation;
183187 struct xrt_space_relation after = rh->impl[idx - 1]->relation;
188188+189189+ if (rh->impl[idx]->timestamp == at_timestamp_ns) {
190190+ // exact match: before
191191+ *out_relation = before;
192192+ ret = M_RELATION_HISTORY_RESULT_EXACT;
193193+ goto end;
194194+ }
195195+ if (rh->impl[idx - 1]->timestamp == at_timestamp_ns) {
196196+ // exact match: after
197197+ *out_relation = after;
198198+ ret = M_RELATION_HISTORY_RESULT_EXACT;
199199+ goto end;
200200+ }
184201 int64_t diff_before, diff_after = 0;
185202 diff_before = at_timestamp_ns - rh->impl[idx]->timestamp;
186203 diff_after = rh->impl[idx - 1]->timestamp - at_timestamp_ns;