aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-08-24 14:37:08 -0700
committerMartin Braun <martin.braun@ettus.com>2018-03-05 13:53:45 -0800
commit347bb79d2adef4b5bf3e3a94577ecc18c0408519 (patch)
tree9812aa2b939c8697abd91218bda5c0d1dd1131c3 /host/lib
parent988b6ecab417dc8e5ac225e112b33c2b2f6193ad (diff)
downloaduhd-347bb79d2adef4b5bf3e3a94577ecc18c0408519.tar.gz
uhd-347bb79d2adef4b5bf3e3a94577ecc18c0408519.tar.bz2
uhd-347bb79d2adef4b5bf3e3a94577ecc18c0408519.zip
uhd: Removed atomic.hpp from public API
atomic.hpp defines a spin lock and a lockfree mutex. There is no reason to have standard constructs in the public API, where we're contractually obligated to not touch them. Thus, moving them into the internal API space.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/include/CMakeLists.txt4
-rw-r--r--host/lib/include/uhd/utils/atomic.hpp74
2 files changed, 76 insertions, 2 deletions
diff --git a/host/lib/include/CMakeLists.txt b/host/lib/include/CMakeLists.txt
index 5eea68f80..a688f4ea9 100644
--- a/host/lib/include/CMakeLists.txt
+++ b/host/lib/include/CMakeLists.txt
@@ -1,7 +1,7 @@
#
-# Copyright 2017 Ettus Research, a National Instruments Company
+# Copyright 2017 Ettus Research (National Instruments Corp.)
#
-# SPDX-License-Identifier: GPL-3.0
+# SPDX-License-Identifier: GPL-3.0+
#
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/host/lib/include/uhd/utils/atomic.hpp b/host/lib/include/uhd/utils/atomic.hpp
new file mode 100644
index 000000000..86b1dddda
--- /dev/null
+++ b/host/lib/include/uhd/utils/atomic.hpp
@@ -0,0 +1,74 @@
+//
+// Copyright 2012-2013,2016-2017 Ettus Research LLC
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#ifndef INCLUDED_UHD_UTILS_ATOMIC_HPP
+#define INCLUDED_UHD_UTILS_ATOMIC_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/utils/system_time.hpp>
+#include <uhd/types/time_spec.hpp>
+#include <boost/thread/thread.hpp>
+#include <atomic>
+
+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 time_spec_t exit_time = uhd::get_system_time() + time_spec_t(timeout);
+ while (cond != value) {
+ if (uhd::get_system_time() > 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();
+ }
+
+ 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;
+ }
+
+ private:
+ std::atomic<bool> _locked;
+ };
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_UTILS_ATOMIC_HPP */