Daily bump.
[official-gcc.git] / gcc / ada / s-osinte-darwin.adb
blobac016d06927601adc360153428f632abca7d1544
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ I N T E R F A C E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1999-2009, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This is a Darwin Threads version of this package
34 pragma Polling (Off);
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
40 use Interfaces.C;
42 -----------------
43 -- To_Duration --
44 -----------------
46 function To_Duration (TS : timespec) return Duration is
47 begin
48 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
49 end To_Duration;
51 function To_Duration (TV : struct_timeval) return Duration is
52 begin
53 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
54 end To_Duration;
56 ------------------------
57 -- To_Target_Priority --
58 ------------------------
60 function To_Target_Priority
61 (Prio : System.Any_Priority) return Interfaces.C.int
63 begin
64 return Interfaces.C.int (Prio);
65 end To_Target_Priority;
67 -----------------
68 -- To_Timespec --
69 -----------------
71 function To_Timespec (D : Duration) return timespec is
72 S : time_t;
73 F : Duration;
75 begin
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
80 -- value.
82 if F < 0.0 then
83 S := S - 1;
84 F := F + 1.0;
85 end if;
87 return timespec'(tv_sec => S,
88 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
89 end To_Timespec;
91 ----------------
92 -- To_Timeval --
93 ----------------
95 function To_Timeval (D : Duration) return struct_timeval is
96 S : time_t;
97 F : Duration;
99 begin
100 S := time_t (D);
101 F := D - Duration (S);
103 -- If F has negative value due to a round-up, adjust for positive F
104 -- value.
106 if F < 0.0 then
107 S := S - 1;
108 F := F + 1.0;
109 end if;
111 return struct_timeval'
112 (Tv_Sec => S,
113 tv_usec => int32_t (Long_Long_Integer (F * 10#1#E6)));
114 end To_Timeval;
116 -------------------
117 -- clock_gettime --
118 -------------------
120 function clock_gettime
121 (clock_id : clockid_t;
122 tp : access timespec) return int
124 pragma Unreferenced (clock_id);
125 Result : int;
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");
133 begin
134 Result := gettimeofday (tv'Unchecked_Access);
135 tp.all := To_Timespec (To_Duration (tv));
136 return Result;
137 end clock_gettime;
139 -----------------
140 -- sched_yield --
141 -----------------
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");
147 begin
148 sched_yield_base (System.Null_Address);
149 return 0;
150 end sched_yield;
152 --------------
153 -- lwp_self --
154 --------------
156 function lwp_self return Address is
157 function pthread_mach_thread_np (thread : pthread_t) return Address;
158 pragma Import (C, pthread_mach_thread_np, "pthread_mach_thread_np");
159 begin
160 return pthread_mach_thread_np (pthread_self);
161 end lwp_self;
163 ------------------
164 -- pthread_init --
165 ------------------
167 procedure pthread_init is
168 begin
169 null;
170 end pthread_init;
172 ----------------
173 -- Stack_Base --
174 ----------------
176 function Get_Stack_Base (thread : pthread_t) return Address is
177 pragma Unreferenced (thread);
178 begin
179 return System.Null_Address;
180 end Get_Stack_Base;
182 end System.OS_Interface;