1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ P R I M I T I V E S --
11 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This version is for VxWorks targets
39 with System.OS_Interface;
40 -- Since the thread library is part of the VxWorks kernel, using OS_Interface
41 -- is not a problem here, as long as we only use System.OS_Interface as a
42 -- set of C imported routines: using Ada routines from this package would
43 -- create a dependency on libgnarl in libgnat, which is not desirable.
48 package body System.OS_Primitives is
50 use System.OS_Interface;
52 --------------------------
53 -- Internal functions --
54 --------------------------
56 function To_Clock_Ticks (D : Duration) return int;
57 -- Convert a duration value (in seconds) into clock ticks.
58 -- Note that this routine is duplicated from System.OS_Interface since
59 -- as explained above, we do not want to depend on libgnarl
61 function To_Clock_Ticks (D : Duration) return int is
62 Ticks : Long_Long_Integer;
63 Rate_Duration : Duration;
64 Ticks_Duration : Duration;
66 -- Ensure that the duration can be converted to ticks
67 -- at the current clock tick rate without overflowing.
69 Rate_Duration := Duration (sysClkRateGet);
71 if D > (Duration'Last / Rate_Duration) then
72 Ticks := Long_Long_Integer (int'Last);
74 -- We always want to round up to the nearest clock tick.
76 Ticks_Duration := D * Rate_Duration;
77 Ticks := Long_Long_Integer (Ticks_Duration);
79 if Ticks_Duration > Duration (Ticks) then
83 if Ticks > Long_Long_Integer (int'Last) then
84 Ticks := Long_Long_Integer (int'Last);
95 function Clock return Duration is
96 TS : aliased timespec;
99 use type Interfaces.C.int;
101 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
102 pragma Assert (Result = 0);
103 return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
106 ---------------------
107 -- Monotonic_Clock --
108 ---------------------
110 function Monotonic_Clock return Duration renames Clock;
116 procedure Timed_Delay
123 Check_Time : Duration := Clock;
126 if Mode = Relative then
128 Abs_Time := Time + Check_Time;
130 Rel_Time := Time - Check_Time;
134 if Rel_Time > 0.0 then
136 Result := taskDelay (To_Clock_Ticks (Rel_Time));
139 exit when Abs_Time <= Check_Time;
141 Rel_Time := Abs_Time - Check_Time;
146 end System.OS_Primitives;