blob: 97a30dc645fe828fb2e1dd2dc72914f9539c5741 (
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
|
//
// 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::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
}
|