Package frc.lib

Class PrimitiveQueue

java.lang.Object
frc.lib.PrimitiveQueue

public class PrimitiveQueue extends Object
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
    Modifier and Type
    Field
    Description
    final double[]
    The array holding the primitive doubles.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the queue by syncing the tail to the head.
    void
    offer(double val)
    Offers a new value to the queue.
    double
    Drains one element from the queue.
    int
    Returns the number of elements currently available to read.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • data

      public final double[] data
      The 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.