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-2020, 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 package body System.OS_Primitives is
38 subtype int is System.CRTL.int;
40 -- ??? These definitions are duplicated from System.OS_Interface because
41 -- we don't want to depend on any package. Consider removing these
42 -- declarations in System.OS_Interface and move these ones to the spec.
44 type time_t is new System.CRTL.int64;
46 type timespec is record
48 tv_nsec : Long_Integer;
50 pragma Convention (C, timespec);
52 function nanosleep (rqtp, rmtp : not null access timespec) return Integer;
53 pragma Import (C, nanosleep, "nanosleep");
59 function Clock return Duration is
60 TS : aliased timespec;
63 type clockid_t is new int;
64 CLOCK_REALTIME : constant clockid_t :=
65 System.OS_Constants.CLOCK_REALTIME;
67 function clock_gettime
68 (clock_id : clockid_t;
69 tp : access timespec) return int;
70 pragma Import (C, clock_gettime, "clock_gettime");
73 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
74 pragma Assert (Result = 0);
75 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
82 function To_Timespec (D : Duration) return timespec;
84 function To_Timespec (D : Duration) return timespec is
89 S := time_t (Long_Long_Integer (D));
90 F := D - Duration (S);
92 -- If F has negative value due to a round-up, adjust for positive F
101 timespec'(tv_sec => S,
102 tv_nsec => Long_Integer (Long_Long_Integer (F * 10#1#E9)));
109 procedure Timed_Delay
118 procedure Initialize is
123 end System.OS_Primitives;