2020-06-12 Arnaud Charlet <charlet@adacore.com>
gcc/ada/
* libgnat/a-coinho.ads, libgnat/a-coinho.adb,
libgnat/a-coinho__shared.ads, libgnat/a-coinho__shared.adb
(Swap): New procedure.
end;
end Replace_Element;
+ ----------
+ -- Swap --
+ ----------
+
+ procedure Swap (Left, Right : in out Holder) is
+ begin
+ if Left.Busy /= 0 then
+ raise Program_Error with "attempt to tamper with elements";
+ end if;
+
+ if Right.Busy /= 0 then
+ raise Program_Error with "attempt to tamper with elements";
+ end if;
+
+ if Left.Element /= Right.Element then
+ declare
+ Tmp : constant Element_Access := Left.Element;
+ begin
+ Left.Element := Right.Element;
+ Right.Element := Tmp;
+ end;
+ end if;
+ end Swap;
+
---------------
-- To_Holder --
---------------
procedure Move (Target : in out Holder; Source : in out Holder);
+ procedure Swap (Left, Right : in out Holder);
+
private
use Ada.Finalization;
end if;
end Replace_Element;
+ ----------
+ -- Swap --
+ ----------
+
+ procedure Swap (Left, Right : in out Holder) is
+ begin
+ if Left.Busy /= 0 then
+ raise Program_Error with "attempt to tamper with elements";
+ end if;
+
+ if Right.Busy /= 0 then
+ raise Program_Error with "attempt to tamper with elements";
+ end if;
+
+ if Left.Reference /= Right.Reference then
+ declare
+ Tmp : constant Shared_Holder_Access := Left.Reference;
+ begin
+ Left.Reference := Right.Reference;
+ Right.Reference := Tmp;
+ end;
+ end if;
+ end Swap;
+
---------------
-- To_Holder --
---------------
procedure Move (Target : in out Holder; Source : in out Holder);
+ procedure Swap (Left, Right : in out Holder);
+
private
use Ada.Finalization;