-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffers.adb
35 lines (32 loc) · 1.11 KB
/
buffers.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
package body Buffers is
task body Buffer is
Start : Integer := 0;
Actual_Size : Integer := 1;
Data : Array(0..Size-1) of Integer;
Test : Boolean := False ;
begin
loop
select
--when ((Size > 1 and Start /= Actual_Size) or (Size = 1 and not Test)) =>
when (Actual_Size /= Start) =>
accept Put ( Obj : in Integer ) do
Data( (Actual_Size - 1) mod Size ) := Obj;
Actual_Size := (Actual_Size + 1 ) mod Size;
Test := True;
end Put;
or
--when ((Size > 1 and (Start /= ((Actual_Size - 1) mod Size))) or (Size = 1 and Test)) =>
when (Start /= ((Actual_Size - 1) mod Size)) =>
accept Get (Obj : out Integer) do
Obj := Data ( Start );
Start := (Start + 1) mod Size;
Test := False;
end Get;
or
terminate;
end select;
end loop;
end Buffer;
end Buffers;