1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/object.hpp"
8 #include <boost/thread/mutex.hpp>
15 * A ring buffer that holds a pre-defined number of integers.
19 class RingBuffer final
22 DECLARE_PTR_TYPEDEFS(RingBuffer);
24 typedef std::vector<int>::size_type SizeType;
26 RingBuffer(SizeType slots);
28 SizeType GetLength() const;
29 void InsertValue(SizeType tv, int num);
30 int UpdateAndGetValues(SizeType tv, SizeType span);
31 double CalculateRate(SizeType tv, SizeType span);
34 mutable boost::mutex m_Mutex;
35 std::vector<int> m_Slots;
37 SizeType m_InsertedValues;
39 void InsertValueUnlocked(SizeType tv, int num);
40 int UpdateAndGetValuesUnlocked(SizeType tv, SizeType span);
45 #endif /* RINGBUFFER_H */