From d4444122215a8cc4e9f4604c0430b1b8acadbfa4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Drohomirecki <adrohomirecki@magicleap.com> Date: Wed, 18 May 2022 14:35:40 +0200 Subject: [PATCH] a/math: Add a clear() method to RelationHistory/m_relation_history --- src/xrt/auxiliary/math/m_relation_history.cpp | 7 ++++++ src/xrt/auxiliary/math/m_relation_history.h | 25 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/xrt/auxiliary/math/m_relation_history.cpp b/src/xrt/auxiliary/math/m_relation_history.cpp index af8d819fc..7d5892bf1 100644 --- a/src/xrt/auxiliary/math/m_relation_history.cpp +++ b/src/xrt/auxiliary/math/m_relation_history.cpp @@ -194,6 +194,13 @@ m_relation_history_get_size(const struct m_relation_history *rh) return (uint32_t)rh->impl.size(); } +void +m_relation_history_clear(struct m_relation_history *rh) +{ + std::unique_lock<os::Mutex> lock(rh->mutex); + rh->impl = {}; +} + void m_relation_history_destroy(struct m_relation_history **rh_ptr) { diff --git a/src/xrt/auxiliary/math/m_relation_history.h b/src/xrt/auxiliary/math/m_relation_history.h index cea096397..6eabcb5a8 100644 --- a/src/xrt/auxiliary/math/m_relation_history.h +++ b/src/xrt/auxiliary/math/m_relation_history.h @@ -37,7 +37,7 @@ enum m_relation_history_result }; /*! - * @brief Creates an opaque relation_history object. + * Creates an opaque relation_history object. * * @public @memberof m_relation_history */ @@ -59,7 +59,7 @@ m_relation_history_push(struct m_relation_history *rh, uint64_t timestamp); /*! - * @brief Interpolates or extrapolates to the desired timestamp. + * Interpolates or extrapolates to the desired timestamp. * * Read-only operation - doesn't remove anything from the buffer or anything like that - you can call this as often as * you want. @@ -72,7 +72,7 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation *out_relation); /*! - * @brief Get the latest report in the buffer, if any. + * Get the latest report in the buffer, if any. * * @param rh self * @param[out] out_time_ns Populated with the latest report time, if any @@ -88,13 +88,21 @@ m_relation_history_get_latest(struct m_relation_history *rh, struct xrt_space_relation *out_relation); /*! - * @brief Returns the number of items in the history. + * Returns the number of items in the history. * * @public @memberof m_relation_history */ uint32_t m_relation_history_get_size(const struct m_relation_history *rh); +/*! + * Clears the history from all of the items. + * + * @public @memberof m_relation_history + */ +void +m_relation_history_clear(struct m_relation_history *rh); + /*! * Destroys an opaque relation_history object. * @@ -179,6 +187,15 @@ public: { return m_relation_history_get_size(mPtr); } + + /*! + * @copydoc m_relation_history_clear + */ + void + clear() noexcept + { + return m_relation_history_clear(mPtr); + } }; } // namespace xrt::auxiliary::math