05.03., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit ed361bad authored by Alessio Netti's avatar Alessio Netti

SensorCache cleaning procedure is now also thread-safe

parent 0a2e7e02
......@@ -151,6 +151,8 @@ void SensorCache::dump() {
uint64_t SensorCache::clean(uint64_t t) {
uint64_t thresh = getTimestamp() - t;
uint64_t ctr = 0;
// Spinning on the lock
while (_updating.exchange(true)) {}
for (auto it = sensorCache.cbegin(); it != sensorCache.cend();) {
uint64_t latestTs = it->second.getLatest().timestamp;
if (latestTs!=0 && latestTs < thresh) {
......@@ -159,5 +161,6 @@ uint64_t SensorCache::clean(uint64_t t) {
} else
++it;
}
_updating.store(false);
return ctr;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment