Line data Source code
1 : /**
2 : * @file DpdkMempool.cpp Implementation of the rte_mempool ownership handles.
3 : *
4 : * This is part of the DUNE DAQ , copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 : #include "dpdklibs/DpdkMempool.hpp"
9 :
10 : #include <rte_mempool.h>
11 :
12 : #include <map>
13 : #include <memory>
14 :
15 : namespace dunedaq::dpdklibs {
16 :
17 : void
18 1 : MempoolDeleter::operator()(rte_mempool* pool) const noexcept
19 : {
20 1 : if (pool != nullptr) {
21 0 : rte_mempool_free(pool);
22 : }
23 1 : }
24 :
25 : unique_mempool
26 1 : take_mempool_ownership(std::unique_ptr<rte_mempool>&& legacy)
27 : {
28 1 : return unique_mempool(legacy.release());
29 : }
30 :
31 1 : BorrowedPoolMap::~BorrowedPoolMap()
32 : {
33 3 : for (auto& [index, pool] : m_map) { // NOLINT(readability-qualified-auto)
34 2 : pool.release(); // NOLINT(bugprone-unused-return-value) borrowed; not owned by this map
35 : }
36 1 : }
37 :
38 : void
39 2 : BorrowedPoolMap::borrow(int index, rte_mempool* pool)
40 : {
41 2 : m_map[index].reset(pool);
42 2 : }
43 :
44 : std::map<int, std::unique_ptr<rte_mempool>>&
45 1 : BorrowedPoolMap::get()
46 : {
47 1 : return m_map;
48 : }
49 :
50 : } // namespace dunedaq::dpdklibs
|