diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-06-19 11:55:32 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:25 -0800 |
commit | b92a8e2f2b548eef7cb5d58edc92d26befcf67d7 (patch) | |
tree | 5b61c013520f76789c70ed8c0e44180674c8f80d /host/lib | |
parent | 67ea15ad4b57c36f8b0dc80a87cf0ac16b585d34 (diff) | |
download | uhd-b92a8e2f2b548eef7cb5d58edc92d26befcf67d7.tar.gz uhd-b92a8e2f2b548eef7cb5d58edc92d26befcf67d7.tar.bz2 uhd-b92a8e2f2b548eef7cb5d58edc92d26befcf67d7.zip |
rfnoc: Add device_id allocator
This is a single atomic allocator in the global uhd::rfnoc namespace, so
that devices can allocate themselves device IDs without having to confer
with the rest of the RFNoC infrastructure.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/include/uhdlib/rfnoc/device_id.hpp | 22 | ||||
-rw-r--r-- | host/lib/rfnoc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/rfnoc/device_id.cpp | 17 |
3 files changed, 40 insertions, 0 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/device_id.hpp b/host/lib/include/uhdlib/rfnoc/device_id.hpp new file mode 100644 index 000000000..d4cecc840 --- /dev/null +++ b/host/lib/include/uhdlib/rfnoc/device_id.hpp @@ -0,0 +1,22 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_DEVICE_ID_HPP +#define INCLUDED_LIBUHD_DEVICE_ID_HPP + +#include <uhdlib/rfnoc/rfnoc_common.hpp> + +namespace uhd { namespace rfnoc { + +//! Return a new, unique device ID. +// +// This function will never return the same device ID twice. +device_id_t allocate_device_id(); + +}} /* namespace uhd::rfnoc */ + +#endif /* INCLUDED_LIBUHD_DEVICE_ID_HPP */ + diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt index 1b627d304..0f9d62c51 100644 --- a/host/lib/rfnoc/CMakeLists.txt +++ b/host/lib/rfnoc/CMakeLists.txt @@ -24,6 +24,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/chdr_packet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_zero.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ctrl_iface.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/device_id.cpp ${CMAKE_CURRENT_SOURCE_DIR}/epid_allocator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graph_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graph.cpp diff --git a/host/lib/rfnoc/device_id.cpp b/host/lib/rfnoc/device_id.cpp new file mode 100644 index 000000000..6bd287dce --- /dev/null +++ b/host/lib/rfnoc/device_id.cpp @@ -0,0 +1,17 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include <uhdlib/rfnoc/device_id.hpp> +#include <atomic> + +using namespace uhd::rfnoc; + +device_id_t uhd::rfnoc::allocate_device_id() +{ + static std::atomic<device_id_t> counter{1}; + return counter++; +} + |