Package frc.lib
Class PrimitiveQueue
java.lang.Object
frc.lib.PrimitiveQueue
A Thread-Safe, GC-Free SPSC (Single-Producer Single-Consumer) Ring Buffer for primitive doubles.
This implementation allows the 200Hz odometry thread and 50Hz main thread to communicate without
locks.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
data
public final double[] dataThe array holding the primitive doubles.
-
-
Constructor Details
-
PrimitiveQueue
public PrimitiveQueue()
-
-
Method Details
-
offer
public void offer(double val) Offers a new value to the queue. Safe to call from the high-frequency thread.- Parameters:
val- The value to offer to the queue.
-
size
public int size()Returns the number of elements currently available to read.- Returns:
- The number of elements in the queue.
-
poll
public double poll()Drains one element from the queue.- Returns:
- The oldest value in the queue, or 0.0 if empty.
-
clear
public void clear()Clears the queue by syncing the tail to the head.
-