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 --
10 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
12 -- GNARL 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 2, or (at your option) any later ver- --
15 -- sion. GNARL 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. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This version is for VxWorks targets
38 with System
.OS_Interface
;
39 -- Since the thread library is part of the VxWorks kernel, using OS_Interface
40 -- is not a problem here, as long as we only use System.OS_Interface as a
41 -- set of C imported routines: using Ada routines from this package would
42 -- create a dependency on libgnarl in libgnat, which is not desirable.
47 package body System
.OS_Primitives
is
49 use System
.OS_Interface
;
51 --------------------------
52 -- Internal functions --
53 --------------------------
55 function To_Clock_Ticks
(D
: Duration) return int
;
56 -- Convert a duration value (in seconds) into clock ticks.
57 -- Note that this routine is duplicated from System.OS_Interface since
58 -- as explained above, we do not want to depend on libgnarl
60 function To_Clock_Ticks
(D
: Duration) return int
is
61 Ticks
: Long_Long_Integer;
62 Rate_Duration
: Duration;
63 Ticks_Duration
: Duration;
65 -- Ensure that the duration can be converted to ticks
66 -- at the current clock tick rate without overflowing.
68 Rate_Duration
:= Duration (sysClkRateGet
);
70 if D
> (Duration'Last / Rate_Duration
) then
71 Ticks
:= Long_Long_Integer (int
'Last);
73 -- We always want to round up to the nearest clock tick.
75 Ticks_Duration
:= D
* Rate_Duration
;
76 Ticks
:= Long_Long_Integer (Ticks_Duration
);
78 if Ticks_Duration
> Duration (Ticks
) then
82 if Ticks
> Long_Long_Integer (int
'Last) then
83 Ticks
:= Long_Long_Integer (int
'Last);
94 function Clock
return Duration is
95 TS
: aliased timespec
;
98 use type Interfaces
.C
.int
;
100 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
101 pragma Assert
(Result
= 0);
102 return Duration (TS
.ts_sec
) + Duration (TS
.ts_nsec
) / 10#
1#E9
;
105 ---------------------
106 -- Monotonic_Clock --
107 ---------------------
109 function Monotonic_Clock
return Duration renames Clock
;
115 procedure Timed_Delay
122 Check_Time
: Duration := Clock
;
125 if Mode
= Relative
then
127 Abs_Time
:= Time
+ Check_Time
;
129 Rel_Time
:= Time
- Check_Time
;
133 if Rel_Time
> 0.0 then
135 Result
:= taskDelay
(To_Clock_Ticks
(Rel_Time
));
138 exit when Abs_Time
<= Check_Time
;
140 Rel_Time
:= Abs_Time
- Check_Time
;
145 end System
.OS_Primitives
;