annotate gcc/ada/libgnat/s-osprim__solaris.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . O S _ P R I M I T I V E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1998-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This version uses gettimeofday and select
kono
parents:
diff changeset
33 -- This file is suitable for Solaris (32 and 64 bits).
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package body System.OS_Primitives is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 -- ??? These definitions are duplicated from System.OS_Interface
kono
parents:
diff changeset
38 -- because we don't want to depend on any package. Consider removing
kono
parents:
diff changeset
39 -- these declarations in System.OS_Interface and move these ones in
kono
parents:
diff changeset
40 -- the spec.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 type struct_timeval is record
kono
parents:
diff changeset
43 tv_sec : Long_Integer;
kono
parents:
diff changeset
44 tv_usec : Long_Integer;
kono
parents:
diff changeset
45 end record;
kono
parents:
diff changeset
46 pragma Convention (C, struct_timeval);
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 procedure gettimeofday
kono
parents:
diff changeset
49 (tv : not null access struct_timeval;
kono
parents:
diff changeset
50 tz : Address := Null_Address);
kono
parents:
diff changeset
51 pragma Import (C, gettimeofday, "gettimeofday");
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 procedure C_select
kono
parents:
diff changeset
54 (n : Integer := 0;
kono
parents:
diff changeset
55 readfds,
kono
parents:
diff changeset
56 writefds,
kono
parents:
diff changeset
57 exceptfds : Address := Null_Address;
kono
parents:
diff changeset
58 timeout : not null access struct_timeval);
kono
parents:
diff changeset
59 pragma Import (C, C_select, "select");
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -----------
kono
parents:
diff changeset
62 -- Clock --
kono
parents:
diff changeset
63 -----------
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 function Clock return Duration is
kono
parents:
diff changeset
66 TV : aliased struct_timeval;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 begin
kono
parents:
diff changeset
69 gettimeofday (TV'Access);
kono
parents:
diff changeset
70 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
kono
parents:
diff changeset
71 end Clock;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -----------------
kono
parents:
diff changeset
74 -- Timed_Delay --
kono
parents:
diff changeset
75 -----------------
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 procedure Timed_Delay
kono
parents:
diff changeset
78 (Time : Duration;
kono
parents:
diff changeset
79 Mode : Integer)
kono
parents:
diff changeset
80 is
kono
parents:
diff changeset
81 Rel_Time : Duration;
kono
parents:
diff changeset
82 Abs_Time : Duration;
kono
parents:
diff changeset
83 Base_Time : constant Duration := Clock;
kono
parents:
diff changeset
84 Check_Time : Duration := Base_Time;
kono
parents:
diff changeset
85 timeval : aliased struct_timeval;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 begin
kono
parents:
diff changeset
88 if Mode = Relative then
kono
parents:
diff changeset
89 Rel_Time := Time;
kono
parents:
diff changeset
90 Abs_Time := Time + Check_Time;
kono
parents:
diff changeset
91 else
kono
parents:
diff changeset
92 Rel_Time := Time - Check_Time;
kono
parents:
diff changeset
93 Abs_Time := Time;
kono
parents:
diff changeset
94 end if;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 if Rel_Time > 0.0 then
kono
parents:
diff changeset
97 loop
kono
parents:
diff changeset
98 timeval.tv_sec := Long_Integer (Rel_Time);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 if Duration (timeval.tv_sec) > Rel_Time then
kono
parents:
diff changeset
101 timeval.tv_sec := timeval.tv_sec - 1;
kono
parents:
diff changeset
102 end if;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 timeval.tv_usec :=
kono
parents:
diff changeset
105 Long_Integer ((Rel_Time - Duration (timeval.tv_sec)) * 10#1#E6);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 C_select (timeout => timeval'Unchecked_Access);
kono
parents:
diff changeset
108 Check_Time := Clock;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 Rel_Time := Abs_Time - Check_Time;
kono
parents:
diff changeset
113 end loop;
kono
parents:
diff changeset
114 end if;
kono
parents:
diff changeset
115 end Timed_Delay;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 ----------------
kono
parents:
diff changeset
118 -- Initialize --
kono
parents:
diff changeset
119 ----------------
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 procedure Initialize is
kono
parents:
diff changeset
122 begin
kono
parents:
diff changeset
123 null;
kono
parents:
diff changeset
124 end Initialize;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 end System.OS_Primitives;