diff options
author | Martin Braun <martin.braun@ettus.com> | 2020-03-02 15:25:13 -0800 |
---|---|---|
committer | atrnati <54334261+atrnati@users.noreply.github.com> | 2020-03-03 08:51:32 -0600 |
commit | 876d4150aa3da531ddd687b48afada6e43f79146 (patch) | |
tree | fd72a71419f4cd800d4e500cfcaded4dfc8dc367 /host/lib/include/uhdlib/utils/atomic.hpp | |
parent | 1393553d623bdf4ba40d5435c9719b6ce990d9ac (diff) | |
download | uhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.gz uhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.bz2 uhd-876d4150aa3da531ddd687b48afada6e43f79146.zip |
uhd: Apply clang-format against all .cpp and .hpp files in host/
Note: template_lvbitx.{cpp,hpp} need to be excluded from the list of
files that clang-format gets applied against.
Diffstat (limited to 'host/lib/include/uhdlib/utils/atomic.hpp')
-rw-r--r-- | host/lib/include/uhdlib/utils/atomic.hpp | 99 |
1 files changed, 51 insertions, 48 deletions
diff --git a/host/lib/include/uhdlib/utils/atomic.hpp b/host/lib/include/uhdlib/utils/atomic.hpp index 303df1bc9..98b1cfa7b 100644 --- a/host/lib/include/uhdlib/utils/atomic.hpp +++ b/host/lib/include/uhdlib/utils/atomic.hpp @@ -14,62 +14,65 @@ #include <atomic> #include <chrono> -namespace uhd{ +namespace uhd { - /*! DEPRECATED -- Will be removed in coming versions of UHD. - * - * Spin-wait on a condition with a timeout. - * \param cond an atomic variable to compare - * \param value compare to atomic for true/false - * \param timeout the timeout in seconds - * \return true for cond == value, false for timeout - */ - template<typename T> - UHD_INLINE bool spin_wait_with_timeout( - std::atomic<T> &cond, - const T value, - const double timeout - ){ - if (cond == value) return true; - const auto exit_time = std::chrono::high_resolution_clock::now() - + std::chrono::microseconds(int64_t(timeout * 1e6)); - while (cond != value) { - if (std::chrono::high_resolution_clock::now() > exit_time) { - return false; - } - boost::this_thread::interruption_point(); - boost::this_thread::yield(); - } +/*! DEPRECATED -- Will be removed in coming versions of UHD. + * + * Spin-wait on a condition with a timeout. + * \param cond an atomic variable to compare + * \param value compare to atomic for true/false + * \param timeout the timeout in seconds + * \return true for cond == value, false for timeout + */ +template <typename T> +UHD_INLINE bool spin_wait_with_timeout( + std::atomic<T>& cond, const T value, const double timeout) +{ + if (cond == value) return true; + const auto exit_time = std::chrono::high_resolution_clock::now() + + std::chrono::microseconds(int64_t(timeout * 1e6)); + while (cond != value) { + if (std::chrono::high_resolution_clock::now() > exit_time) { + return false; + } + boost::this_thread::interruption_point(); + boost::this_thread::yield(); } + return true; +} - /*! DEPRECATED -- Will be removed in coming versions of UHD. - * - * Claimer class to provide synchronization for multi-thread access. - * Claiming enables buffer classes to be used with a buffer queue. - */ - class simple_claimer{ - public: - simple_claimer(void){ - this->release(); - } +/*! DEPRECATED -- Will be removed in coming versions of UHD. + * + * Claimer class to provide synchronization for multi-thread access. + * Claiming enables buffer classes to be used with a buffer queue. + */ +class simple_claimer +{ +public: + simple_claimer(void) + { + this->release(); + } - UHD_INLINE void release(void){ - _locked = false; - } + UHD_INLINE void release(void) + { + _locked = false; + } - UHD_INLINE bool claim_with_wait(const double timeout){ - if (spin_wait_with_timeout(_locked, false, timeout)){ - _locked = true; - return true; - } - return false; + UHD_INLINE bool claim_with_wait(const double timeout) + { + if (spin_wait_with_timeout(_locked, false, timeout)) { + _locked = true; + return true; } + return false; + } - private: - std::atomic<bool> _locked; - }; +private: + std::atomic<bool> _locked; +}; -} //namespace uhd +} // namespace uhd #endif /* INCLUDED_UHD_UTILS_ATOMIC_HPP */ |