VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
calculate_sample.h File Reference

Per-GUID cumulative sample loss tracker for VLink subscribers. More...

#include <cstdint>
#include <shared_mutex>
#include <unordered_map>
#include "../base/macros.h"
Include dependency graph for calculate_sample.h:

Go to the source code of this file.

Classes

 Thread-safe, per-GUID cumulative sample loss counter. More...

Namespaces

Detailed Description

Per-GUID cumulative sample loss tracker for VLink subscribers.

CalculateSample maintains per-sender (GUID) sequence-number state to detect gaps in the message stream. It is used by DDS and other transports that carry monotonically-increasing sequence numbers with their messages.

Algorithm
For each GUID, the tracker records:
  • first – the first sequence number seen from this sender.
  • expected – the next sequence number expected.
  • lost – cumulative count of skipped sequence numbers.

On each update(seq, guid) call:

  • If expected == 0 or the gap looks like a reset, the state is re-initialised (no loss recorded for the first message).
  • Otherwise, lost is incremented by the difference (seq - expected), and expected is set to seq + 1.
Thread Safety
All public methods are thread-safe; update() uses an exclusive lock and get_total() / get_lost() use a shared lock.
Note
  • A gap larger than UINT32_MAX between consecutive sequence numbers is treated as a counter reset rather than a loss event.
  • get_total() returns the sum over all GUIDs of (expected - first), i.e. the number of expected messages.