1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
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-1994, Florida State University --
|
10 |
|
|
-- Copyright (C) 1995-2010, AdaCore --
|
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 |
|
|
with System.Traces;
|
36 |
|
|
with System.Parameters;
|
37 |
|
|
|
38 |
|
|
package body Ada.Calendar.Delays is
|
39 |
|
|
|
40 |
|
|
package OSP renames System.OS_Primitives;
|
41 |
|
|
package SSL renames System.Soft_Links;
|
42 |
|
|
|
43 |
|
|
use type SSL.Timed_Delay_Call;
|
44 |
|
|
|
45 |
|
|
use System.Traces;
|
46 |
|
|
|
47 |
|
|
-- Earlier, System.Time_Operations was used to implement the following
|
48 |
|
|
-- operations. The idea was to avoid sucking in the tasking packages. This
|
49 |
|
|
-- did not work. Logically, we can't have it both ways. There is no way to
|
50 |
|
|
-- implement time delays that will have correct task semantics without
|
51 |
|
|
-- reference to the tasking run-time system. To achieve this goal, we now
|
52 |
|
|
-- use soft links.
|
53 |
|
|
|
54 |
|
|
-----------------------
|
55 |
|
|
-- Local Subprograms --
|
56 |
|
|
-----------------------
|
57 |
|
|
|
58 |
|
|
procedure Timed_Delay_NT (Time : Duration; Mode : Integer);
|
59 |
|
|
-- Timed delay procedure used when no tasking is active
|
60 |
|
|
|
61 |
|
|
---------------
|
62 |
|
|
-- Delay_For --
|
63 |
|
|
---------------
|
64 |
|
|
|
65 |
|
|
procedure Delay_For (D : Duration) is
|
66 |
|
|
begin
|
67 |
|
|
if System.Parameters.Runtime_Traces then
|
68 |
|
|
Send_Trace_Info (W_Delay, D);
|
69 |
|
|
end if;
|
70 |
|
|
|
71 |
|
|
SSL.Timed_Delay.all (Duration'Min (D, OSP.Max_Sensible_Delay),
|
72 |
|
|
OSP.Relative);
|
73 |
|
|
|
74 |
|
|
if System.Parameters.Runtime_Traces then
|
75 |
|
|
Send_Trace_Info (M_Delay, D);
|
76 |
|
|
end if;
|
77 |
|
|
end Delay_For;
|
78 |
|
|
|
79 |
|
|
-----------------
|
80 |
|
|
-- Delay_Until --
|
81 |
|
|
-----------------
|
82 |
|
|
|
83 |
|
|
procedure Delay_Until (T : Time) is
|
84 |
|
|
D : constant Duration := To_Duration (T);
|
85 |
|
|
|
86 |
|
|
begin
|
87 |
|
|
if System.Parameters.Runtime_Traces then
|
88 |
|
|
Send_Trace_Info (WU_Delay, D);
|
89 |
|
|
end if;
|
90 |
|
|
|
91 |
|
|
SSL.Timed_Delay.all (D, OSP.Absolute_Calendar);
|
92 |
|
|
|
93 |
|
|
if System.Parameters.Runtime_Traces then
|
94 |
|
|
Send_Trace_Info (M_Delay, D);
|
95 |
|
|
end if;
|
96 |
|
|
end Delay_Until;
|
97 |
|
|
|
98 |
|
|
--------------------
|
99 |
|
|
-- Timed_Delay_NT --
|
100 |
|
|
--------------------
|
101 |
|
|
|
102 |
|
|
procedure Timed_Delay_NT (Time : Duration; Mode : Integer) is
|
103 |
|
|
begin
|
104 |
|
|
OSP.Timed_Delay (Time, Mode);
|
105 |
|
|
end Timed_Delay_NT;
|
106 |
|
|
|
107 |
|
|
-----------------
|
108 |
|
|
-- To_Duration --
|
109 |
|
|
-----------------
|
110 |
|
|
|
111 |
|
|
function To_Duration (T : Time) return Duration is
|
112 |
|
|
begin
|
113 |
|
|
-- Since time has multiple representations on different platforms, a
|
114 |
|
|
-- target independent operation in Ada.Calendar is used to perform
|
115 |
|
|
-- this conversion.
|
116 |
|
|
|
117 |
|
|
return Delay_Operations.To_Duration (T);
|
118 |
|
|
end To_Duration;
|
119 |
|
|
|
120 |
|
|
begin
|
121 |
|
|
-- Set up the Timed_Delay soft link to the non tasking version if it has
|
122 |
|
|
-- not been already set. If tasking is present, Timed_Delay has already set
|
123 |
|
|
-- this soft link, or this will be overridden during the elaboration of
|
124 |
|
|
-- System.Tasking.Initialization
|
125 |
|
|
|
126 |
|
|
if SSL.Timed_Delay = null then
|
127 |
|
|
SSL.Timed_Delay := Timed_Delay_NT'Access;
|
128 |
|
|
end if;
|
129 |
|
|
|
130 |
|
|
end Ada.Calendar.Delays;
|