blob: 60544eb58f26fa6d731ffe2eb123033ee5773046 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
//
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/exception.hpp>
#include <uhdlib/rfnoc/epid_allocator.hpp>
using namespace uhd;
using namespace uhd::rfnoc;
epid_allocator::epid_allocator(sep_id_t start_epid) : _next_epid(start_epid) {}
sep_id_t epid_allocator::allocate_epid(const sep_addr_t& addr)
{
std::lock_guard<std::mutex> lock(_mutex);
if (_epid_map.count(addr) == 0) {
sep_id_t new_epid = _next_epid++;
_epid_map[addr] = new_epid;
_addr_map[new_epid] = addr;
return new_epid;
} else {
return _epid_map.at(addr);
}
}
sep_id_t epid_allocator::allocate_epid(
const sep_addr_t& addr, mgmt::mgmt_portal& mgmt_portal, chdr_ctrl_xport& xport)
{
std::lock_guard<std::mutex> lock(_mutex);
if (_epid_map.count(addr) == 0) {
sep_id_t new_epid = _next_epid++;
_epid_map[addr] = new_epid;
_addr_map[new_epid] = addr;
mgmt_portal.initialize_endpoint(xport, addr, new_epid);
return new_epid;
} else {
sep_id_t epid = _epid_map.at(addr);
mgmt_portal.register_endpoint(addr, epid);
return epid;
}
}
sep_id_t epid_allocator::get_epid(const sep_addr_t& addr)
{
std::lock_guard<std::mutex> lock(_mutex);
if (_epid_map.count(addr) != 0) {
return _epid_map.at(addr);
} else {
throw uhd::lookup_error(
"An EPID has not been allocated for the requested endpoint");
}
}
sep_addr_t epid_allocator::lookup_addr(const sep_id_t& epid) const
{
std::lock_guard<std::mutex> lock(_mutex);
if (_addr_map.count(epid) > 0) {
return _addr_map.at(epid);
} else {
throw uhd::lookup_error("The specified EPID has not been allocated");
}
}
void epid_allocator::deallocate_epid(sep_id_t)
{
std::lock_guard<std::mutex> lock(_mutex);
// TODO: Nothing to do for deallocate.
// With the current counter approach we assume that we will not run out of EPIDs
}
|