proper cmake

This commit is contained in:
2023-06-04 16:10:06 +02:00
parent 13a8b4c35d
commit fdcb0cf0c4
154 changed files with 1273 additions and 1620 deletions

View File

@@ -0,0 +1,31 @@
//
// Created by Stepan Usatiuk on 05.05.2023.
//
#include "../includes/RunningAverage.h"
RunningAverage::RunningAverage(std::function<unsigned long long int()> getFunc, int max, int ms)
: getFunc(std::move(getFunc)), max(max), ms(ms), thread(&RunningAverage::loop, this) {
}
void RunningAverage::loop() {
while (!stop) {
{
std::lock_guard lock(dataLock);
data.emplace_front(getFunc());
if (data.size() > max) data.pop_back();
}
std::this_thread::sleep_for(std::chrono::duration(std::chrono::milliseconds(ms)));
}
}
RunningAverage::~RunningAverage() {
stop = true;
thread.join();
}
unsigned long long RunningAverage::get() {
std::lock_guard lock(dataLock);
if (data.empty()) return 0;
return std::accumulate(data.begin(), data.end(), 0UL) / data.size();
}