1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
9 -- Copyright (C) 1999-2009 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 is a Darwin Threads version of this package
35 -- Turn off polling, we do not want ATC polling to take place during
36 -- tasking operations. It causes infinite loops and other problems.
38 package body System.OS_Interface is
46 function To_Duration (TS : timespec) return Duration is
48 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
51 function To_Duration (TV : struct_timeval) return Duration is
53 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
56 ------------------------
57 -- To_Target_Priority --
58 ------------------------
60 function To_Target_Priority
61 (Prio : System.Any_Priority) return Interfaces.C.int
64 return Interfaces.C.int (Prio);
65 end To_Target_Priority;
71 function To_Timespec (D : Duration) return timespec is
76 S := time_t (Long_Long_Integer (D));
77 F := D - Duration (S);
79 -- If F has negative value due to a round-up, adjust for positive F
87 return timespec'(tv_sec => S,
88 tv_nsec => int32_t (Long_Long_Integer (F * 10#1#E9)));
95 function To_Timeval (D : Duration) return struct_timeval is
101 F := D - Duration (S);
103 -- If F has negative value due to a round-up, adjust for positive F
111 return struct_timeval'
113 tv_usec => int32_t (Long_Long_Integer (F * 10#1#E6)));
120 function clock_gettime
121 (clock_id : clockid_t;
122 tp : access timespec) return int
124 pragma Unreferenced (clock_id);
126 tv : aliased struct_timeval;
128 function gettimeofday
129 (tv : access struct_timeval;
130 tz : System.Address := System.Null_Address) return int;
131 pragma Import (C, gettimeofday, "gettimeofday");
134 Result := gettimeofday (tv'Unchecked_Access);
135 tp.all := To_Timespec (To_Duration (tv));
143 function sched_yield return int is
144 procedure sched_yield_base (arg : System.Address);
145 pragma Import (C, sched_yield_base, "pthread_yield_np");
148 sched_yield_base (System.Null_Address);
156 procedure pthread_init is
165 function Get_Stack_Base (thread : pthread_t) return Address is
166 pragma Unreferenced (thread);
168 return System.Null_Address;
171 end System.OS_Interface;