simple_components_4.68.0_da9b0f3a/synchronization-interprocess-generic_shared_object.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--                                                                    --
--  package                         Copyright (c)  Dmitry A. Kazakov  --
--     Synchronization.Interprocess.               Luebeck            --
--     Generic_Shared_Object                       Spring, 2018       --
--  Implementation                                                    --
--                                Last revision :  19:18 30 Apr 2018  --
--                                                                    --
--  This  library  is  free software; you can redistribute it and/or  --
--  modify it under the terms of the GNU General Public  License  as  --
--  published by the Free Software Foundation; either version  2  of  --
--  the License, or (at your option) any later version. This library  --
--  is distributed in the hope that it will be useful,  but  WITHOUT  --
--  ANY   WARRANTY;   without   even   the   implied   warranty   of  --
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  --
--  General  Public  License  for  more  details.  You  should  have  --
--  received  a  copy  of  the GNU General Public License along with  --
--  this library; if not, write to  the  Free  Software  Foundation,  --
--  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    --
--                                                                    --
--  As a special exception, if other files instantiate generics from  --
--  this unit, or you link this unit with other files to produce  an  --
--  executable, this unit does not by  itself  cause  the  resulting  --
--  executable to be covered by the GNU General Public License. This  --
--  exception  does not however invalidate any other reasons why the  --
--  executable file might be covered by the GNU Public License.       --
--____________________________________________________________________--

with Ada.Exceptions;     use Ada.Exceptions;
with Ada.IO_Exceptions;  use Ada.IO_Exceptions;
with Ada.Tags;           use Ada.Tags;

package body Synchronization.Interprocess.Generic_Shared_Object is

   procedure Finalize (Object : in out Shared_Object) is
   begin
      null;
   end Finalize;

   procedure Generic_Call (Object : in out Shared_Object) is
      Lock : Holder (Object.Lock.all'Unchecked_Access);
   begin
      Operation (Object.Value.all);
   end Generic_Call;

   function Get (Object : Shared_Object) return Object_Type is
      Lock : Holder (Object.Lock.all'Unchecked_Access);
   begin
      return Object.Value.all;
   end Get;

   function Get_Signature (Object : Shared_Object) return Unsigned_16 is
   begin
      return Get_Signature (External_Tag (Shared_Object'Tag));
   end Get_Signature;

   function Get_Size (Object : Shared_Object) return Storage_Count is
   begin
      return Round (Object_Type'Max_Size_In_Storage_Elements);
   end Get_Size;

   procedure Set
             (  Object : in out Shared_Object;
                Value  : Object_Type
             )  is
      Lock : Holder (Object.Lock.all'Unchecked_Access);
   begin
      Object.Value.all := Value;
   end Set;

   procedure Map
             (  Object   : in out Shared_Object;
                Shared   : in out Abstract_Shared_Environment'Class;
                Location : System.Address;
                Size     : Storage_Count;
                Owner    : Boolean
             )  is
      package Mapper is new Generic_Memory_Mapper (Object_Type);
      This : Abstract_Shared_Object_Ptr := Shared.First;
   begin
      while This /= null and then This /= Object'Unchecked_Access loop
         if This.all in Mutex'Class then
            Object.Lock := Mutex'Class (This.all)'Unchecked_Access;
         end if;
         This := This.Next;
      end loop;
      if Object.Lock = null then
         Raise_Exception
         (  Mode_Error'Identity,
            (  "The environment contains no mutex record member "
            &  "appearing before the shared object"
         )  );
      end if;
      Object.Value := Mapper.Map (Location, Owner).all'Unchecked_Access;
   end Map;

end Synchronization.Interprocess.Generic_Shared_Object;