summaryrefslogtreecommitdiff
path: root/gcc/ada/a-tasatt.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-14 08:45:25 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-14 08:45:25 +0000
commit9925603e39a1d02a6f0883d26e4eafb7f148eed0 (patch)
tree7f1f9f1c3411501de6576d01a74c4d83f635c7a1 /gcc/ada/a-tasatt.adb
parentfcdc023a8715ff3e826cf73114712889e4319607 (diff)
downloadgcc-9925603e39a1d02a6f0883d26e4eafb7f148eed0.tar.gz
2007-08-14 Robert Dewar <dewar@adacore.com>
* s-intman-irix.adb, s-osinte-irix.adb, s-osinte-irix.ads, s-proinf-irix-athread.ads, s-osinte-hpux-dce.adb, s-osinte-hpux-dce.ads, s-parame-hpux.ads, s-intman-dummy.adb, s-tasinf-solaris.adb, s-tasinf-solaris.ads, s-asthan-vms-alpha.adb, s-inmaop-vms.adb, s-intman-vms.adb, s-intman-vms.ads, s-osprim-mingw.adb, s-parame-vms-restrict.ads, s-parame-ae653.ads, s-intman-vxworks.ads, s-intman-vxworks.ads, s-intman-vxworks.adb, s-parame-vxworks.ads, s-tfsetr-vxworks.adb, s-interr.adb, s-interr.ads, a-tasatt.adb, exp_ch13.adb, s-htable.ads, s-imgboo.ads, s-imglli.ads, s-imgllu.ads, s-imguns.ads, g-eacodu.adb, par-ch12.adb, s-stache.ads, s-stausa.adb, s-poosiz.adb, s-parame.ads, s-mastop.ads, s-osinte-darwin.ads, a-chtgke.adb, s-asthan-vms-alpha.adb, s-parame-vms-alpha.ads, s-parame-vms-ia64.ads, s-parame-vxworks.adb, s-except.ads, g-altcon.adb: Minor reformatting ada-tree.h: Delete empty line. ali.ads: Minor reformatting Clarification of comments. Minor spelling correction * exp_dbug.adb: Add Warnings Off to suppress new warning * a-witeio.adb (Write): Add Warnings (Off) for unneeded IN OUT mode formal * a-strunb.adb (Set_Unbounded_String): Avoid memory leak by freeing old value * a-textio.adb (Write): Remove an unnecessary IN OUT mode from * a-textio.ads: Reorder the standard input/output/error declarations for consistency. * g-dirope.adb, g-dirope.ads: Change Dir to mode IN for Open call * par-ch2.adb: Recognize RM specially in errout Change 'R'M to RM in all error messages * scng.adb: Recognize RM specially in errout * sem.ads, sem.adb, exp_strm.adb, exp_ch5.ads, expander.adb: Rename N_Return node to be N_Simple_Return, to reflect Ada 2005 terminology. * s-direio.adb: Add missing routine header box. * sem_attr.ads: Add ??? comments * sem_eval.adb: Recognize RM specially in errout Change 'R'M to RM in all error messages * sem_maps.adb, sem_maps.ads: Remove some unnecessary IN OUT modes * s-tasinf.ads: Fix minor comment typo. * a-cihama.adb: Minor comment addition * a-ztexio.adb (Write): Add Warnings (Off) for unneeded IN OUT mode formal * s-tasinf-tru64.ads: Fix minor comment typo. * itypes.ads: Comment update. * ali-util.adb: Remove Generic_Separately_Compiled guard, not needed anymore. * argv.c: Added protection against null gnat_argv and gnat_envp. * bcheck.adb (Check_Consistency): Use correct markup character ({) in warning message when Tolerate_Consistency_Errors is True. * cstand.adb (Create_Standard): Do not call Init_Size_Alignment for Any_Id, as this subprogram is only applicable to *type* entities (it sets RM_Size). Instead initialize just Esize and Alignment. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127440 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-tasatt.adb')
-rw-r--r--gcc/ada/a-tasatt.adb134
1 files changed, 64 insertions, 70 deletions
diff --git a/gcc/ada/a-tasatt.adb b/gcc/ada/a-tasatt.adb
index 3bace41794a..82b2df2f823 100644
--- a/gcc/ada/a-tasatt.adb
+++ b/gcc/ada/a-tasatt.adb
@@ -126,23 +126,22 @@
-- might result in dangling references.
-- Another problem with instantiations deeper than the library level is that
--- there is risk of storage leakage, or dangling references to reused
--- storage. That is, if an instantiation of Ada.Task_Attributes is made
--- within a procedure, what happens to the storage allocated for attributes,
--- when the procedure call returns? Apparently (RM 7.6.1 (4)) any such
--- objects must be finalized, since they will no longer be accessible, and in
--- general one would expect that the storage they occupy would be recovered
--- for later reuse. (If not, we would have a case of storage leakage.)
--- Assuming the storage is recovered and later reused, we have potentially
--- dangerous dangling references. When the procedure containing the
--- instantiation of Ada.Task_Attributes returns, there may still be
--- unterminated tasks with associated attribute values for that instantiation.
--- When such tasks eventually terminate, the RTS will attempt to call the
--- Deallocate procedure on them. If the corresponding storage has already
--- been deallocated, when the master of the access type was left, we have a
--- potential disaster. This disaster is compounded since the pointer to
--- Deallocate is probably through a "trampoline" which will also have been
--- destroyed.
+-- there is risk of storage leakage, or dangling references to reused storage.
+-- That is, if an instantiation of Ada.Task_Attributes is made within a
+-- procedure, what happens to the storage allocated for attributes, when the
+-- procedure call returns? Apparently (RM 7.6.1 (4)) any such objects must be
+-- finalized, since they will no longer be accessible, and in general one
+-- would expect that the storage they occupy would be recovered for later
+-- reuse. (If not, we would have a case of storage leakage.) Assuming the
+-- storage is recovered and later reused, we have potentially dangerous
+-- dangling references. When the procedure containing the instantiation of
+-- Ada.Task_Attributes returns, there may still be unterminated tasks with
+-- associated attribute values for that instantiation. When such tasks
+-- eventually terminate, the RTS will attempt to call the Deallocate procedure
+-- on them. If the corresponding storage has already been deallocated, when
+-- the master of the access type was left, we have a potential disaster. This
+-- disaster is compounded since the pointer to Deallocate is probably through
+-- a "trampoline" which will also have been destroyed.
-- For this reason, we arrange to remove all dangling references before
-- leaving the scope of an instantiation. This is ugly, since it requires
@@ -156,38 +155,36 @@
-- the default initial one. This allows a potential savings in allocation,
-- for attributes that are not used by all tasks.
--- For efficiency, we reserve space in the TCB for a fixed number of
--- direct-access attributes. These are required to be of a size that fits in
--- the space of an object of type System.Address. Because we must use
--- unchecked bitwise copy operations on these values, they cannot be of a
--- controlled type, but that is covered automatically since controlled
--- objects are too large to fit in the spaces.
-
--- We originally deferred the initialization of these direct-access
--- attributes, just as we do for the indirect-access attributes, and used a
--- per-task bit vector to keep track of which attributes were currently
--- defined for that task. We found that the overhead of maintaining this
--- bit-vector seriously slowed down access to the attributes, and made the
--- fetch operation non-atomic, so that even to read an attribute value
--- required locking the TCB. Therefore, we now initialize such attributes for
--- all existing tasks at the time of the attribute instantiation, and
--- initialize existing attributes for each new task at the time it is
--- created.
+-- For efficiency, we reserve space in the TCB for a fixed number of direct-
+-- access attributes. These are required to be of a size that fits in the
+-- space of an object of type System.Address. Because we must use unchecked
+-- bitwise copy operations on these values, they cannot be of a controlled
+-- type, but that is covered automatically since controlled objects are too
+-- large to fit in the spaces.
+
+-- We originally deferred initialization of these direct-access attributes,
+-- just as we do for the indirect-access attributes, and used a per-task bit
+-- vector to keep track of which attributes were currently defined for that
+-- task. We found that the overhead of maintaining this bit-vector seriously
+-- slowed down access to the attributes, and made the fetch operation non-
+-- atomic, so that even to read an attribute value required locking the TCB.
+-- Therefore, we now initialize such attributes for all existing tasks at the
+-- time of the attribute instantiation, and initialize existing attributes for
+-- each new task at the time it is created.
-- The latter initialization requires a list of all the instantiation
-- descriptors. Updates to this list, as well as the bit-vector that is used
-- to reserve slots for attributes in the TCB, require mutual exclusion. That
-- is provided by the Lock/Unlock_RTS.
--- One special problem that added complexity to the design is that the
--- per-task list of indirect attributes contains objects of different types.
--- We use unchecked pointer conversion to link these nodes together and
--- access them, but the records may not have identical internal structure.
--- Initially, we thought it would be enough to allocate all the common
--- components of the records at the front of each record, so that their
--- positions would correspond. Unfortunately, GNAT adds "dope" information at
--- the front of a record, if the record contains any controlled-type
--- components.
+-- One special problem that added complexity to the design is that the per-
+-- task list of indirect attributes contains objects of different types. We
+-- use unchecked pointer conversion to link these nodes together and access
+-- them, but the records may not have identical internal structure. Initially,
+-- we thought it would be enough to allocate all the common components of
+-- the records at the front of each record, so that their positions would
+-- correspond. Unfortunately, GNAT adds "dope" information at the front
+-- of a record, if the record contains any controlled-type components.
--
-- This means that the offset of the fields we use to link the nodes is at
-- different positions on nodes of different types. To get around this, each
@@ -211,15 +208,14 @@
-- Value : aliased Attribute; -- the generic formal type
-- end record;
--- Another interesting problem is with the initialization of the
--- instantiation descriptors. Originally, we did this all via the Initialize
--- procedure of the descriptor type and code in the package body. It turned
--- out that the Initialize procedure needed quite a bit of information,
--- including the size of the attribute type, the initial value of the
--- attribute (if it fits in the TCB), and a pointer to the deallocator
--- procedure. These needed to be "passed" in via access discriminants. GNAT
--- was having trouble with access discriminants, so all this work was moved
--- to the package body.
+-- Another interesting problem is with the initialization of the instantiation
+-- descriptors. Originally, we did this all via the Initialize procedure of
+-- the descriptor type and code in the package body. It turned out that the
+-- Initialize procedure needed quite a bit of information, including the size
+-- of the attribute type, the initial value of the attribute (if it fits in
+-- the TCB), and a pointer to the deallocator procedure. These needed to be
+-- "passed" in via access discriminants. GNAT was having trouble with access
+-- discriminants, so all this work was moved to the package body.
with System.Error_Reporting;
-- Used for Shutdown;
@@ -284,11 +280,11 @@ package body Ada.Task_Attributes is
type Access_Wrapper is access all Wrapper;
pragma Warnings (Off);
- -- We turn warnings off for the following declarations of the
- -- To_Attribute_Handle conversions, since these are used only for small
- -- attributes where we know that there are no problems with alignment, but
- -- the compiler will generate warnings for the occurrences in the large
- -- attribute case, even though they will not actually be used.
+ -- We turn warnings off for the following To_Attribute_Handle conversions,
+ -- since these are used only for small attributes where we know that there
+ -- are no problems with alignment, but the compiler will generate warnings
+ -- for the occurrences in the large attribute case, even though they will
+ -- not actually be used.
function To_Attribute_Handle is new Ada.Unchecked_Conversion
(System.Address, Attribute_Handle);
@@ -342,8 +338,8 @@ package body Ada.Task_Attributes is
------------------------
procedure Deallocate (P : in out Access_Node);
- -- Passed to the RTS via unchecked conversion of a pointer to
- -- permit finalization and deallocation of attribute storage nodes
+ -- Passed to the RTS via unchecked conversion of a pointer to permit
+ -- finalization and deallocation of attribute storage nodes.
--------------------------
-- Instantiation Record --
@@ -359,9 +355,9 @@ package body Ada.Task_Attributes is
-- The generic formal type, may be controlled
end record;
- -- A number of unchecked conversions involving Wrapper_Access sources
- -- are performed in this unit. We have to ensure that the designated
- -- object is always strictly enough aligned.
+ -- A number of unchecked conversions involving Wrapper_Access sources are
+ -- performed in this unit. We have to ensure that the designated object is
+ -- always strictly enough aligned.
for Wrapper'Alignment use Standard'Maximum_Alignment;
@@ -598,8 +594,7 @@ package body Ada.Task_Attributes is
end loop;
-- Unlock RTS here to follow the lock ordering rule that prevent us
- -- from using new (i.e the Global_Lock) while holding any other
- -- lock.
+ -- from using new (i.e the Global_Lock) while holding any other lock.
POP.Unlock_RTS;
W := new Wrapper'((null, Local'Unchecked_Access, null), Val);
@@ -652,7 +647,7 @@ package body Ada.Task_Attributes is
if Local.Index /= 0 then
- -- Get value of attribute. Warnings off, because for large
+ -- Get value of attribute. We turn Warnings off, because for large
-- attributes, this code can generate alignment warnings. But of
-- course large attributes are never directly addressed so in fact
-- we will never execute the code in this case.
@@ -708,9 +703,9 @@ package body Ada.Task_Attributes is
-- Start of elaboration code for package Ada.Task_Attributes
begin
- -- This unchecked conversion can give warnings when alignments
- -- are incorrect, but they will not be used in such cases anyway,
- -- so the warnings can be safely ignored.
+ -- This unchecked conversion can give warnings when alignments are
+ -- incorrect, but they will not be used in such cases anyway, so the
+ -- warnings can be safely ignored.
pragma Warnings (Off);
Local.Deallocate := To_Lib_Level_Deallocator (Deallocate'Access);
@@ -789,8 +784,7 @@ begin
-- Attribute goes into a node onto a linked list
else
- -- Replace stub for finalization routine that is called at task
- -- termination.
+ -- Replace stub for finalization routine called at task termination
Initialization.Finalize_Attributes_Link :=
System.Tasking.Task_Attributes.Finalize_Attributes'Access;