DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
#include <RateLimiter.hpp>
Public Types | |
using | timestamp_t = std::uint64_t |
Public Member Functions | |
RateLimiter (double kilohertz) | |
void | init () |
void | adjust (double kilohertz) |
void | limit () |
Static Public Attributes | |
static constexpr timestamp_t | ns = 1 |
static constexpr timestamp_t | us = 1000 * ns |
static constexpr timestamp_t | ms = 1000 * us |
static constexpr timestamp_t | s = 1000 * ms |
Protected Member Functions | |
timestamp_t | gettime () |
Private Attributes | |
std::atomic< double > | m_kilohertz |
timestamp_t | m_max_overshoot |
std::atomic< timestamp_t > | m_period |
timestamp_t | m_now |
timestamp_t | m_deadline |
RateLimiter usage:
auto limiter = RateLimiter(1000); // 1MHz limiter.init(); while (duration) { // do work limiter.limit(); } NOTES: This rate limiter is a simple implementation that is intended to be used for fast tasks, i.e. tasks that take less or much less time than the time intervals (1 / rate) that the RateLimiter is operating with. It doesn't work correctly if the tasks take longer than 1 / rate.
Definition at line 34 of file RateLimiter.hpp.
using dunedaq::datahandlinglibs::RateLimiter::timestamp_t = std::uint64_t |
Definition at line 37 of file RateLimiter.hpp.
|
inlineexplicit |
Definition at line 43 of file RateLimiter.hpp.
|
inline |
Optionally: adjust rate from another thread
auto adjuster = std::thread([&]() { int newrate = 1000; while (newrate > 0) { limiter.adjust(newrate); newrate–; std::this_thread::sleep_for(std::chrono::seconds(1)); } }
Definition at line 67 of file RateLimiter.hpp.
|
inlineprotected |
Definition at line 98 of file RateLimiter.hpp.
|
inline |
Definition at line 50 of file RateLimiter.hpp.
|
inline |
Definition at line 73 of file RateLimiter.hpp.
|
private |
Definition at line 110 of file RateLimiter.hpp.
|
private |
Definition at line 106 of file RateLimiter.hpp.
|
private |
Definition at line 107 of file RateLimiter.hpp.
|
private |
Definition at line 109 of file RateLimiter.hpp.
|
private |
Definition at line 108 of file RateLimiter.hpp.
|
inlinestaticconstexpr |
Definition at line 40 of file RateLimiter.hpp.
|
inlinestaticconstexpr |
Definition at line 38 of file RateLimiter.hpp.
|
inlinestaticconstexpr |
Definition at line 41 of file RateLimiter.hpp.
|
inlinestaticconstexpr |
Definition at line 39 of file RateLimiter.hpp.