Commit e9c9d122 by Hristian Kirtchev Committed by Arnaud Charlet

s-stposu.adb (Allocate_Any_Controlled): Reimplement the mechanism which accounts…

s-stposu.adb (Allocate_Any_Controlled): Reimplement the mechanism which accounts for size vs alignment issues and...

2011-08-29  Hristian Kirtchev  <kirtchev@adacore.com>

	* s-stposu.adb (Allocate_Any_Controlled): Reimplement the mechanism
	which accounts for size vs alignment issues and calculates the size of
	the list header.
	(Deallocate_Any_Controlled): Ditto.
	(Nearest_Multiple_Rounded_Up): New routine.

From-SVN: r178218
parent 09fae88d
2011-08-29 Hristian Kirtchev <kirtchev@adacore.com>
* s-stposu.adb (Allocate_Any_Controlled): Reimplement the mechanism
which accounts for size vs alignment issues and calculates the size of
the list header.
(Deallocate_Any_Controlled): Ditto.
(Nearest_Multiple_Rounded_Up): New routine.
2011-08-29 Tristan Gingold <gingold@adacore.com> 2011-08-29 Tristan Gingold <gingold@adacore.com>
* a-exstat.adb (String_To_EO): Do no set Cleanup_Flag. * a-exstat.adb (String_To_EO): Do no set Cleanup_Flag.
......
...@@ -46,6 +46,12 @@ package body System.Storage_Pools.Subpools is ...@@ -46,6 +46,12 @@ package body System.Storage_Pools.Subpools is
procedure Detach (N : not null SP_Node_Ptr); procedure Detach (N : not null SP_Node_Ptr);
-- Unhook a subpool node from an arbitrary subpool list -- Unhook a subpool node from an arbitrary subpool list
function Nearest_Multiple_Rounded_Up
(Size : Storage_Count;
Alignment : Storage_Count) return Storage_Count;
-- Given arbitrary values of storage size and alignment, calculate the
-- nearest multiple of the alignment rounded up where size can fit.
-------------- --------------
-- Allocate -- -- Allocate --
-------------- --------------
...@@ -191,11 +197,10 @@ package body System.Storage_Pools.Subpools is ...@@ -191,11 +197,10 @@ package body System.Storage_Pools.Subpools is
-- Account for possible padding space before the header due to a -- Account for possible padding space before the header due to a
-- larger alignment. -- larger alignment.
if Alignment > Header_Size then Header_And_Padding :=
Header_And_Padding := Alignment; Nearest_Multiple_Rounded_Up
else (Size => Header_Size,
Header_And_Padding := Header_Size; Alignment => Alignment);
end if;
N_Size := Storage_Size + Header_And_Padding; N_Size := Storage_Size + Header_And_Padding;
...@@ -307,11 +312,14 @@ package body System.Storage_Pools.Subpools is ...@@ -307,11 +312,14 @@ package body System.Storage_Pools.Subpools is
-- Step 1: Detachment -- Step 1: Detachment
if Is_Controlled then if Is_Controlled then
if Alignment > Header_Size then
Header_And_Padding := Alignment; -- Account for possible padding space before the header due to a
else -- larger alignment.
Header_And_Padding := Header_Size;
end if; Header_And_Padding :=
Nearest_Multiple_Rounded_Up
(Size => Header_Size,
Alignment => Alignment);
-- N_Addr N_Ptr Addr (from input) -- N_Addr N_Ptr Addr (from input)
-- | | | -- | | |
...@@ -497,6 +505,26 @@ package body System.Storage_Pools.Subpools is ...@@ -497,6 +505,26 @@ package body System.Storage_Pools.Subpools is
Pool.Subpools.Prev := Pool.Subpools'Unchecked_Access; Pool.Subpools.Prev := Pool.Subpools'Unchecked_Access;
end Initialize_Pool; end Initialize_Pool;
---------------------------------
-- Nearest_Multiple_Rounded_Up --
---------------------------------
function Nearest_Multiple_Rounded_Up
(Size : Storage_Count;
Alignment : Storage_Count) return Storage_Count
is
begin
if Size mod Alignment = 0 then
return Size;
-- Add enough padding to reach the nearest multiple of the alignment
-- rounding up.
else
return ((Size + Alignment - 1) / Alignment) * Alignment;
end if;
end Nearest_Multiple_Rounded_Up;
--------------------- ---------------------
-- Pool_Of_Subpool -- -- Pool_Of_Subpool --
--------------------- ---------------------
......
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