FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / 52osinte.adb
blob02c438590cbb1bb0136e4a8ddca5d3c8397d9f03
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) 1999-2000 Free Software Foundation, Inc. --
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. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This is a LynxOS (Native) version of this package
37 pragma Polling (Off);
38 -- Turn off polling, we do not want ATC polling to take place during
39 -- tasking operations. It causes infinite loops and other problems.
41 with Interfaces.C;
43 package body System.OS_Interface is
45 use Interfaces.C;
47 -------------------
48 -- clock_gettime --
49 -------------------
51 function clock_gettime
52 (clock_id : clockid_t;
53 tp : access timespec)
54 return int
56 function clock_gettime_base
57 (clock_id : clockid_t;
58 tp : access timespec)
59 return int;
60 pragma Import (C, clock_gettime_base, "clock_gettime");
62 begin
63 if clock_gettime_base (clock_id, tp) /= 0 then
64 return errno;
65 end if;
67 return 0;
68 end clock_gettime;
70 -----------------
71 -- To_Duration --
72 -----------------
74 function To_Duration (TS : timespec) return Duration is
75 begin
76 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
77 end To_Duration;
79 function To_Duration (TV : struct_timeval) return Duration is
80 begin
81 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
82 end To_Duration;
84 -----------------
85 -- To_Timespec --
86 -----------------
88 function To_Timespec (D : Duration) return timespec is
89 S : time_t;
90 F : Duration;
92 begin
93 S := time_t (Long_Long_Integer (D));
94 F := D - Duration (S);
96 -- If F has negative value due to a round-up, adjust for positive F
97 -- value.
99 if F < 0.0 then
100 S := S - 1;
101 F := F + 1.0;
102 end if;
104 return timespec' (tv_sec => S,
105 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
106 end To_Timespec;
108 ----------------
109 -- To_Timeval --
110 ----------------
112 function To_Timeval (D : Duration) return struct_timeval is
113 S : time_t;
114 F : Duration;
116 begin
117 S := time_t (Long_Long_Integer (D));
118 F := D - Duration (S);
120 -- If F has negative value due to a round-up, adjust for positive F
121 -- value.
123 if F < 0.0 then
124 S := S - 1;
125 F := F + 1.0;
126 end if;
128 return struct_timeval' (tv_sec => S,
129 tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
130 end To_Timeval;
132 -------------------------
133 -- POSIX.1c Section 3 --
134 -------------------------
136 function sigwait
137 (set : access sigset_t;
138 sig : access Signal)
139 return int
141 function sigwait_base
142 (set : access sigset_t;
143 value : System.Address)
144 return Signal;
145 pragma Import (C, sigwait_base, "sigwait");
147 begin
148 sig.all := sigwait_base (set, Null_Address);
150 if sig.all = -1 then
151 return errno;
152 end if;
154 return 0;
155 end sigwait;
157 --------------------------
158 -- POSIX.1c Section 11 --
159 --------------------------
161 -- For all the following functions, LynxOS threads has the POSIX Draft 4
162 -- begavior; it sets errno but the standard Posix requires it to be
163 -- returned.
165 function pthread_mutexattr_init
166 (attr : access pthread_mutexattr_t)
167 return int
169 function pthread_mutexattr_create
170 (attr : access pthread_mutexattr_t)
171 return int;
172 pragma Import (C, pthread_mutexattr_create, "pthread_mutexattr_create");
174 begin
175 if pthread_mutexattr_create (attr) /= 0 then
176 return errno;
177 end if;
179 return 0;
180 end pthread_mutexattr_init;
182 function pthread_mutexattr_destroy
183 (attr : access pthread_mutexattr_t)
184 return int
186 function pthread_mutexattr_delete
187 (attr : access pthread_mutexattr_t)
188 return int;
189 pragma Import (C, pthread_mutexattr_delete, "pthread_mutexattr_delete");
191 begin
192 if pthread_mutexattr_delete (attr) /= 0 then
193 return errno;
194 end if;
196 return 0;
197 end pthread_mutexattr_destroy;
199 function pthread_mutex_init
200 (mutex : access pthread_mutex_t;
201 attr : access pthread_mutexattr_t)
202 return int
204 function pthread_mutex_init_base
205 (mutex : access pthread_mutex_t;
206 attr : pthread_mutexattr_t)
207 return int;
208 pragma Import (C, pthread_mutex_init_base, "pthread_mutex_init");
210 begin
211 if pthread_mutex_init_base (mutex, attr.all) /= 0 then
212 return errno;
213 end if;
215 return 0;
216 end pthread_mutex_init;
218 function pthread_mutex_destroy
219 (mutex : access pthread_mutex_t)
220 return int
222 function pthread_mutex_destroy_base
223 (mutex : access pthread_mutex_t)
224 return int;
225 pragma Import (C, pthread_mutex_destroy_base, "pthread_mutex_destroy");
227 begin
228 if pthread_mutex_destroy_base (mutex) /= 0 then
229 return errno;
230 end if;
232 return 0;
233 end pthread_mutex_destroy;
235 function pthread_mutex_lock
236 (mutex : access pthread_mutex_t)
237 return int
239 function pthread_mutex_lock_base
240 (mutex : access pthread_mutex_t)
241 return int;
242 pragma Import (C, pthread_mutex_lock_base, "pthread_mutex_lock");
244 begin
245 if pthread_mutex_lock_base (mutex) /= 0 then
246 return errno;
247 end if;
249 return 0;
250 end pthread_mutex_lock;
252 function pthread_mutex_unlock
253 (mutex : access pthread_mutex_t)
254 return int
256 function pthread_mutex_unlock_base
257 (mutex : access pthread_mutex_t)
258 return int;
259 pragma Import (C, pthread_mutex_unlock_base, "pthread_mutex_unlock");
261 begin
262 if pthread_mutex_unlock_base (mutex) /= 0 then
263 return errno;
264 end if;
266 return 0;
267 end pthread_mutex_unlock;
269 function pthread_condattr_init
270 (attr : access pthread_condattr_t)
271 return int
273 function pthread_condattr_create
274 (attr : access pthread_condattr_t)
275 return int;
276 pragma Import (C, pthread_condattr_create, "pthread_condattr_create");
278 begin
279 if pthread_condattr_create (attr) /= 0 then
280 return errno;
281 end if;
283 return 0;
284 end pthread_condattr_init;
286 function pthread_condattr_destroy
287 (attr : access pthread_condattr_t)
288 return int
290 function pthread_condattr_delete
291 (attr : access pthread_condattr_t)
292 return int;
293 pragma Import (C, pthread_condattr_delete, "pthread_condattr_delete");
295 begin
296 if pthread_condattr_delete (attr) /= 0 then
297 return errno;
298 end if;
300 return 0;
301 end pthread_condattr_destroy;
303 function pthread_cond_init
304 (cond : access pthread_cond_t;
305 attr : access pthread_condattr_t)
306 return int
308 function pthread_cond_init_base
309 (cond : access pthread_cond_t;
310 attr : pthread_condattr_t)
311 return int;
312 pragma Import (C, pthread_cond_init_base, "pthread_cond_init");
314 begin
315 if pthread_cond_init_base (cond, attr.all) /= 0 then
316 return errno;
317 end if;
319 return 0;
320 end pthread_cond_init;
322 function pthread_cond_destroy
323 (cond : access pthread_cond_t)
324 return int
326 function pthread_cond_destroy_base
327 (cond : access pthread_cond_t)
328 return int;
329 pragma Import (C, pthread_cond_destroy_base, "pthread_cond_destroy");
331 begin
332 if pthread_cond_destroy_base (cond) /= 0 then
333 return errno;
334 end if;
336 return 0;
337 end pthread_cond_destroy;
339 function pthread_cond_signal
340 (cond : access pthread_cond_t)
341 return int
343 function pthread_cond_signal_base
344 (cond : access pthread_cond_t)
345 return int;
346 pragma Import (C, pthread_cond_signal_base, "pthread_cond_signal");
348 begin
349 if pthread_cond_signal_base (cond) /= 0 then
350 return errno;
351 end if;
353 return 0;
354 end pthread_cond_signal;
356 function pthread_cond_wait
357 (cond : access pthread_cond_t;
358 mutex : access pthread_mutex_t)
359 return int
361 function pthread_cond_wait_base
362 (cond : access pthread_cond_t;
363 mutex : access pthread_mutex_t)
364 return int;
365 pragma Import (C, pthread_cond_wait_base, "pthread_cond_wait");
367 begin
368 if pthread_cond_wait_base (cond, mutex) /= 0 then
369 return errno;
370 end if;
372 return 0;
373 end pthread_cond_wait;
375 function pthread_cond_timedwait
376 (cond : access pthread_cond_t;
377 mutex : access pthread_mutex_t;
378 reltime : access timespec) return int
380 function pthread_cond_timedwait_base
381 (cond : access pthread_cond_t;
382 mutex : access pthread_mutex_t;
383 reltime : access timespec) return int;
384 pragma Import (C, pthread_cond_timedwait_base, "pthread_cond_timedwait");
386 begin
387 if pthread_cond_timedwait_base (cond, mutex, reltime) /= 0 then
388 if errno = EAGAIN then
389 return ETIMEDOUT;
390 end if;
392 return errno;
393 end if;
395 return 0;
396 end pthread_cond_timedwait;
398 --------------------------
399 -- POSIX.1c Section 13 --
400 --------------------------
402 function pthread_setschedparam
403 (thread : pthread_t;
404 policy : int;
405 param : access struct_sched_param)
406 return int
408 function pthread_setscheduler
409 (thread : pthread_t;
410 policy : int;
411 prio : int)
412 return int;
413 pragma Import (C, pthread_setscheduler, "pthread_setscheduler");
415 begin
416 if pthread_setscheduler (thread, policy, param.sched_priority) = -1 then
417 return errno;
418 end if;
420 return 0;
421 end pthread_setschedparam;
423 function pthread_mutexattr_setprotocol
424 (attr : access pthread_mutexattr_t;
425 protocol : int)
426 return int
428 begin
429 return 0;
430 end pthread_mutexattr_setprotocol;
432 function pthread_mutexattr_setprioceiling
433 (attr : access pthread_mutexattr_t;
434 prioceiling : int)
435 return int
437 begin
438 return 0;
439 end pthread_mutexattr_setprioceiling;
441 function pthread_attr_setscope
442 (attr : access pthread_attr_t;
443 contentionscope : int)
444 return int
446 begin
447 return 0;
448 end pthread_attr_setscope;
450 function sched_yield return int is
451 procedure pthread_yield;
452 pragma Import (C, pthread_yield, "pthread_yield");
454 begin
455 pthread_yield;
456 return 0;
457 end sched_yield;
459 -----------------------------
460 -- P1003.1c - Section 16 --
461 -----------------------------
463 function pthread_attr_setdetachstate
464 (attr : access pthread_attr_t;
465 detachstate : int)
466 return int
468 begin
469 return 0;
470 end pthread_attr_setdetachstate;
472 function pthread_create
473 (thread : access pthread_t;
474 attributes : access pthread_attr_t;
475 start_routine : Thread_Body;
476 arg : System.Address)
477 return int
479 -- The LynxOS pthread_create doesn't seems to work.
480 -- Workaround : We're using st_new instead.
482 -- function pthread_create_base
483 -- (thread : access pthread_t;
484 -- attributes : pthread_attr_t;
485 -- start_routine : Thread_Body;
486 -- arg : System.Address)
487 -- return int;
488 -- pragma Import (C, pthread_create_base, "pthread_create");
490 St : aliased st_t := attributes.st;
492 function st_new
493 (start_routine : Thread_Body;
494 arg : System.Address;
495 attributes : access st_t;
496 thread : access pthread_t)
497 return int;
498 pragma Import (C, st_new, "st_new");
500 begin
501 -- Following code would be used if above commented function worked
503 -- if pthread_create_base
504 -- (thread, attributes.all, start_routine, arg) /= 0 then
506 if st_new (start_routine, arg, St'Access, thread) /= 0 then
507 return errno;
508 end if;
510 return 0;
511 end pthread_create;
513 function pthread_detach (thread : pthread_t) return int is
514 aliased_thread : aliased pthread_t := thread;
516 function pthread_detach_base (thread : access pthread_t) return int;
517 pragma Import (C, pthread_detach_base, "pthread_detach");
519 begin
520 if pthread_detach_base (aliased_thread'Access) /= 0 then
521 return errno;
522 end if;
524 return 0;
525 end pthread_detach;
527 --------------------------
528 -- POSIX.1c Section 17 --
529 --------------------------
531 function pthread_setspecific
532 (key : pthread_key_t;
533 value : System.Address)
534 return int
536 function pthread_setspecific_base
537 (key : pthread_key_t;
538 value : System.Address)
539 return int;
540 pragma Import (C, pthread_setspecific_base, "pthread_setspecific");
542 begin
543 if pthread_setspecific_base (key, value) /= 0 then
544 return errno;
545 end if;
547 return 0;
548 end pthread_setspecific;
550 function pthread_getspecific (key : pthread_key_t) return System.Address is
551 procedure pthread_getspecific_base
552 (key : pthread_key_t;
553 value : access System.Address);
554 pragma Import (C, pthread_getspecific_base, "pthread_getspecific");
556 value : aliased System.Address := System.Null_Address;
558 begin
559 pthread_getspecific_base (key, value'Unchecked_Access);
560 return value;
561 end pthread_getspecific;
563 function Get_Stack_Base (thread : pthread_t) return Address is
564 begin
565 return Null_Address;
566 end Get_Stack_Base;
568 function pthread_key_create
569 (key : access pthread_key_t;
570 destructor : destructor_pointer)
571 return int
573 function pthread_keycreate
574 (key : access pthread_key_t;
575 destructor : destructor_pointer)
576 return int;
577 pragma Import (C, pthread_keycreate, "pthread_keycreate");
579 begin
580 if pthread_keycreate (key, destructor) /= 0 then
581 return errno;
582 end if;
584 return 0;
585 end pthread_key_create;
587 procedure pthread_init is
588 begin
589 null;
590 end pthread_init;
592 end System.OS_Interface;