This unit is based on BBqueue.Offsets_Only and embeds an internal buffer. It provides directly usable slices of memory from its internal buffer:
Q : aliased Buffer (64);
WG : Write_Grant := Empty;
S : Slice_Rec;
begin Grant (Q, WG, 8); if State (WG) = Valid then declare B : Storage_Array (1 .. Slice (WG).Length) with Address => Slice (WG).Addr; begin B := (others => 42); end; Commit (Q, WG); end if;
type Buffer (Size : Buffer_Size)
is limited private;
procedure Commit (This : in out Buffer;
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.
function Empty return Read_Grant
function Empty return Write_Grant
procedure Grant (This : in out Buffer;
G : in out Write_Grant;
Size : Count)
Request a contiguous writeable slice of the internal buffer
procedure Read (This : in out Buffer;
G : in out Read_Grant;
Max : Count := Count'Last)
Request contiguous readable slice of up to Max elements from the internal buffer.
generic
with procedure Process_Read (Data : Storage_Array;
To_Release : out Count);
procedure Read_CB (This : in out Buffer;
Result : out Result_Kind)
Read from the buffer using a "callback". This procedure will call Process_Read () on the slice returned by Read (), if the result is Valid. It will then call Release with the value To_Release returned by Process_Read ().
type Read_Grant is limited private;
function Read_Grant_In_Progress (This : Buffer) return Boolean
procedure Release (This : in out Buffer;
G : in out Read_Grant;
Size : Count := Count'Last)
Release a readable slice. Size can be smaller than the granted slice for partial releases.
function Slice (G : Read_Grant) return Slice_Rec
function Slice (G : Write_Grant) return Slice_Rec
type Slice_Rec is record
Length : Count;
Addr : System.Address;
end record;
function State (G : Read_Grant) return Result_Kind
function State (G : Write_Grant) return Result_Kind
generic
with procedure Process_Write (Data : out Storage_Array;
To_Commit : out Count);
procedure Write_CB (This : in out Buffer;
Size : Count;
Result : out Result_Kind)
Write in the buffer using a "callback". This procedure will call Process_Write () on the slice returned by Grant (), if the result is Valid. It will then call Commit with the value To_Commit returned by Process_Write ().
type Write_Grant is limited private;
function Write_Grant_In_Progress (This : Buffer) return Boolean