← All compilation units

Flyology.Bounded_Channels

Description

Supplies fixed-capacity closeable channels with ordinary Ada entry semantics. The channel allocates no storage after elaboration and owns no task. Multiple producers and consumers may call it concurrently. A blocked sender or receiver resumes when the channel closes; terminal outcomes are reported through Boolean parameters rather than exceptions.

Element assignment and finalization run inside protected operations. Element_Type and Empty_Value operations must not block, reenter the same Channel, or propagate exceptions.

Channel

type Channel (Capacity : Positive) is tagged limited private;

Fixed-capacity multi-producer, multi-consumer FIFO. Values accepted before Close remain receivable in order until the channel drains.

Record fields
Capacity

Maximum queued values

Close

procedure Close (Item : in out Channel)

Idempotently close the channel and wake blocked callers.

Parameters
Item

Channel

Element_Type

type Element_Type is private;

Empty_Value

Empty_Value : Element_Type;

Is_Closed

function Is_Closed (Item : Channel) return Boolean

Report whether Close was called.

Parameters
Item

Channel

Return value

True after closure

Length

function Length (Item : Channel) return Natural

Return a thread-safe snapshot of the queued value count.

Parameters
Item

Channel

Return value

Current queue depth

Receive

procedure Receive (Item : in out Channel; Value : out Element_Type; Available : out Boolean)

Wait for a value. Values queued before Close remain receivable; Available is false once the closed channel is empty. Value is defined only when Available is true.

Parameters
Item

Channel

Value

Received value when Available

Available

Whether a value was returned

Receive_For

procedure Receive_For
  (Item      : in out Channel;
   Value     : out Element_Type;
   Available : out Boolean;
   Timeout   : Duration;
   Timed_Out : out Boolean)

Wait for a value for at most Timeout seconds. A negative timeout waits without a deadline; zero is an immediate attempt. Timed_Out distinguishes an open empty channel from a closed and drained channel. On timeout, Value is Empty_Value and Available is false. On closure, Value is defined only when Available is true.

Parameters
Item

Channel

Value

Received value when Available

Available

Whether a value was returned

Timeout

Maximum monotonic wait in seconds

Timed_Out

True only when the wait interval expired

Send

procedure Send (Item : in out Channel; Value : Element_Type; Accepted : out Boolean)

Wait for space and enqueue Value, or return Accepted false after Close. The protected entry suspends lightweight callers cooperatively and provides bounded backpressure without blocking an event-loop thread.

Parameters
Item

Channel

Value

Value to enqueue

Accepted

False only when closed

Send_For

procedure Send_For
  (Item      : in out Channel;
   Value     : Element_Type;
   Accepted  : out Boolean;
   Timeout   : Duration;
   Timed_Out : out Boolean)

Wait for space for at most Timeout seconds. A negative timeout waits without a deadline; zero is an immediate attempt. Closing the channel returns Accepted false without setting Timed_Out. Timeout leaves the channel unchanged and returns Accepted false with Timed_Out true.

Parameters
Item

Channel

Value

Value to enqueue

Accepted

Whether the value was queued

Timeout

Maximum monotonic wait in seconds

Timed_Out

True only when the wait interval expired

Try_Receive

procedure Try_Receive (Item : in out Channel; Value : out Element_Type; Available : out Boolean)

Attempt to receive without waiting. Value is defined only when Available is true.

Parameters
Item

Channel

Value

Received value when Available

Available

True only when a queued value was available

Try_Send

procedure Try_Send (Item : in out Channel; Value : Element_Type; Accepted : out Boolean)

Attempt to enqueue without waiting.

Parameters
Item

Channel

Value

Value to enqueue

Accepted

True only when open space was available