Commit 8942b30c by Arnaud Charlet

[multiple changes]

2014-07-16  Vadim Godunko  <godunko@adacore.com>

	* a-coinho-shared.adb (Adjust): Create
	copy of internal shared object and element when source container
	is locked.
	(Copy): Likewise.
	(Query_Element): Likewise.
	(Update_Element): Likewise.
	(Constant_Reference): Likewise. Raise Constraint_Error on attempt
	to get reference for empty holder.
	(Reference): Likewise.

2014-07-16  Thomas Quinot  <quinot@adacore.com>

	* exp_ch4.adb (Find_Hook_Context): New subprogram, extracted
	from Process_Transient_Oject.
	* exp_ch4.ads: Ditto.
	* exp_ch9.adb (Build_Class_Wide_Master): Insert the _master
	declaration as an action on the topmost enclosing expression,
	not on a possibly conditional subexpreession.

From-SVN: r212645
parent d6f824bf
2014-07-16 Vadim Godunko <godunko@adacore.com> 2014-07-16 Vadim Godunko <godunko@adacore.com>
* a-coinho-shared.adb (Adjust): Create
copy of internal shared object and element when source container
is locked.
(Copy): Likewise.
(Query_Element): Likewise.
(Update_Element): Likewise.
(Constant_Reference): Likewise. Raise Constraint_Error on attempt
to get reference for empty holder.
(Reference): Likewise.
2014-07-16 Thomas Quinot <quinot@adacore.com>
* exp_ch4.adb (Find_Hook_Context): New subprogram, extracted
from Process_Transient_Oject.
* exp_ch4.ads: Ditto.
* exp_ch9.adb (Build_Class_Wide_Master): Insert the _master
declaration as an action on the topmost enclosing expression,
not on a possibly conditional subexpreession.
2014-07-16 Vadim Godunko <godunko@adacore.com>
* a-coinho.adb, a-coinho-shared.adb, a-coinho.ads, a-coinho-shared.ads: * a-coinho.adb, a-coinho-shared.adb, a-coinho.ads, a-coinho-shared.ads:
Fix parameter mode of Update_Element. Fix parameter mode of Update_Element.
......
...@@ -57,7 +57,20 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -57,7 +57,20 @@ package body Ada.Containers.Indefinite_Holders is
overriding procedure Adjust (Container : in out Holder) is overriding procedure Adjust (Container : in out Holder) is
begin begin
if Container.Reference /= null then if Container.Reference /= null then
Reference (Container.Reference); if Container.Busy = 0 then
-- Container is not locked, reuse existing internal shared object.
Reference (Container.Reference);
else
-- Otherwise, 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;
end if; end if;
Container.Busy := 0; Container.Busy := 0;
...@@ -113,16 +126,34 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -113,16 +126,34 @@ package body Ada.Containers.Indefinite_Holders is
------------------------ ------------------------
function Constant_Reference function Constant_Reference
(Container : aliased Holder) return Constant_Reference_Type (Container : aliased Holder) return Constant_Reference_Type is
is
Ref : constant Constant_Reference_Type :=
(Element => Container.Reference.Element.all'Access,
Control => (Controlled with Container'Unrestricted_Access));
B : Natural renames Ref.Control.Container.Busy;
begin begin
Reference (Ref.Control.Container.Reference); if Container.Reference = null then
B := B + 1; raise Constraint_Error with "container is empty";
return Ref;
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;
declare
Ref : constant Constant_Reference_Type :=
(Element => Container.Reference.Element.all'Access,
Control => (Controlled with Container'Unrestricted_Access));
begin
Reference (Ref.Control.Container.Reference);
Ref.Control.Container.Busy := Ref.Control.Container.Busy + 1;
return Ref;
end;
end Constant_Reference; end Constant_Reference;
---------- ----------
...@@ -133,10 +164,21 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -133,10 +164,21 @@ package body Ada.Containers.Indefinite_Holders is
begin begin
if Source.Reference = null then if Source.Reference = null then
return (Controlled with null, 0); return (Controlled with null, 0);
else elsif Source.Busy = 0 then
-- Container is not locked, reuse internal shared object.
Reference (Source.Reference); Reference (Source.Reference);
return (Controlled with Source.Reference, 0); return (Controlled with Source.Reference, 0);
else
-- Otherwise, create copy of both internal shared object and elemet.
return
(Controlled with
new Shared_Holder'
(Counter => <>,
Element => new Element_Type'(Source.Reference.Element.all)),
0);
end if; end if;
end Copy; end Copy;
...@@ -224,6 +266,19 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -224,6 +266,19 @@ package body Ada.Containers.Indefinite_Holders is
begin begin
if Container.Reference = null then if Container.Reference = null then
raise Constraint_Error with "container is empty"; 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; end if;
B := B + 1; B := B + 1;
...@@ -284,15 +339,34 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -284,15 +339,34 @@ package body Ada.Containers.Indefinite_Holders is
end Reference; end Reference;
function Reference function Reference
(Container : aliased in out Holder) return Reference_Type (Container : aliased in out Holder) return Reference_Type is
is
Ref : constant Reference_Type :=
(Element => Container.Reference.Element.all'Access,
Control => (Controlled with Container'Unrestricted_Access));
begin begin
Reference (Ref.Control.Container.Reference); if Container.Reference = null then
Container.Busy := Container.Busy + 1; raise Constraint_Error with "container is empty";
return Ref;
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;
declare
Ref : constant Reference_Type :=
(Element => Container.Reference.Element.all'Access,
Control => (Controlled with Container'Unrestricted_Access));
begin
Reference (Ref.Control.Container.Reference);
Ref.Control.Container.Busy := Ref.Control.Container.Busy + 1;
return Ref;
end;
end Reference; end Reference;
--------------------- ---------------------
...@@ -387,6 +461,19 @@ package body Ada.Containers.Indefinite_Holders is ...@@ -387,6 +461,19 @@ package body Ada.Containers.Indefinite_Holders is
begin begin
if Container.Reference = null then if Container.Reference = null then
raise Constraint_Error with "container is empty"; 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; end if;
B := B + 1; B := B + 1;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1992-2013, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -103,4 +103,11 @@ package Exp_Ch4 is ...@@ -103,4 +103,11 @@ package Exp_Ch4 is
-- have special circuitry in Expand_N_Type_Conversion to promote both of -- have special circuitry in Expand_N_Type_Conversion to promote both of
-- the operands to type Integer. -- the operands to type Integer.
function Find_Hook_Context (N : Node_Id) return Node_Id;
-- Determine a suitable node on which to attach actions related to N
-- that need to be elaborated unconditionally (i.e. in general the topmost
-- expression of which N is a subexpression, which may or may not be
-- evaluated, for example if N is the right operand of a short circuit
-- operator).
end Exp_Ch4; end Exp_Ch4;
...@@ -29,6 +29,7 @@ with Einfo; use Einfo; ...@@ -29,6 +29,7 @@ with Einfo; use Einfo;
with Elists; use Elists; with Elists; use Elists;
with Errout; use Errout; with Errout; use Errout;
with Exp_Ch3; use Exp_Ch3; with Exp_Ch3; use Exp_Ch3;
with Exp_Ch4; use Exp_Ch4;
with Exp_Ch6; use Exp_Ch6; with Exp_Ch6; use Exp_Ch6;
with Exp_Ch11; use Exp_Ch11; with Exp_Ch11; use Exp_Ch11;
with Exp_Dbug; use Exp_Dbug; with Exp_Dbug; use Exp_Dbug;
...@@ -1151,7 +1152,6 @@ package body Exp_Ch9 is ...@@ -1151,7 +1152,6 @@ package body Exp_Ch9 is
then then
declare declare
Master_Decl : Node_Id; Master_Decl : Node_Id;
begin begin
Set_Has_Master_Entity (Master_Scope); Set_Has_Master_Entity (Master_Scope);
...@@ -1169,7 +1169,7 @@ package body Exp_Ch9 is ...@@ -1169,7 +1169,7 @@ package body Exp_Ch9 is
Make_Explicit_Dereference (Loc, Make_Explicit_Dereference (Loc,
New_Occurrence_Of (RTE (RE_Current_Master), Loc))); New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
Insert_Action (Related_Node, Master_Decl); Insert_Action (Find_Hook_Context (Related_Node), Master_Decl);
Analyze (Master_Decl); Analyze (Master_Decl);
-- Mark the containing scope as a task master. Masters associated -- Mark the containing scope as a task master. Masters associated
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment