Compare commits

..

No commits in common. "dev" and "atomic_cmake" have entirely different histories.

2 changed files with 9 additions and 10 deletions

View File

@ -38,7 +38,11 @@ map<K, uint64_t> Metrics<K>::get_data() const {
template<typename K>
map<K, uint64_t> Metrics<K>::get_data_and_clear() {
map<K, uint64_t> data = get_data();
map<K, uint64_t> data;
{
shared_lock<shared_mutex> lock(mtx);
auto data = get_data();
}
clear();
return data;
}
@ -53,10 +57,9 @@ template<typename K>
Metrics<K>& Metrics<K>::operator++(int n) {
shared_lock<shared_mutex> lock(mtx);
// Increment all counters by n as an example
// for (auto& counter : counters) {
// counter.second.fetch_add(n, memory_order_relaxed);
// }
n++;
for (auto& counter : counters) {
counter.second.fetch_add(n, memory_order_relaxed);
}
return *this;
}

View File

@ -65,11 +65,7 @@ int main() {
// map<string, uint64_t> MyStats = {{"access", 3},{ "error", 0}};
// stats.set(MyStats);
// // get and clear all counters
auto dataWithClear = metrika.get_data_and_clear();
for (auto& [key, value] : dataWithClear) {
cout << "Log analitic " << key << ", value: " << value << endl;
}
// auto dataWithClear = stats.get_data_and_clear();
return 0;
}