Some fix, check operator++
This commit is contained in:
parent
e659a78bd1
commit
a5efeaf654
@ -38,11 +38,7 @@ map<K, uint64_t> Metrics<K>::get_data() const {
|
|||||||
|
|
||||||
template<typename K>
|
template<typename K>
|
||||||
map<K, uint64_t> Metrics<K>::get_data_and_clear() {
|
map<K, uint64_t> Metrics<K>::get_data_and_clear() {
|
||||||
map<K, uint64_t> data;
|
map<K, uint64_t> data = get_data();
|
||||||
{
|
|
||||||
shared_lock<shared_mutex> lock(mtx);
|
|
||||||
auto data = get_data();
|
|
||||||
}
|
|
||||||
clear();
|
clear();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -57,9 +53,10 @@ template<typename K>
|
|||||||
Metrics<K>& Metrics<K>::operator++(int n) {
|
Metrics<K>& Metrics<K>::operator++(int n) {
|
||||||
shared_lock<shared_mutex> lock(mtx);
|
shared_lock<shared_mutex> lock(mtx);
|
||||||
// Increment all counters by n as an example
|
// Increment all counters by n as an example
|
||||||
for (auto& counter : counters) {
|
// for (auto& counter : counters) {
|
||||||
counter.second.fetch_add(n, memory_order_relaxed);
|
// counter.second.fetch_add(n, memory_order_relaxed);
|
||||||
}
|
// }
|
||||||
|
n++;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,11 @@ int main() {
|
|||||||
// map<string, uint64_t> MyStats = {{"access", 3},{ "error", 0}};
|
// map<string, uint64_t> MyStats = {{"access", 3},{ "error", 0}};
|
||||||
// stats.set(MyStats);
|
// stats.set(MyStats);
|
||||||
// // get and clear all counters
|
// // get and clear all counters
|
||||||
// auto dataWithClear = stats.get_data_and_clear();
|
auto dataWithClear = metrika.get_data_and_clear();
|
||||||
|
|
||||||
|
for (auto& [key, value] : dataWithClear) {
|
||||||
|
cout << "Log analitic " << key << ", value: " << value << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user