aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-coinho-shared.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2017-01-13 11:51:45 +0100
committerArnaud Charlet <charlet@gcc.gnu.org>2017-01-13 11:51:45 +0100
commit448a1eb3eb4357dcdd1e2271e267bedb0c4b7d6c (patch)
tree5046dc349b497c30eee1bc5826b72386ac220e56 /gcc/ada/a-coinho-shared.adb
parentb2c1aa8fe9463fcfe5f1750023bff9093f5b3b41 (diff)
downloadgcc-448a1eb3eb4357dcdd1e2271e267bedb0c4b7d6c.zip
gcc-448a1eb3eb4357dcdd1e2271e267bedb0c4b7d6c.tar.gz
gcc-448a1eb3eb4357dcdd1e2271e267bedb0c4b7d6c.tar.bz2
[multiple changes]
2017-01-13 Javier Miranda <miranda@adacore.com> * sem_ch6.adb (Freeze_Expr_Types): New subprogram. (Analyze_Subprogram_Body_Helper): At the occurrence of an expression function declaration that is a completion, its expression causes freezing (AI12-0103). 2017-01-13 Vadim Godunko <godunko@adacore.com> * a-coinho-shared.adb: Fix memory leaks in Constant_Reference and Reference functions of Ada.Containers.Indefinite_Holders. 2017-01-13 Bob Duff <duff@adacore.com> * s-os_lib.ads: Minor comment fixes. 2017-01-13 Hristian Kirtchev <kirtchev@adacore.com> * exp_ch3.adb (Default_Initialize_Object): Do not default initialize an object when it is of a task type and restriction No_Tasking is in effect because the initialization is obsolete. * exp_ch9.adb (Build_Master_Entity): Do not generate a master when restriction No_Tasking is in effect. (Build_Master_Renaming): Do not rename a master when restriction No_Tasking is in effect. From-SVN: r244418
Diffstat (limited to 'gcc/ada/a-coinho-shared.adb')
-rw-r--r--gcc/ada/a-coinho-shared.adb94
1 files changed, 41 insertions, 53 deletions
diff --git a/gcc/ada/a-coinho-shared.adb b/gcc/ada/a-coinho-shared.adb
index 81732b9..3373dbd 100644
--- a/gcc/ada/a-coinho-shared.adb
+++ b/gcc/ada/a-coinho-shared.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2013-2015, Free Software Foundation, Inc. --
+-- Copyright (C) 2013-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -39,6 +39,10 @@ package body Ada.Containers.Indefinite_Holders is
procedure Free is
new Ada.Unchecked_Deallocation (Element_Type, Element_Access);
+ procedure Detach (Container : Holder);
+ -- Detach data from shared copy if necessary. This is necessary to prepare
+ -- container to be modified.
+
---------
-- "=" --
---------
@@ -142,21 +146,10 @@ package body Ada.Containers.Indefinite_Holders is
begin
if Container.Reference = null then
raise Constraint_Error with "container is empty";
-
- elsif Container.Busy = 0
- and then not System.Atomic_Counters.Is_One
- (Container.Reference.Counter)
- then
- -- Container is not locked and internal shared object is used by
- -- other container, create copy of both internal shared object and
- -- element.
-
- Container'Unrestricted_Access.Reference :=
- new Shared_Holder'
- (Counter => <>,
- Element => new Element_Type'(Container.Reference.Element.all));
end if;
+ Detach (Container);
+
declare
Ref : constant Constant_Reference_Type :=
(Element => Container.Reference.Element.all'Access,
@@ -197,6 +190,34 @@ package body Ada.Containers.Indefinite_Holders is
end if;
end Copy;
+ ------------
+ -- Detach --
+ ------------
+
+ procedure Detach (Container : Holder) is
+ begin
+ if Container.Busy = 0
+ and then not System.Atomic_Counters.Is_One
+ (Container.Reference.Counter)
+ then
+ -- Container is not locked and internal shared object is used by
+ -- other container, create copy of both internal shared object and
+ -- element.
+
+ declare
+ Old : constant Shared_Holder_Access := Container.Reference;
+
+ begin
+ Container'Unrestricted_Access.Reference :=
+ new Shared_Holder'
+ (Counter => <>,
+ Element =>
+ new Element_Type'(Container.Reference.Element.all));
+ Unreference (Old);
+ end;
+ end if;
+ end Detach;
+
-------------
-- Element --
-------------
@@ -281,21 +302,10 @@ package body Ada.Containers.Indefinite_Holders is
begin
if Container.Reference = null then
raise Constraint_Error with "container is empty";
-
- elsif Container.Busy = 0
- and then
- not System.Atomic_Counters.Is_One (Container.Reference.Counter)
- then
- -- Container is not locked and internal shared object is used by
- -- other container, create copy of both internal shared object and
- -- element.
-
- Container'Unrestricted_Access.Reference :=
- new Shared_Holder'
- (Counter => <>,
- Element => new Element_Type'(Container.Reference.Element.all));
end if;
+ Detach (Container);
+
B := B + 1;
begin
@@ -359,21 +369,10 @@ package body Ada.Containers.Indefinite_Holders is
begin
if Container.Reference = null then
raise Constraint_Error with "container is empty";
-
- elsif Container.Busy = 0
- and then
- not System.Atomic_Counters.Is_One (Container.Reference.Counter)
- then
- -- Container is not locked and internal shared object is used by
- -- other container, create copy of both internal shared object and
- -- element.
-
- Container.Reference :=
- new Shared_Holder'
- (Counter => <>,
- Element => new Element_Type'(Container.Reference.Element.all));
end if;
+ Detach (Container);
+
declare
Ref : constant Reference_Type :=
(Element => Container.Reference.Element.all'Access,
@@ -477,21 +476,10 @@ package body Ada.Containers.Indefinite_Holders is
begin
if Container.Reference = null then
raise Constraint_Error with "container is empty";
-
- elsif Container.Busy = 0
- and then
- not System.Atomic_Counters.Is_One (Container.Reference.Counter)
- then
- -- Container is not locked and internal shared object is used by
- -- other container, create copy of both internal shared object and
- -- element.
-
- Container'Unrestricted_Access.Reference :=
- new Shared_Holder'
- (Counter => <>,
- Element => new Element_Type'(Container.Reference.Element.all));
end if;
+ Detach (Container);
+
B := B + 1;
begin