Add x prefix to v850e case for handling --with-cpu=v850e.
[official-gcc.git] / gcc / ada / 5hosinte.adb
blob5436f44569488a5c2678a7c4491ce479bd48bb9f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA 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 -- --
10 -- Copyright (C) 1991-2001, Florida State University --
11 -- --
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. --
22 -- --
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. --
29 -- --
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). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is a DCE version of this package.
37 -- Currently HP-UX and SNI use this file
39 pragma Polling (Off);
40 -- Turn off polling, we do not want ATC polling to take place during
41 -- tasking operations. It causes infinite loops and other problems.
43 -- This package encapsulates all direct interfaces to OS services
44 -- that are needed by children of System.
46 with Interfaces.C; use Interfaces.C;
48 package body System.OS_Interface is
50 -----------------
51 -- To_Duration --
52 -----------------
54 function To_Duration (TS : timespec) return Duration is
55 begin
56 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
57 end To_Duration;
59 -----------------
60 -- To_Timespec --
61 -----------------
63 function To_Timespec (D : Duration) return timespec is
64 S : time_t;
65 F : Duration;
67 begin
68 S := time_t (Long_Long_Integer (D));
69 F := D - Duration (S);
71 -- If F has negative value due to a round-up, adjust for positive F
72 -- value.
73 if F < 0.0 then
74 S := S - 1;
75 F := F + 1.0;
76 end if;
78 return timespec' (tv_sec => S,
79 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
80 end To_Timespec;
82 function To_Duration (TV : struct_timeval) return Duration is
83 begin
84 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
85 end To_Duration;
87 function To_Timeval (D : Duration) return struct_timeval is
88 S : time_t;
89 F : Duration;
90 begin
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
95 -- value.
97 if F < 0.0 then
98 S := S - 1;
99 F := F + 1.0;
100 end if;
102 return struct_timeval' (tv_sec => S,
103 tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
104 end To_Timeval;
106 ---------------------------
107 -- POSIX.1c Section 3 --
108 ---------------------------
110 function sigwait
111 (set : access sigset_t;
112 sig : access Signal)
113 return int
115 Result : int;
117 begin
118 Result := sigwait (set);
120 if Result = -1 then
121 sig.all := 0;
122 return errno;
123 end if;
125 sig.all := Signal (Result);
126 return 0;
127 end sigwait;
129 -- DCE_THREADS does not have pthread_kill. Instead, we just ignore it.
131 function pthread_kill (thread : pthread_t; sig : Signal) return int is
132 begin
133 return 0;
134 end pthread_kill;
136 ----------------------------
137 -- POSIX.1c Section 11 --
138 ----------------------------
140 -- For all the following functions, DCE Threads has a non standard
141 -- behavior: it sets errno but the standard Posix requires it to be
142 -- returned.
144 function pthread_mutexattr_init
145 (attr : access pthread_mutexattr_t)
146 return int
148 function pthread_mutexattr_create
149 (attr : access pthread_mutexattr_t)
150 return int;
151 pragma Import (C, pthread_mutexattr_create, "pthread_mutexattr_create");
153 begin
154 if pthread_mutexattr_create (attr) /= 0 then
155 return errno;
156 else
157 return 0;
158 end if;
159 end pthread_mutexattr_init;
161 function pthread_mutexattr_destroy
162 (attr : access pthread_mutexattr_t)
163 return int
165 function pthread_mutexattr_delete
166 (attr : access pthread_mutexattr_t)
167 return int;
168 pragma Import (C, pthread_mutexattr_delete, "pthread_mutexattr_delete");
170 begin
171 if pthread_mutexattr_delete (attr) /= 0 then
172 return errno;
173 else
174 return 0;
175 end if;
176 end pthread_mutexattr_destroy;
178 function pthread_mutex_init
179 (mutex : access pthread_mutex_t;
180 attr : access pthread_mutexattr_t)
181 return int
183 function pthread_mutex_init_base
184 (mutex : access pthread_mutex_t;
185 attr : pthread_mutexattr_t)
186 return int;
187 pragma Import (C, pthread_mutex_init_base, "pthread_mutex_init");
189 begin
190 if pthread_mutex_init_base (mutex, attr.all) /= 0 then
191 return errno;
192 else
193 return 0;
194 end if;
195 end pthread_mutex_init;
197 function pthread_mutex_destroy
198 (mutex : access pthread_mutex_t)
199 return int
201 function pthread_mutex_destroy_base
202 (mutex : access pthread_mutex_t)
203 return int;
204 pragma Import (C, pthread_mutex_destroy_base, "pthread_mutex_destroy");
206 begin
207 if pthread_mutex_destroy_base (mutex) /= 0 then
208 return errno;
209 else
210 return 0;
211 end if;
212 end pthread_mutex_destroy;
214 function pthread_mutex_lock
215 (mutex : access pthread_mutex_t)
216 return int
218 function pthread_mutex_lock_base
219 (mutex : access pthread_mutex_t)
220 return int;
221 pragma Import (C, pthread_mutex_lock_base, "pthread_mutex_lock");
223 begin
224 if pthread_mutex_lock_base (mutex) /= 0 then
225 return errno;
226 else
227 return 0;
228 end if;
229 end pthread_mutex_lock;
231 function pthread_mutex_unlock
232 (mutex : access pthread_mutex_t)
233 return int
235 function pthread_mutex_unlock_base
236 (mutex : access pthread_mutex_t)
237 return int;
238 pragma Import (C, pthread_mutex_unlock_base, "pthread_mutex_unlock");
240 begin
241 if pthread_mutex_unlock_base (mutex) /= 0 then
242 return errno;
243 else
244 return 0;
245 end if;
246 end pthread_mutex_unlock;
248 function pthread_condattr_init
249 (attr : access pthread_condattr_t)
250 return int
252 function pthread_condattr_create
253 (attr : access pthread_condattr_t)
254 return int;
255 pragma Import (C, pthread_condattr_create, "pthread_condattr_create");
257 begin
258 if pthread_condattr_create (attr) /= 0 then
259 return errno;
260 else
261 return 0;
262 end if;
263 end pthread_condattr_init;
265 function pthread_condattr_destroy
266 (attr : access pthread_condattr_t)
267 return int
269 function pthread_condattr_delete
270 (attr : access pthread_condattr_t)
271 return int;
272 pragma Import (C, pthread_condattr_delete, "pthread_condattr_delete");
274 begin
275 if pthread_condattr_delete (attr) /= 0 then
276 return errno;
277 else
278 return 0;
279 end if;
280 end pthread_condattr_destroy;
282 function pthread_cond_init
283 (cond : access pthread_cond_t;
284 attr : access pthread_condattr_t)
285 return int
287 function pthread_cond_init_base
288 (cond : access pthread_cond_t;
289 attr : pthread_condattr_t)
290 return int;
291 pragma Import (C, pthread_cond_init_base, "pthread_cond_init");
293 begin
294 if pthread_cond_init_base (cond, attr.all) /= 0 then
295 return errno;
296 else
297 return 0;
298 end if;
299 end pthread_cond_init;
301 function pthread_cond_destroy
302 (cond : access pthread_cond_t)
303 return int
305 function pthread_cond_destroy_base
306 (cond : access pthread_cond_t)
307 return int;
308 pragma Import (C, pthread_cond_destroy_base, "pthread_cond_destroy");
310 begin
311 if pthread_cond_destroy_base (cond) /= 0 then
312 return errno;
313 else
314 return 0;
315 end if;
316 end pthread_cond_destroy;
318 function pthread_cond_signal
319 (cond : access pthread_cond_t)
320 return int
322 function pthread_cond_signal_base
323 (cond : access pthread_cond_t)
324 return int;
325 pragma Import (C, pthread_cond_signal_base, "pthread_cond_signal");
327 begin
328 if pthread_cond_signal_base (cond) /= 0 then
329 return errno;
330 else
331 return 0;
332 end if;
333 end pthread_cond_signal;
335 function pthread_cond_wait
336 (cond : access pthread_cond_t;
337 mutex : access pthread_mutex_t)
338 return int
340 function pthread_cond_wait_base
341 (cond : access pthread_cond_t;
342 mutex : access pthread_mutex_t)
343 return int;
344 pragma Import (C, pthread_cond_wait_base, "pthread_cond_wait");
346 begin
347 if pthread_cond_wait_base (cond, mutex) /= 0 then
348 return errno;
349 else
350 return 0;
351 end if;
352 end pthread_cond_wait;
354 function pthread_cond_timedwait
355 (cond : access pthread_cond_t;
356 mutex : access pthread_mutex_t;
357 abstime : access timespec)
358 return int
360 function pthread_cond_timedwait_base
361 (cond : access pthread_cond_t;
362 mutex : access pthread_mutex_t;
363 abstime : access timespec)
364 return int;
365 pragma Import (C, pthread_cond_timedwait_base, "pthread_cond_timedwait");
367 begin
368 if pthread_cond_timedwait_base (cond, mutex, abstime) /= 0 then
369 if errno = EAGAIN then
370 return ETIMEDOUT;
371 else
372 return errno;
373 end if;
374 else
375 return 0;
376 end if;
377 end pthread_cond_timedwait;
379 ----------------------------
380 -- POSIX.1c Section 13 --
381 ----------------------------
383 function pthread_setschedparam
384 (thread : pthread_t;
385 policy : int;
386 param : access struct_sched_param) return int
388 function pthread_setscheduler
389 (thread : pthread_t;
390 policy : int;
391 priority : int)
392 return int;
393 pragma Import (C, pthread_setscheduler, "pthread_setscheduler");
395 begin
396 if pthread_setscheduler (thread, policy, param.sched_priority) = -1 then
397 return errno;
398 else
399 return 0;
400 end if;
401 end pthread_setschedparam;
403 function sched_yield return int is
404 procedure pthread_yield;
405 pragma Import (C, pthread_yield, "pthread_yield");
406 begin
407 pthread_yield;
408 return 0;
409 end sched_yield;
411 -----------------------------
412 -- P1003.1c - Section 16 --
413 -----------------------------
415 function pthread_attr_init (attributes : access pthread_attr_t) return int
417 function pthread_attr_create
418 (attributes : access pthread_attr_t)
419 return int;
420 pragma Import (C, pthread_attr_create, "pthread_attr_create");
422 begin
423 if pthread_attr_create (attributes) /= 0 then
424 return errno;
425 else
426 return 0;
427 end if;
428 end pthread_attr_init;
430 function pthread_attr_destroy
431 (attributes : access pthread_attr_t) return int
433 function pthread_attr_delete
434 (attributes : access pthread_attr_t)
435 return int;
436 pragma Import (C, pthread_attr_delete, "pthread_attr_delete");
438 begin
439 if pthread_attr_delete (attributes) /= 0 then
440 return errno;
441 else
442 return 0;
443 end if;
444 end pthread_attr_destroy;
446 function pthread_attr_setstacksize
447 (attr : access pthread_attr_t;
448 stacksize : size_t) return int
450 function pthread_attr_setstacksize_base
451 (attr : access pthread_attr_t;
452 stacksize : size_t)
453 return int;
454 pragma Import (C, pthread_attr_setstacksize_base,
455 "pthread_attr_setstacksize");
457 begin
458 if pthread_attr_setstacksize_base (attr, stacksize) /= 0 then
459 return errno;
460 else
461 return 0;
462 end if;
463 end pthread_attr_setstacksize;
465 function pthread_create
466 (thread : access pthread_t;
467 attributes : access pthread_attr_t;
468 start_routine : Thread_Body;
469 arg : System.Address) return int
471 function pthread_create_base
472 (thread : access pthread_t;
473 attributes : pthread_attr_t;
474 start_routine : Thread_Body;
475 arg : System.Address)
476 return int;
477 pragma Import (C, pthread_create_base, "pthread_create");
479 begin
480 if pthread_create_base
481 (thread, attributes.all, start_routine, arg) /= 0
482 then
483 return errno;
484 else
485 return 0;
486 end if;
487 end pthread_create;
489 ----------------------------
490 -- POSIX.1c Section 17 --
491 ----------------------------
493 function pthread_setspecific
494 (key : pthread_key_t;
495 value : System.Address) return int
497 function pthread_setspecific_base
498 (key : pthread_key_t;
499 value : System.Address) return int;
500 pragma Import (C, pthread_setspecific_base, "pthread_setspecific");
502 begin
503 if pthread_setspecific_base (key, value) /= 0 then
504 return errno;
505 else
506 return 0;
507 end if;
508 end pthread_setspecific;
510 function pthread_getspecific (key : pthread_key_t) return System.Address is
511 function pthread_getspecific_base
512 (key : pthread_key_t;
513 value : access System.Address) return int;
514 pragma Import (C, pthread_getspecific_base, "pthread_getspecific");
515 Addr : aliased System.Address;
517 begin
518 if pthread_getspecific_base (key, Addr'Access) /= 0 then
519 return System.Null_Address;
520 else
521 return Addr;
522 end if;
523 end pthread_getspecific;
525 function pthread_key_create
526 (key : access pthread_key_t;
527 destructor : destructor_pointer) return int
529 function pthread_keycreate
530 (key : access pthread_key_t;
531 destructor : destructor_pointer) return int;
532 pragma Import (C, pthread_keycreate, "pthread_keycreate");
534 begin
535 if pthread_keycreate (key, destructor) /= 0 then
536 return errno;
537 else
538 return 0;
539 end if;
540 end pthread_key_create;
542 function Get_Stack_Base (thread : pthread_t) return Address is
543 begin
544 return Null_Address;
545 end Get_Stack_Base;
547 procedure pthread_init is
548 begin
549 null;
550 end pthread_init;
552 function intr_attach (sig : int; handler : isr_address) return long is
553 function c_signal (sig : int; handler : isr_address) return long;
554 pragma Import (C, c_signal, "signal");
556 begin
557 return c_signal (sig, handler);
558 end intr_attach;
560 end System.OS_Interface;