BBqueue

Entities

Simple Types

Record Types

Subtypes

Subprograms

Description

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;

Buffer_Offset

subtype Buffer_Offset is Storage_Offset range 0 .. Count'Last - 1;

Buffer_Size

subtype Buffer_Size is Count range 1 .. Count'Last;

Commit

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.

Parameters
This
G
Size

Count

subtype Count is Storage_Count;

Empty

function Empty return Read_Grant
Return Value

Empty

function Empty return Write_Grant
Return Value

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

Parameters
This
G
Size

Offsets_Only

type Offsets_Only (Size : Buffer_Size) is limited private;

Read

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

Parameters
This
G
Max

Read_Grant

type Read_Grant is limited private;

Read_Grant_In_Progress

function Read_Grant_In_Progress (This : Offsets_Only) return Boolean
Parameters
This
Return Value

Release

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.

Parameters
This
G
Size

Result_Kind

type Result_Kind is (Valid, Grant_In_Progress, Insufficient_Size, Empty);
Enumeration Literal
Valid
Grant_In_Progress
Insufficient_Size
Empty

Slice

function Slice (G : Read_Grant) return Slice_Rec
Parameters
G
Return Value

Slice

function Slice (G : Write_Grant) return Slice_Rec
Parameters
G
Return Value

Slice_Rec

type Slice_Rec is record
   Length : Count;
   From   : Buffer_Offset;
   To     : Buffer_Offset;
end record;
Record fields
Length
From
To

State

function State (G : Read_Grant) return Result_Kind
Parameters
G
Return Value

State

function State (G : Write_Grant) return Result_Kind
Parameters
G
Return Value

Valid_Read_Slice

function Valid_Read_Slice (This : Offsets_Only; Slice : Slice_Rec) return Boolean
Parameters
This
Slice
Return Value

Valid_Slice

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.

Parameters
This
Slice
Return Value

Valid_Write_Slice

function Valid_Write_Slice (This : Offsets_Only; Slice : Slice_Rec) return Boolean
Parameters
This
Slice
Return Value

Write_Grant

type Write_Grant is limited private;

Write_Grant_In_Progress

function Write_Grant_In_Progress (This : Offsets_Only) return Boolean
Parameters
This
Return Value