Skip to content

Commit

Permalink
Make queue peek circular
Browse files Browse the repository at this point in the history
  • Loading branch information
masonticehurst committed Feb 17, 2024
1 parent de12756 commit 5d477b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions eRINA_STM32F7/src/rina/queues.adb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package body Queues is
-- Queues shouldn't be iterable? Yeah I don't really care
function Peek (L : Queue_Index) return T is
begin
return A (L);
return A (L + (X mod Queue_Index'Last));
end Peek;

function Size return Natural is
Expand All @@ -28,13 +28,14 @@ package body Queues is
entry Pop (V : out T) when N > 0 is
begin
N := N - 1;

V := A (Idx - Queue_Index (N) - 1);
X := ((X + 1) mod Queue_Index'Last);
end Pop;

entry Pop when N > 0 is
begin
N := N - 1;
X := ((X + 1) mod Queue_Index'Last);
end Pop;

end Queue;
Expand Down
3 changes: 2 additions & 1 deletion eRINA_STM32F7/src/rina/queues.ads
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package Queues is
entry Pop (V : out T);
private
N : Natural := 0;
Idx : Queue_Index := Queue_Array'First;
A : Queue_Array;
Idx : Queue_Index := Queue_Array'First;
L : Positive := Positive (Queue_Index'Last);
X : Queue_Index := Queue_Array'First;
end Queue;

end Queues;

0 comments on commit 5d477b4

Please sign in to comment.