Natools

Check-in [610b834d9d]
Login
Overview
Comment:references: add Is_Last primitive

It's almost a break in abstraction, and it's unsafe to use when the reference can be accessed concurrently. However it might have some use in some context, to free the last reference when checked in a protected or thread-local context, to build a crude garbage collection system.

Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 610b834d9dfa299d29c0efd41365b0f6d159c65e
User & Date: nat on 2014-08-24 20:31:35
Other Links: manifest | tags
Context
2014-08-25
19:57
reference_tests: also test the new Is_Last function check-in: 111a93ca40 user: nat tags: trunk
2014-08-24
20:31
references: add Is_Last primitive

It's almost a break in abstraction, and it's unsafe to use when the reference can be accessed concurrently. However it might have some use in some context, to free the last reference when checked in a protected or thread-local context, to build a crude garbage collection system. check-in: 610b834d9d user: nat tags: trunk

2014-08-22
17:05
time_io-tests: add a check with an invalid leap-second time, to reach full coverage check-in: c517c2f45f user: nat tags: trunk
Changes

Modified src/natools-references__intel.adb from [bc469c4162] to [e77d1335d9].

111
112
113
114
115
116
117






118
119
120
121
122
123
124


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;








   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";









>
>
>
>
>
>







111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;


   function Is_Last (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count.all = 1;
   end Is_Last;


   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";


Modified src/natools-references__intel.ads from [0b0ecf7c36] to [8d5344f138].

69
70
71
72
73
74
75





76
77
78
79
80
81
82
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object






   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object







>
>
>
>
>







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object

   function Is_Last (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref is the last reference to its object.
      --  WARNING: This is inherently not task-safe if Ref can be
      --  concurrently accessed.

   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object

Modified src/natools-references__protected.adb from [3bfa20ca4b] to [440d417607].

109
110
111
112
113
114
115






116
117
118
119
120
121
122


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;








   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";









>
>
>
>
>
>







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;


   function Is_Last (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count.Get_Value = 1;
   end Is_Last;


   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";


Modified src/natools-references__protected.ads from [18a0c38fdf] to [3cec4789c7].

67
68
69
70
71
72
73





74
75
76
77
78
79
80
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object






   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object







>
>
>
>
>







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object

   function Is_Last (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref is the last reference to its object.
      --  WARNING: This is inherently not task-safe if Ref can be
      --  concurrently accessed.

   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object

Modified src/natools-references__unsafe.adb from [4a7ba030d7] to [6254848d3e].

107
108
109
110
111
112
113






114
115
116
117
118
119
120


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;








   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";









>
>
>
>
>
>







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126


   function Is_Empty (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count = null;
   end Is_Empty;


   function Is_Last (Ref : Immutable_Reference) return Boolean is
   begin
      return Ref.Count.all = 1;
   end Is_Last;


   function "=" (Left, Right : Immutable_Reference) return Boolean is
   begin
      return Left.Data = Right.Data;
   end "=";


Modified src/natools-references__unsafe.ads from [65f8ced397] to [c4d7238aec].

66
67
68
69
70
71
72



73
74
75
76
77
78
79
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object




   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object







>
>
>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object

   function Is_Last (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref is the last reference to its object

   function "=" (Left, Right : Immutable_Reference) return Boolean;
      --  Check whether Left and Right refer to the same object

   function Query (Ref : in Immutable_Reference) return Accessor;
   pragma Inline (Query);
      --  Return a derefenciable constant access to the held object