garlic_6.0.1_90ef4b6f/Garlic/s-gartas.ads

  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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
------------------------------------------------------------------------------
--                                                                          --
--                            GLADE COMPONENTS                              --
--                                                                          --
--                S Y S T E M . G A R L I C . T A S K I N G                 --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--         Copyright (C) 1996-2020 Free Software Foundation, Inc.           --
--                                                                          --
-- GARLIC 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- --
-- sion.  GARLIC is distributed  in the hope that  it will be  useful,  but --
-- WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHANTABI- --
-- LITY 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 GARLIC;  see file COPYING.  If  --
-- not, write to the Free Software Foundation, 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.Task_Identification;
pragma Elaborate_All (Ada.Task_Identification);
with Ada.Unchecked_Deallocation;

with System.Garlic.Soft_Links;
with System.Garlic.Types;

package System.Garlic.Tasking is

   procedure Initialize;

   -------------------------------------------
   -- Critical Section for PCS with Tasking --
   -------------------------------------------

   procedure Enter_Critical_Section;

   procedure Leave_Critical_Section;

   --------------------------------
   -- Mutex for PCS with Tasking --
   --------------------------------

   type Protected_Mutex_Type is new Soft_Links.Mutex_Type with private;

   function Create return Soft_Links.Mutex_Access;

   procedure Enter (M : Protected_Mutex_Type);

   procedure Destroy (M : in out Protected_Mutex_Type);

   procedure Leave (M : Protected_Mutex_Type);

   ----------------------------------
   -- Watcher for PCS with Tasking --
   ----------------------------------

   type Protected_Watcher_Type is new Soft_Links.Watcher_Type with private;

   function Create (V : Types.Version_Id) return Soft_Links.Watcher_Access;

   procedure Destroy (W : in out Protected_Watcher_Type);

   procedure Differ
     (W : in out Protected_Watcher_Type;
      V : Types.Version_Id);

   procedure Lookup
     (W : Protected_Watcher_Type;
      V : out Types.Version_Id);

   procedure Update (W : in out Protected_Watcher_Type);

   -----------------------------------------
   -- Advanced Mutex for PCS with Tasking --
   -----------------------------------------

   type Protected_Adv_Mutex_Type is new Soft_Links.Adv_Mutex_Type with private;

   function Create return Soft_Links.Adv_Mutex_Access;

   procedure Enter (M : in out Protected_Adv_Mutex_Type);

   procedure Destroy (M : in out Protected_Adv_Mutex_Type);

   procedure Leave (M : in out Protected_Adv_Mutex_Type);

   function Is_Environment_Task return Boolean;

   function Env_Task_Awake_Count return Natural;

   function Independent_Task_Count return Natural;

   procedure List_Tasks;

   function Get_Priority return Natural;

   procedure Set_Priority (P : Natural);

--    function Get_Task_Stamp return Float;

--    procedure Set_Task_Stamp (S : Float);

   --  We export Mutex_PO because the abortable part of a select ...
   --  then abort construct must be an entry call.

   protected type Mutex_PO is
      entry Enter;
      procedure Leave;
      function Is_Held return Boolean;
   private
      Held : Boolean := False;
   end Mutex_PO;

   type Mutex_PO_Access is access Mutex_PO;

   procedure Free is
     new Ada.Unchecked_Deallocation (Mutex_PO, Mutex_PO_Access);

private

   type Protected_Mutex_Type is new Soft_Links.Mutex_Type
     with record
        X : Mutex_PO_Access;
     end record;

   protected type Watcher_PO is
      procedure Update;
      entry Differ (From : Types.Version_Id);
      function Lookup return Types.Version_Id;
      procedure Init (Initial_Value : Types.Version_Id);
   private
      entry Wait_For_Update (From : Types.Version_Id);
      Value   : Types.Version_Id;
      Updated : Boolean := False;
   end Watcher_PO;

   type Protected_Watcher_Type is new Soft_Links.Watcher_Type with record
      P : Watcher_PO;
   end record;

   protected type Clever_Lock is
      entry Lock;
      entry Unlock;
      --  This entry could be a procedure, but we want the Task_Id of the
      --  caller for debugging purpose.
   private
      entry Contention;
      Count : Natural := 0;
      Owner : Ada.Task_Identification.Task_Id;
   end Clever_Lock;

   type Protected_Adv_Mutex_Type is new Soft_Links.Adv_Mutex_Type
     with record
        X : Clever_Lock;
     end record;

end System.Garlic.Tasking;