From 081937df1b9d1577b02a4f4754a9b8461e30433f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 24 Aug 2021 16:07:29 +0000 Subject: [PATCH] stopped using System.Atomic_Counters.Atomic_Counter --- lib2/h3-mm.adb | 24 +++++++++++++++--------- lib2/h3-mm.ads | 5 +++-- lib2/h3-strings.adb | 2 +- lib2/h3-strings.ads | 14 +++++++------- lib2/h3.ads | 18 ------------------ 5 files changed, 26 insertions(+), 37 deletions(-) diff --git a/lib2/h3-mm.adb b/lib2/h3-mm.adb index aa85acd..c55ecf9 100644 --- a/lib2/h3-mm.adb +++ b/lib2/h3-mm.adb @@ -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,11 +47,16 @@ 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; -end H3.MM; \ No newline at end of file +end H3.MM; diff --git a/lib2/h3-mm.ads b/lib2/h3-mm.ads index 5260b2a..5caff85 100644 --- a/lib2/h3-mm.ads +++ b/lib2/h3-mm.ads @@ -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; @@ -32,4 +33,4 @@ package H3.MM is overriding procedure Finalize (R: in out Ref_Counted); -end H3.MM; \ No newline at end of file +end H3.MM; diff --git a/lib2/h3-strings.adb b/lib2/h3-strings.adb index 97164c3..28f802f 100644 --- a/lib2/h3-strings.adb +++ b/lib2/h3-strings.adb @@ -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 diff --git a/lib2/h3-strings.ads b/lib2/h3-strings.ads index 029e8e9..d441265 100644 --- a/lib2/h3-strings.ads +++ b/lib2/h3-strings.ads @@ -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); diff --git a/lib2/h3.ads b/lib2/h3.ads index 103b154..938b1a9 100644 --- a/lib2/h3.ads +++ b/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;