Line data Source code
1 : /**
2 : * @file ListStorage.cpp ListStorage implementations
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "ListStorage.hpp"
10 : #include "CommonIssues.hpp"
11 :
12 : bool
13 65013 : dunedaq::listrev::ListStorage::has_list(const int& id) const
14 : {
15 65013 : std::lock_guard<std::mutex> lk(m_lists_mutex);
16 130026 : return m_lists.count(id);
17 65013 : }
18 :
19 : dunedaq::listrev::IntList
20 5 : dunedaq::listrev::ListStorage::get_list(const int& id) const
21 : {
22 5 : std::lock_guard<std::mutex> lk(m_lists_mutex);
23 5 : if (!m_lists.count(id)) {
24 1 : throw ListNotFound(ERS_HERE, id);
25 : }
26 :
27 8 : return m_lists.at(id);
28 5 : }
29 :
30 : void
31 7 : dunedaq::listrev::ListStorage::add_list(IntList list, bool ignoreDuplicates)
32 : {
33 7 : std::lock_guard<std::mutex> lk(m_lists_mutex);
34 7 : if (m_lists.count(list.list_id) && !ignoreDuplicates) {
35 1 : throw ListExists(ERS_HERE, list.list_id);
36 : }
37 6 : m_lists[list.list_id] = list;
38 :
39 7 : while (m_lists.size() > m_capacity) {
40 1 : m_lists.erase(m_lists.begin());
41 : }
42 7 : }
43 :
44 : size_t
45 7 : dunedaq::listrev::ListStorage::size() const
46 : {
47 7 : std::lock_guard<std::mutex> lk(m_lists_mutex);
48 14 : return m_lists.size();
49 7 : }
50 :
51 : void
52 3 : dunedaq::listrev::ListStorage::flush()
53 : {
54 3 : std::lock_guard<std::mutex> lk(m_lists_mutex);
55 3 : m_lists.clear();
56 3 : }
|