mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
one more try
This commit is contained in:
parent
cfaa97d8f3
commit
7de8a2267f
2 changed files with 21 additions and 7 deletions
|
@ -321,8 +321,9 @@ public:
|
|||
static std::atomic<uint64_t> _lastReport;
|
||||
static std::atomic<uint64_t> _maxElapsed;
|
||||
static std::atomic<int> _maxElapsedAverage;
|
||||
bool _quit { false };
|
||||
static ThreadSafeMovingAverage<int, HEARTBEAT_SAMPLES> _movingAverage;
|
||||
|
||||
bool _quit { false };
|
||||
};
|
||||
|
||||
std::atomic<uint64_t> DeadlockWatchdogThread::_heartbeat;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#ifndef hifi_SimpleMovingAverage_h
|
||||
#define hifi_SimpleMovingAverage_h
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <stdint.h>
|
||||
|
||||
class SimpleMovingAverage {
|
||||
|
@ -68,12 +68,17 @@ public:
|
|||
template <class T, int MAX_NUM_SAMPLES> class ThreadSafeMovingAverage {
|
||||
public:
|
||||
void clear() {
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
numSamples = 0;
|
||||
}
|
||||
|
||||
bool isAverageValid() const { return (numSamples > 0); }
|
||||
bool isAverageValid() const {
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
return (numSamples > 0);
|
||||
}
|
||||
|
||||
void addSample(T sample) {
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
if (numSamples > 0) {
|
||||
T lastAverage = average;
|
||||
average = (sample * WEIGHTING) + (lastAverage * ONE_MINUS_WEIGHTING);
|
||||
|
@ -84,14 +89,22 @@ public:
|
|||
numSamples++;
|
||||
}
|
||||
|
||||
T getAverage() const { return average; }
|
||||
T getNumSamples() const { return numSamples; }
|
||||
T getAverage() const {
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
return average;
|
||||
}
|
||||
|
||||
T getNumSamples() const {
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
return numSamples;
|
||||
}
|
||||
|
||||
private:
|
||||
const float WEIGHTING = 1.0f / (float)MAX_NUM_SAMPLES;
|
||||
const float ONE_MINUS_WEIGHTING = 1.0f - WEIGHTING;
|
||||
std::atomic<int> numSamples{ 0 };
|
||||
std::atomic<T> average;
|
||||
int numSamples { 0 };
|
||||
T average;
|
||||
mutable std::mutex _lock;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue