1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ P R I M I T I V E S --
9 -- Copyright (C) 1998-2023, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This version is for POSIX.1-2008-like operating systems
35 with System
.OS_Constants
;
36 with System
.Parameters
;
37 package body System
.OS_Primitives
is
39 subtype int
is System
.CRTL
.int
;
41 -- ??? These definitions are duplicated from System.OS_Interface because
42 -- we don't want to depend on any package. Consider removing these
43 -- declarations in System.OS_Interface and move these ones to the spec.
45 type time_t
is range -2 ** (System
.Parameters
.time_t_bits
- 1)
46 .. 2 ** (System
.Parameters
.time_t_bits
- 1) - 1;
48 type timespec
is record
50 tv_nsec
: Long_Integer;
52 pragma Convention
(C
, timespec
);
54 function nanosleep
(rqtp
, rmtp
: not null access timespec
) return Integer;
55 pragma Import
(C
, nanosleep
, "nanosleep");
61 function Clock
return Duration is
62 TS
: aliased timespec
;
65 type clockid_t
is new int
;
66 CLOCK_REALTIME
: constant clockid_t
:=
67 System
.OS_Constants
.CLOCK_REALTIME
;
69 function clock_gettime
70 (clock_id
: clockid_t
;
71 tp
: access timespec
) return int
;
72 pragma Import
(C
, clock_gettime
, "clock_gettime");
75 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
76 pragma Assert
(Result
= 0);
77 return Duration (TS
.tv_sec
) + Duration (TS
.tv_nsec
) / 10#
1#E9
;
84 function To_Timespec
(D
: Duration) return timespec
;
86 function To_Timespec
(D
: Duration) return timespec
is
91 S
:= time_t
(Long_Long_Integer (D
));
92 F
:= D
- Duration (S
);
94 -- If F has negative value due to a round-up, adjust for positive F
103 timespec
'(tv_sec => S,
104 tv_nsec => Long_Integer (Long_Long_Integer (F * 10#1#E9)));
111 procedure Timed_Delay
120 procedure Initialize is
125 end System.OS_Primitives;