Skip to content
Snippets Groups Projects
Commit e7d0dcdd authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'clear.CxxUtils-20221203' into 'master'

CxxUtils: Add ConcurrentRangeMap::clear().

See merge request !58961
parents fe68a790 52e7f5f8
No related branches found
No related tags found
4 merge requests!59674InDetPerformanceMonitoring with LumiBlock selection,!59383cppcheck in trigger code: Prefer prefix ++/-- operators for non-primitive types.,!58990Draft:Fixing bug in FTF config when running with Reco_tf,!58961CxxUtils: Add ConcurrentRangeMap::clear().
......@@ -479,6 +479,13 @@ public:
size_t trim (const std::vector<key_query_type>& keys);
/**
* @brief Remove all entries in the container.
* Mostly for testing --- should not normally be used.
*/
void clear();
/**
* @brief Return the current number of elements in the map.
*/
......
......@@ -486,7 +486,7 @@ T_CONCURRENTRANGEMAP
void
CONCURRENTRANGEMAP::updateRanges (std::function<void (RANGE&)> rangeUpdater,
const typename Updater_t::Context_t& ctx
/*= Updater_t::defaultContext()*/)
/*= Updater_t::defaultContext()*/)
{
lock_t lock (m_mutex);
......@@ -609,6 +609,38 @@ CONCURRENTRANGEMAP::trim (const std::vector<key_query_type>& keys)
}
/**
* @brief Remove all entries in the container.
* Mostly for testing --- should not normally be used.
*/
T_CONCURRENTRANGEMAP
void CONCURRENTRANGEMAP::clear()
{
lock_t lock (m_mutex);
// Don't do anything if the container's already empty.
value_type* last = m_last;
if (last == nullptr) return;
value_type* begin = m_begin;
while (begin != last) {
mapped_type todel = begin->second;
++begin;
m_begin = begin;
m_payloadDeleter->discard (todel);
}
// Now have one element left. Be sure to clean m_begin first.
mapped_type todel = begin->second;
++begin;
m_begin = nullptr;
m_last = nullptr;
m_begin = begin;
m_payloadDeleter->discard (todel);
}
/**
* @brief Return the current number of elements in the map.
*/
......
test1a
test1b
test1c
test1d
test2
......@@ -869,6 +869,34 @@ void test1c()
}
// Test clear();
void test1d()
{
std::cout << "test1d\n";
Payload::Hist phist;
TestMap map (TestMap::Updater_t(), std::make_shared<PayloadDeleter>(), 3);
assert (map.emplace (Range (10, 20), std::make_unique<Payload> (10, &phist)) ==
TestMap::EmplaceResult::SUCCESS);
assert (map.emplace (Range (20, 30), std::make_unique<Payload> (20, &phist)) ==
TestMap::EmplaceResult::SUCCESS);
assert (map.size() == 2);
assert (phist.size() == 2);
map.clear();
assert (map.size() == 0);
assert (phist.size() == 2);
for (int i=0; i < nslots; i++) {
map.quiescent (i);
}
assert (map.size() == 0);
assert (phist.size() == 0);
assert (map.emplace (Range (40, 50), std::make_unique<Payload> (40, &phist)) ==
TestMap::EmplaceResult::SUCCESS);
assert (map.size() == 1);
assert (phist.size() == 1);
}
//***************************************************************************
// Threaded test.
//
......@@ -1088,6 +1116,7 @@ int main()
test1a();
test1b();
test1c();
test1d();
test2();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment