garlic_90ef4b6f/Garlic/s-gasoli.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
 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
------------------------------------------------------------------------------
--                                                                          --
--                            GLADE COMPONENTS                              --
--                                                                          --
--             S Y S T E M . G A R L I C . S O F T _ L I N K S              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--         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.Calendar; use Ada.Calendar;
with Ada.Unchecked_Deallocation;

with System.Garlic.Types; use System.Garlic.Types;

package body System.Garlic.Soft_Links is

   Mutex_Create     : Mutex_Creation_Function;
   Watcher_Create   : Watcher_Creation_Function;
   Adv_Mutex_Create : Adv_Mutex_Creation_Function;

   procedure Free is
      new Ada.Unchecked_Deallocation (Mutex_Type'Class, Mutex_Access);

   procedure Free is
      new Ada.Unchecked_Deallocation (Watcher_Type'Class, Watcher_Access);

   procedure Free is
     new Ada.Unchecked_Deallocation (Adv_Mutex_Type'Class, Adv_Mutex_Access);

   generic package Proc is
      procedure Register (P : Parameterless_Procedure);
      procedure Call;
      pragma Inline (Call);
   end Proc;

   package body Proc is

      Var : Parameterless_Procedure;

      ----------
      -- Call --
      ----------

      procedure Call is
      begin
         if Var /= null then
            Var.all;
         end if;
      end Call;

      --------------
      -- Register --
      --------------

      procedure Register (P : Parameterless_Procedure) is
      begin
         Var := P;
      end Register;

   end Proc;

   package P_Add_Non_Terminating_Task is new Proc;
   procedure Register_Add_Non_Terminating_Task
     (P : Parameterless_Procedure)
     renames P_Add_Non_Terminating_Task.Register;
   procedure Add_Non_Terminating_Task
     renames P_Add_Non_Terminating_Task.Call;

   package P_Sub_Non_Terminating_Task is new Proc;
   procedure Register_Sub_Non_Terminating_Task
     (P : Parameterless_Procedure)
     renames P_Sub_Non_Terminating_Task.Register;
   procedure Sub_Non_Terminating_Task
     renames P_Sub_Non_Terminating_Task.Call;

   package P_Activity_Detected is new Proc;
   procedure Register_Activity_Detected
     (P : Parameterless_Procedure)
     renames P_Activity_Detected.Register;
   procedure Activity_Detected
     renames P_Activity_Detected.Call;

   package P_Local_Termination is new Proc;
   procedure Register_Local_Termination
     (P : Parameterless_Procedure)
     renames P_Local_Termination.Register;
   procedure Local_Termination
     renames P_Local_Termination.Call;

   package P_Global_Termination is new Proc;
   procedure Register_Global_Termination
     (P : Parameterless_Procedure)
     renames P_Global_Termination.Register;
   procedure Global_Termination
     renames P_Global_Termination.Call;

   package P_Enter_Critical_Section is new Proc;
   procedure Register_Enter_Critical_Section
     (P : Parameterless_Procedure)
     renames P_Enter_Critical_Section.Register;
   procedure Enter_Critical_Section
     renames P_Enter_Critical_Section.Call;

   package P_Leave_Critical_Section is new Proc;
   procedure Register_Leave_Critical_Section
     (P : Parameterless_Procedure)
     renames P_Leave_Critical_Section.Register;
   procedure Leave_Critical_Section
     renames P_Leave_Critical_Section.Call;

   package P_RPC_Shutdown is new Proc;
   procedure Register_RPC_Shutdown
     (P : Parameterless_Procedure)
     renames P_RPC_Shutdown.Register;
   procedure RPC_Shutdown
     renames P_RPC_Shutdown.Call;

   Is_Env_Task : Return_Boolean_Function;

   Awake_Count : Return_Natural_Function;

   Ind_Task_Count : Return_Natural_Function;

   package P_List_Tasks is new Proc;
   procedure Register_List_Tasks
     (P : Parameterless_Procedure)
     renames P_List_Tasks.Register;
   procedure List_Tasks
     renames P_List_Tasks.Call;

   Get_Task_Priority : Return_Natural_Function;
   Set_Task_Priority : Natural_Parameter_Procedure;

--    Get_Task_Stamp    : Return_Float_Function;
--    Set_Task_Stamp    : Float_Parameter_Procedure;

   procedure Free is
      new Ada.Unchecked_Deallocation
     (Abort_Handler_Type'Class, Abort_Handler_Access);

   Var_Abort_Handler : Abort_Handler_Access;

   -------------------
   -- Abort_Handler --
   -------------------

   function Abort_Handler return Abort_Handler_Type'Class is
   begin
      return Var_Abort_Handler.all;
   end Abort_Handler;

   ------------
   -- Adjust --
   ------------

   procedure Adjust (Self : in out Abort_Handler_Type)
   is
      pragma Unreferenced (Self);
   begin
      null;
   end Adjust;

   ------------
   -- Create --
   ------------

   procedure Create (M : out Mutex_Access) is
   begin
      M := Mutex_Create.all;
   end Create;

   ------------
   -- Create --
   ------------

   procedure Create
     (W : out Watcher_Access;
      V : Version_Id := No_Version) is
   begin
      W := Watcher_Create (V);
   end Create;

   ------------
   -- Create --
   ------------

   procedure Create (M :  out Adv_Mutex_Access) is
   begin
      M := Adv_Mutex_Create.all;
   end Create;

   -------------
   -- Destroy --
   -------------

   procedure Destroy (M : in out Mutex_Access) is
   begin
      if M /= null then
         Destroy (M.all);
         Free (M);
      end if;
   end Destroy;

   -------------
   -- Destroy --
   -------------

   procedure Destroy (W : in out Watcher_Access) is
   begin
      if W /= null then
         Destroy (W.all);
         Free (W);
      end if;
   end Destroy;

   -------------
   -- Destroy --
   -------------

   procedure Destroy (M : in out Adv_Mutex_Access) is
   begin
      if M /= null then
         Destroy (M.all);
         Free (M);
      end if;
   end Destroy;

   ------------
   -- Differ --
   ------------

   procedure Differ (W : Watcher_Access; V : Types.Version_Id) is
   begin
      pragma Assert (W /= null);
      Differ (W.all, V);
   end Differ;

   -----------
   -- Enter --
   -----------

   procedure Enter (M : Mutex_Access) is
   begin
      pragma Assert (M /= null);
      Enter (M.all);
   end Enter;

   -----------
   -- Enter --
   -----------

   procedure Enter (M : Adv_Mutex_Access) is
   begin
      pragma Assert (M /= null);
      Enter (M.all);
   end Enter;

   --------------------------
   -- Env_Task_Awake_Count --
   --------------------------

   function Env_Task_Awake_Count return Natural is
   begin
      return Awake_Count.all;
   end Env_Task_Awake_Count;

   ------------------
   -- Get_Priority --
   ------------------

   function Get_Priority return Natural is
   begin
      return Get_Task_Priority.all;
   end Get_Priority;

--    ---------------
--    -- Get_Stamp --
--    ---------------

--    function Get_Stamp return Float is
--    begin
--       return Get_Task_Stamp.all;
--    end Get_Stamp;

   -----------------------------
   -- Independent_Task_Count --
   -----------------------------

   function Independent_Task_Count return Natural is
   begin
      return Ind_Task_Count.all;
   end Independent_Task_Count;

   -------------------------
   -- Is_Environment_Task --
   -------------------------

   function Is_Environment_Task return Boolean is
   begin
      return Is_Env_Task.all;
   end Is_Environment_Task;

   -----------
   -- Leave --
   -----------

   procedure Leave (M : Mutex_Access) is
   begin
      pragma Assert (M /= null);
      Leave (M.all);
   end Leave;

   -----------
   -- Leave --
   -----------

   procedure Leave (M : Adv_Mutex_Access) is
   begin
      pragma Assert (M /= null);
      Leave (M.all);
   end Leave;

   ------------
   -- Lookup --
   ------------

   procedure Lookup (W : Watcher_Access; V : out Types.Version_Id) is
   begin
      pragma Assert (W /= null);
      Lookup (W.all, V);
   end Lookup;

   ----------------------------
   -- Register_Abort_Handler --
   ----------------------------

   procedure Register_Abort_Handler
     (Abort_Handler : Abort_Handler_Access) is
   begin
      if Var_Abort_Handler /= null then
         Free (Var_Abort_Handler);
      end if;
      Var_Abort_Handler := Abort_Handler;
   end Register_Abort_Handler;

   ------------------------------------------
   -- Register_Adv_Mutex_Creation_Function --
   ------------------------------------------

   procedure Register_Adv_Mutex_Creation_Function
     (F : Adv_Mutex_Creation_Function)
   is
   begin
      Adv_Mutex_Create := F;
   end Register_Adv_Mutex_Creation_Function;

   -----------------------------------
   -- Register_Env_Task_Awake_Count --
   -----------------------------------

   procedure Register_Env_Task_Awake_Count
     (F : Return_Natural_Function) is
   begin
      Awake_Count := F;
   end Register_Env_Task_Awake_Count;

   ---------------------------
   -- Register_Get_Priority --
   ---------------------------

   procedure Register_Get_Priority
     (F : Return_Natural_Function) is
   begin
      Get_Task_Priority := F;
   end Register_Get_Priority;

--    ------------------------
--    -- Register_Get_Stamp --
--    ------------------------

--    procedure Register_Get_Stamp
--      (F : Return_Float_Function)
--    is
--    begin
--       Get_Task_Stamp := F;
--    end Register_Get_Stamp;

   -------------------------------------
   -- Register_Independent_Task_Count --
   -------------------------------------

   procedure Register_Independent_Task_Count
     (F : Return_Natural_Function) is
   begin
      Ind_Task_Count := F;
   end Register_Independent_Task_Count;

   ----------------------------------
   -- Register_Is_Environment_Task --
   ----------------------------------

   procedure Register_Is_Environment_Task
     (F : Return_Boolean_Function)
   is
   begin
      Is_Env_Task := F;
   end Register_Is_Environment_Task;

   --------------------------------------
   -- Register_Mutex_Creation_Function --
   --------------------------------------

   procedure Register_Mutex_Creation_Function
     (F : Mutex_Creation_Function)
   is
   begin
      Mutex_Create := F;
   end Register_Mutex_Creation_Function;

   ---------------------------
   -- Register_Set_Priority --
   ---------------------------

   procedure Register_Set_Priority
     (P : Natural_Parameter_Procedure) is
   begin
      Set_Task_Priority := P;
   end Register_Set_Priority;

--    ------------------------
--    -- Register_Set_Stamp --
--    ------------------------

--    procedure Register_Set_Stamp
--      (P : Float_Parameter_Procedure)
--    is
--    begin
--       Set_Task_Stamp := P;
--    end Register_Set_Stamp;

   ----------------------------------------
   -- Register_Watcher_Creation_Function --
   ----------------------------------------

   procedure Register_Watcher_Creation_Function
     (F : Watcher_Creation_Function)
   is
   begin
      Watcher_Create := F;
   end Register_Watcher_Creation_Function;

   ------------------
   -- Set_Priority --
   ------------------

   procedure Set_Priority (P : Natural) is
   begin
      Set_Task_Priority (P);
   end Set_Priority;

--    ---------------
--    -- Set_Stamp --
--    ---------------

--    procedure Set_Stamp (S : Float) is
--    begin
--       Set_Task_Stamp (S);
--    end Set_Stamp;

--    -----------------
--    -- Stamp_Image --
--    -----------------

--    function Stamp_Image (M : String) return String is
--       S : constant Float := Get_Stamp;
--       N : Integer;
--       A : String (1 .. 10) := (others => ' ');
--       R : String (1 .. 10) := (others => ' ');

--    begin
--       N := Integer (S * 1_000.0);
--       for I in reverse A'Range loop
--          A (I) := Hex ((N mod 10) + 1);
--          N := N / 10;
--          exit when N = 0;
--       end loop;
--       N := Integer ((Float (Seconds (Clock)) - S) * 1_000.0);
--       if N < 0 then
--          N := 0;
--       end if;
--       for I in reverse R'Range loop
--          R (I) := Hex ((N mod 10) + 1);
--          N := N  / 10;
--          exit when N = 0;
--       end loop;
--       return A & ASCII.HT & R & "ms" & ASCII.HT & M;
--    end Stamp_Image;

   ------------
   -- Update --
   ------------

   procedure Update (W : Watcher_Access) is
   begin
      pragma Assert (W /= null);
      Update (W.all);
   end Update;

end System.Garlic.Soft_Links;