Skip to content
Snippets Groups Projects
Commit 5f9ee990 authored by Jens Georg's avatar Jens Georg
Browse files

Improve location locking in updater

 - Preallocate the unordered set with worst-case size before the loop
 - Perform insert and lock in one step using the return value of insert
parent 36a351eb
No related branches found
No related tags found
No related merge requests found
......@@ -36,22 +36,26 @@ namespace ChimeraTK {
return;
}
// Worst-case: We need to lock all locations, so pre-allocate this here
std::unordered_set<EqFct*> locationsToLock;
locationsToLock.reserve(_toDoocsEqFctMap.size());
ReadAnyGroup group(_elementsToRead.begin(), _elementsToRead.end());
while(true) {
// Wait until any variable got an update
auto notification = group.waitAny();
auto updatedElement = notification.getId();
// Gather all involved locations in a unique set
std::unordered_set<EqFct*> locationsToLock;
for(auto& location : _toDoocsEqFctMap[updatedElement]) locationsToLock.insert(location);
// Lock all involved locations
for(auto& location : locationsToLock) location->lock();
for(auto& location : _toDoocsEqFctMap[updatedElement]) {
if(locationsToLock.insert(location).second) location->lock();
}
// Complete the read transfer of the process variable
notification.accept();
// Call all updater functions
for(auto& updaterFunction : _toDoocsUpdateMap[updatedElement]) updaterFunction();
// Unlock all involved locations
for(auto& location : locationsToLock) location->unlock();
locationsToLock.clear();
// Allow shutting down this thread...
boost::this_thread::interruption_point();
}
......
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