Based on James Munns' https://github.com/jamesmunns/bbqueue
BBqueue implements lock free, one producer one consumer, BipBuffers.
This unit only handles index offsets without having an internal buffer. It can be used to allocate slices of an existing array, e.g.:
Buf : Storage_Array (8 .. 64) := (others => 0); : aliased Offsets_Only (Buf'Length); G : Write_Grant := BBqueue.Empty; : Slice_Rec;
begin Grant (Q, WG, 8); if State (WG) = Valid then S := Slice (WG); Buf (Buf'First + S.From .. Buf'First + S.To) := (others => 42); Commit (Q, WG); end if;
subtype Buffer_Offset is Storage_Offset range 0 .. Count'Last - 1;
subtype Buffer_Size is Count range 1 .. Count'Last;
procedure Commit (This : in out Offsets_Only;
G : in out Write_Grant;
Size : Count := Count'Last)
Commit a writeable slice. Size can be smaller than the granted slice for partial commits. The commited slice is then available for Read.
subtype Count is Storage_Count;
function Empty return Read_Grant
function Empty return Write_Grant
procedure Grant (This : in out Offsets_Only;
G : in out Write_Grant;
Size : Count)
Request indexes of a contiguous writeable slice of exactly Size elements
type Offsets_Only (Size : Buffer_Size) is limited private;
procedure Read (This : in out Offsets_Only;
G : in out Read_Grant;
Max : Count := Count'Last)
Request indexes of a contiguous readable slice of up to Max elements
type Read_Grant is limited private;
function Read_Grant_In_Progress (This : Offsets_Only) return Boolean
procedure Release (This : in out Offsets_Only;
G : in out Read_Grant;
Size : Count := Count'Last)
Release a readable slice. Size can be smaller than the granted slice for partial releases.
type Result_Kind is (Valid, Grant_In_Progress, Insufficient_Size, Empty);
function Slice (G : Read_Grant) return Slice_Rec
function Slice (G : Write_Grant) return Slice_Rec
type Slice_Rec is record
Length : Count;
From : Buffer_Offset;
To : Buffer_Offset;
end record;
function State (G : Read_Grant) return Result_Kind
function State (G : Write_Grant) return Result_Kind
function Valid_Read_Slice (This : Offsets_Only; Slice : Slice_Rec) return Boolean
function Valid_Slice (This : Offsets_Only; Slice : Slice_Rec) return Boolean
A valid slice contains offsets within the bounds of the array range. This ensures that: Arr (Arr'First + Start_Offset .. Arr'First + End_Offset) will never be out of bounds.
function Valid_Write_Slice (This : Offsets_Only; Slice : Slice_Rec) return Boolean
type Write_Grant is limited private;
function Write_Grant_In_Progress (This : Offsets_Only) return Boolean