111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
|
|
4 -- --
|
|
5 -- A D A . C A L E N D A R . D E L A Y S --
|
|
6 -- --
|
|
7 -- B o d y --
|
|
8 -- --
|
|
9 -- Copyright (C) 1991-2017, Florida State University --
|
131
|
10 -- Copyright (C) 1995-2018, AdaCore --
|
111
|
11 -- --
|
|
12 -- GNAT is free software; you can redistribute it and/or modify it under --
|
|
13 -- terms of the GNU General Public License as published by the Free Soft- --
|
|
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
|
|
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
|
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
|
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
|
|
18 -- --
|
|
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
20 -- additional permissions described in the GCC Runtime Library Exception, --
|
|
21 -- version 3.1, as published by the Free Software Foundation. --
|
|
22 -- --
|
|
23 -- You should have received a copy of the GNU General Public License and --
|
|
24 -- a copy of the GCC Runtime Library Exception along with this program; --
|
|
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
26 -- <http://www.gnu.org/licenses/>. --
|
|
27 -- --
|
|
28 -- GNARL was developed by the GNARL team at Florida State University. --
|
|
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
|
|
30 -- --
|
|
31 ------------------------------------------------------------------------------
|
|
32
|
|
33 with System.OS_Primitives;
|
|
34 with System.Soft_Links;
|
|
35
|
|
36 package body Ada.Calendar.Delays is
|
|
37
|
|
38 package OSP renames System.OS_Primitives;
|
|
39 package SSL renames System.Soft_Links;
|
|
40
|
|
41 use type SSL.Timed_Delay_Call;
|
|
42
|
|
43 -- Earlier, System.Time_Operations was used to implement the following
|
|
44 -- operations. The idea was to avoid sucking in the tasking packages. This
|
|
45 -- did not work. Logically, we can't have it both ways. There is no way to
|
|
46 -- implement time delays that will have correct task semantics without
|
|
47 -- reference to the tasking run-time system. To achieve this goal, we now
|
|
48 -- use soft links.
|
|
49
|
|
50 -----------------------
|
|
51 -- Local Subprograms --
|
|
52 -----------------------
|
|
53
|
|
54 procedure Timed_Delay_NT (Time : Duration; Mode : Integer);
|
|
55 -- Timed delay procedure used when no tasking is active
|
|
56
|
|
57 ---------------
|
|
58 -- Delay_For --
|
|
59 ---------------
|
|
60
|
|
61 procedure Delay_For (D : Duration) is
|
|
62 begin
|
|
63 SSL.Timed_Delay.all (Duration'Min (D, OSP.Max_Sensible_Delay),
|
|
64 OSP.Relative);
|
|
65 end Delay_For;
|
|
66
|
|
67 -----------------
|
|
68 -- Delay_Until --
|
|
69 -----------------
|
|
70
|
|
71 procedure Delay_Until (T : Time) is
|
|
72 D : constant Duration := To_Duration (T);
|
|
73
|
|
74 begin
|
|
75 SSL.Timed_Delay.all (D, OSP.Absolute_Calendar);
|
|
76 end Delay_Until;
|
|
77
|
|
78 --------------------
|
|
79 -- Timed_Delay_NT --
|
|
80 --------------------
|
|
81
|
|
82 procedure Timed_Delay_NT (Time : Duration; Mode : Integer) is
|
|
83 begin
|
|
84 OSP.Timed_Delay (Time, Mode);
|
|
85 end Timed_Delay_NT;
|
|
86
|
|
87 -----------------
|
|
88 -- To_Duration --
|
|
89 -----------------
|
|
90
|
|
91 function To_Duration (T : Time) return Duration is
|
|
92 begin
|
|
93 -- Since time has multiple representations on different platforms, a
|
|
94 -- target independent operation in Ada.Calendar is used to perform
|
|
95 -- this conversion.
|
|
96
|
|
97 return Delay_Operations.To_Duration (T);
|
|
98 end To_Duration;
|
|
99
|
|
100 begin
|
|
101 -- Set up the Timed_Delay soft link to the non tasking version if it has
|
|
102 -- not been already set. If tasking is present, Timed_Delay has already set
|
|
103 -- this soft link, or this will be overridden during the elaboration of
|
|
104 -- System.Tasking.Initialization
|
|
105
|
|
106 if SSL.Timed_Delay = null then
|
|
107 SSL.Timed_Delay := Timed_Delay_NT'Access;
|
|
108 end if;
|
|
109
|
|
110 end Ada.Calendar.Delays;
|