-- --
-- S p e c --
-- --
--- --
--- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
+-- Copyright (C) 1998-2009, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
--- ware Foundation; either version 2, or (at your option) any later ver- --
+-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception, --
+-- version 3.1, as published by the Free Software Foundation. --
-- --
--- 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. --
+-- You should have received a copy of the GNU General Public License and --
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
+-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- provides a more general implementation not dedicated to file
-- storage.
+-- This unit (and shared passive partitions) are supported on all
+-- GNAT implementations except on OpenVMS (where problems arise from
+-- trying to share files, and with version numbers of files)
+
-- --------------------------
-- -- Shared Storage Model --
-- --------------------------
-- The approach is as follows:
--- For each shared variable, var, an access routine varR is created whose
--- body has the following form (this example is for Pkg.Var):
-
--- procedure varR is
--- S : Ada.Streams.Stream_IO.Stream_Access;
--- begin
--- S := Shared_Var_ROpen ("pkg.var");
--- if S /= null then
--- typ'Read (S);
--- Shared_Var_Close (S);
--- end if;
--- end varR;
-
--- The routine Shared_Var_ROpen in package System.Shared_Storage
--- either returns null if the storage does not exist, or otherwise a
--- Stream_Access value that references the corresponding shared
--- storage, ready to read the current value.
-
--- Each reference to the shared variable, var, is preceded by a
--- call to the corresponding varR procedure, which either leaves the
--- initial value unchanged if the storage does not exist, or reads
--- the current value from the shared storage.
-
--- In addition, for each shared variable, var, an assignment routine
--- is created whose body has the following form (again for Pkg.Var)
-
--- procedure VarA is
--- S : Ada.Streams.Stream_IO.Stream_Access;
--- begin
--- S := Shared_Var_WOpen ("pkg.var");
--- typ'Write (S, var);
--- Shared_Var_Close (S);
--- end VarA;
-
--- The routine Shared_Var_WOpen in package System.Shared_Storage
--- returns a Stream_Access value that references the corresponding
--- shared storage, ready to write the new value.
-
--- Each assignment to the shared variable, var, is followed by a call
--- to the corresponding varA procedure, which writes the new value to
--- the shared storage.
-
--- Note that there is no general synchronization for these storage
--- read and write operations, since it is assumed that a correctly
--- operating programs will provide appropriate synchronization. In
--- particular, variables can be protected using protected types with
--- no entries.
-
--- The routine Shared_Var_Close is called to indicate the end of a
--- read/write operations. This can be useful even in the context of
--- the GNAT implementation. For instance, when a read operation and a
--- write operation occur at the same time on the same partition, as
--- the same stream is used simultaneously, both operations can
--- terminate abruptly by raising exception Mode_Error because the
--- stream has been opened in read mode and then in write mode and at
--- least used by the read opartion. To avoid this unexpected
--- behaviour, we introduce a synchronization at the partition level.
+-- For each shared variable, var, an instantiation of the below generic
+-- package is created which provides Read and Write supporting procedures.
+
+-- The routine Read in package System.Shared_Storage.Shared_Var_Procs
+-- ensures to assign variable V to the last written value among processes
+-- referencing it. A call to this procedure is generated by the expander
+-- before each read access to the shared variable.
+
+-- The routine Write in package System.Shared_Storage.Shared_Var_Proc
+-- set a new value to the shared variable and, according to the used
+-- implementation, propagate this value among processes referencing it.
+-- A call to this procedure is generated by the expander after each
+-- assignment of the shared variable.
-- Note: a special circuit allows the use of stream attributes Read and
-- Write for limited types (using the corresponding attribute for the
-- These calls to the read and assign routines, as well as the lock
-- and unlock routines, are inserted by the expander (see exp_smem.adb).
-with Ada.Streams.Stream_IO;
-
package System.Shared_Storage is
- package SIO renames Ada.Streams.Stream_IO;
-
- function Shared_Var_ROpen (Var : String) return SIO.Stream_Access;
- -- As described above, this routine returns null if the
- -- corresponding shared storage does not exist, and otherwise, if
- -- the storage does exist, a Stream_Access value that references
- -- the shared storage, ready to read the current value.
-
- function Shared_Var_WOpen (Var : String) return SIO.Stream_Access;
- -- As described above, this routine returns a Stream_Access value
- -- that references the shared storage, ready to write the new
- -- value. The storage is created by this call if it does not
- -- already exist.
-
- procedure Shared_Var_Close (Var : in SIO.Stream_Access);
- -- This routine signals the end of a read/assign operation. It can
- -- be useful to embrace a read/write operation between a call to
- -- open and a call to close which protect the whole operation.
- -- Otherwise, two simultaneous operations can result in the
- -- raising of exception Data_Error by setting the access mode of
- -- the variable in an incorrect mode.
-
procedure Shared_Var_Lock (Var : String);
-- This procedure claims the shared storage lock. It is used for
-- protected types in shared passive packages. A call to this
-- the lock is busy.
procedure Shared_Var_Unlock (Var : String);
- -- This procedure releases the shared storage lock obtaind by a
- -- prior call to the Shared_Mem_Lock procedure, and is to be
+ -- This procedure releases the shared storage lock obtained by a
+ -- prior call to the Shared_Var_Lock procedure, and is to be
-- generated as the last operation in the body of a protected
-- subprogram.
+ -- This generic package is instantiated for each shared passive
+ -- variable. It provides supporting procedures called upon each
+ -- read or write access by the expanded code.
+
+ generic
+
+ type Typ is limited private;
+ -- Shared passive variable type
+
+ V : in out Typ;
+ -- Shared passive variable
+
+ Full_Name : String;
+ -- Shared passive variable storage name
+
+ package Shared_Var_Procs is
+
+ procedure Read;
+ -- Shared passive variable access routine. Each reference to the
+ -- shared variable, V, is preceded by a call to the corresponding
+ -- Read procedure, which either leaves the initial value unchanged
+ -- if the storage does not exist, or reads the current value from
+ -- the shared storage.
+
+ procedure Write;
+ -- Shared passive variable assignment routine. Each assignment to
+ -- the shared variable, V, is followed by a call to the corresponding
+ -- Write procedure, which writes the new value to the shared storage.
+
+ end Shared_Var_Procs;
+
end System.Shared_Storage;