stopped using System.Atomic_Counters.Atomic_Counter
This commit is contained in:
parent
757ef193ca
commit
081937df1b
@ -5,8 +5,8 @@ package body H3.MM is
|
||||
begin
|
||||
Finalize (R);
|
||||
R.Data := new Ref_Counted_Record;
|
||||
--R.Data.Ref_Count := 1;
|
||||
System.Atomic_Counters.Initialize (R.Data.Ref_Count); -- initialize to 1
|
||||
R.Data.Ref_Count := 1;
|
||||
--System.Atomic_Counters.Initialize (R.Data.Ref_Count); -- initialize to 1
|
||||
end Create;
|
||||
|
||||
procedure Create (R: in out Ref_Counted; V: in Item_Type) is
|
||||
@ -26,7 +26,8 @@ package body H3.MM is
|
||||
|
||||
function Is_Shared (R: in Ref_Counted) return Standard.Boolean is
|
||||
begin
|
||||
return R.Data /= null and then not System.Atomic_Counters.Is_One(R.Data.Ref_Count);
|
||||
--return R.Data /= null and then not System.Atomic_Counters.Is_One(R.Data.Ref_Count);
|
||||
return R.Data /= null and then R.Data.Ref_Count > 1;
|
||||
end Is_Shared;
|
||||
|
||||
procedure Initialize (R: in out Ref_Counted) is
|
||||
@ -37,8 +38,8 @@ package body H3.MM is
|
||||
procedure Adjust (R: in out Ref_Counted) is
|
||||
begin
|
||||
if R.Data /= null then
|
||||
--R.Data.Ref_Count := R.Data.Ref_Count + 1;
|
||||
System.Atomic_Counters.Increment (R.Data.Ref_Count);
|
||||
R.Data.Ref_Count := R.Data.Ref_Count + 1;
|
||||
--System.Atomic_Counters.Increment (R.Data.Ref_Count);
|
||||
end if;
|
||||
end Adjust;
|
||||
|
||||
@ -46,10 +47,15 @@ package body H3.MM is
|
||||
procedure Dealloc is new Ada.Unchecked_Deallocation(Ref_Counted_Record, Ref_Counted_Pointer);
|
||||
begin
|
||||
if R.Data /= null then
|
||||
if System.Atomic_Counters.Decrement(R.Data.Ref_Count) then
|
||||
-- The reference count reached 0
|
||||
--if System.Atomic_Counters.Decrement(R.Data.Ref_Count) then
|
||||
-- -- The reference count reached 0
|
||||
-- Dealloc (R.Data);
|
||||
-- -- R.DAta must be null here
|
||||
--end if;
|
||||
if R.Data.Ref_Count = 1 then
|
||||
Dealloc (R.Data);
|
||||
-- R.DAta must be null here
|
||||
else
|
||||
R.Data.Ref_Count := R.Data.Ref_Count - 1;
|
||||
end if;
|
||||
end if;
|
||||
end Finalize;
|
||||
|
@ -7,7 +7,8 @@ package H3.MM is
|
||||
type Item_Pointer is access all Item_Type;
|
||||
|
||||
type Ref_Counted_Record is record
|
||||
Ref_Count: System.Atomic_Counters.Atomic_Counter;
|
||||
--Ref_Count: System.Atomic_Counters.Atomic_Counter;
|
||||
Ref_Count: System_Size;
|
||||
Item: aliased Item_Type;
|
||||
end record;
|
||||
|
||||
|
@ -19,7 +19,7 @@ package body H3.Strings is
|
||||
begin
|
||||
return Str.Buffer.Slot'Length;
|
||||
end Get_Hard_Capacity;
|
||||
pragma inline (Get_Hard_Capacity);
|
||||
pragma Inline (Get_Hard_Capacity);
|
||||
|
||||
function Get_Length (Str: in Elastic_String) return System_Size is
|
||||
begin
|
||||
|
@ -16,28 +16,28 @@ package H3.Strings is
|
||||
function To_Character_Array (Str: in Elastic_String) return Character_Array;
|
||||
|
||||
function Get_Capacity (Str: in Elastic_String) return System_Size;
|
||||
pragma inline (Get_Capacity);
|
||||
pragma Inline (Get_Capacity);
|
||||
|
||||
function Get_Length (Str: in Elastic_String) return System_Size;
|
||||
pragma inline (Get_Length);
|
||||
pragma Inline (Get_Length);
|
||||
|
||||
-- the return type is System_Size for consistency with Get_FIrst_Index.
|
||||
function Get_First_Index (Str: in Elastic_String) return System_Size;
|
||||
pragma inline (Get_First_Index);
|
||||
pragma Inline (Get_First_Index);
|
||||
|
||||
-- the return type is System_Size because the Last index can be -1 off the System_Index'First.
|
||||
function Get_Last_Index (Str: in Elastic_String) return System_Size;
|
||||
pragma inline (Get_Last_index);
|
||||
pragma Inline (Get_Last_index);
|
||||
|
||||
function Get_Item (Str: in Elastic_String; Pos: in System_Index) return Character_Type;
|
||||
pragma inline (Get_Item);
|
||||
pragma Inline (Get_Item);
|
||||
|
||||
-- unsafe
|
||||
function Get_Slot_Pointer (Str: in Elastic_String) return Thin_Character_Array_Pointer;
|
||||
pragma inline (Get_Slot_Pointer);
|
||||
pragma Inline (Get_Slot_Pointer);
|
||||
|
||||
function Is_Shared(Str: in Elastic_String) return Standard.Boolean;
|
||||
pragma inline (Is_Shared);
|
||||
pragma Inline (Is_Shared);
|
||||
|
||||
procedure Purge (Str: in out Elastic_String);
|
||||
procedure Clear (Str: in out Elastic_String);
|
||||
|
18
lib2/h3.ads
18
lib2/h3.ads
@ -1,6 +1,5 @@
|
||||
with System;
|
||||
with System.Storage_Pools;
|
||||
with System.Atomic_Counters;
|
||||
with Ada.Finalization;
|
||||
|
||||
package H3 is
|
||||
@ -35,21 +34,4 @@ package H3 is
|
||||
function Align (X: in System_Size; Y: in System_Size) return System_Size;
|
||||
pragma Inline(Align);
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Reference Counting
|
||||
-- ---------------------------------------------------------------------
|
||||
-- type Ref_Counted is abstract tagged record
|
||||
-- --Ref_Count: System.Atomic_Counters.Atomic_Counter;
|
||||
-- Ref_Count: System_Size;
|
||||
-- end record;
|
||||
|
||||
-- type Ref_Counted_Pointer is access all Ref_Counted'Class;
|
||||
-- type Ref is new Ada.Finalization.Controlled with record
|
||||
-- Data: Ref_Counted_Pointer;
|
||||
-- end record;
|
||||
|
||||
-- procedure Set (R: in out Ref; Data: in Ref_Counted_Pointer);
|
||||
-- function Get (R: in Ref) return Ref_Counted_Pointer;
|
||||
-- overriding procedure Adjust (R: in out Ref);
|
||||
-- overriding procedure Finalize (R: in out Ref);
|
||||
end H3;
|
||||
|
Loading…
Reference in New Issue
Block a user