Daily bump.
[official-gcc.git] / gcc / ada / 52osinte.adb
blobeeab87d69502ac4298a2519c24551e3c907e6c3b
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 -- $Revision: 1.1 $
10 -- --
11 -- Copyright (C) 1999-2000 Free Software Foundation, Inc. --
12 -- --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNARL was developed by the GNARL team at Florida State University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is a LynxOS (Native) version of this package
38 pragma Polling (Off);
39 -- Turn off polling, we do not want ATC polling to take place during
40 -- tasking operations. It causes infinite loops and other problems.
42 with Interfaces.C;
44 package body System.OS_Interface is
46 use Interfaces.C;
48 -------------------
49 -- clock_gettime --
50 -------------------
52 function clock_gettime
53 (clock_id : clockid_t;
54 tp : access timespec)
55 return int
57 function clock_gettime_base
58 (clock_id : clockid_t;
59 tp : access timespec)
60 return int;
61 pragma Import (C, clock_gettime_base, "clock_gettime");
63 begin
64 if clock_gettime_base (clock_id, tp) /= 0 then
65 return errno;
66 end if;
68 return 0;
69 end clock_gettime;
71 -----------------
72 -- To_Duration --
73 -----------------
75 function To_Duration (TS : timespec) return Duration is
76 begin
77 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
78 end To_Duration;
80 function To_Duration (TV : struct_timeval) return Duration is
81 begin
82 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
83 end To_Duration;
85 -----------------
86 -- To_Timespec --
87 -----------------
89 function To_Timespec (D : Duration) return timespec is
90 S : time_t;
91 F : Duration;
93 begin
94 S := time_t (Long_Long_Integer (D));
95 F := D - Duration (S);
97 -- If F has negative value due to a round-up, adjust for positive F
98 -- value.
100 if F < 0.0 then
101 S := S - 1;
102 F := F + 1.0;
103 end if;
105 return timespec' (tv_sec => S,
106 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
107 end To_Timespec;
109 ----------------
110 -- To_Timeval --
111 ----------------
113 function To_Timeval (D : Duration) return struct_timeval is
114 S : time_t;
115 F : Duration;
117 begin
118 S := time_t (Long_Long_Integer (D));
119 F := D - Duration (S);
121 -- If F has negative value due to a round-up, adjust for positive F
122 -- value.
124 if F < 0.0 then
125 S := S - 1;
126 F := F + 1.0;
127 end if;
129 return struct_timeval' (tv_sec => S,
130 tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
131 end To_Timeval;
133 -------------------------
134 -- POSIX.1c Section 3 --
135 -------------------------
137 function sigwait
138 (set : access sigset_t;
139 sig : access Signal)
140 return int
142 function sigwait_base
143 (set : access sigset_t;
144 value : System.Address)
145 return Signal;
146 pragma Import (C, sigwait_base, "sigwait");
148 begin
149 sig.all := sigwait_base (set, Null_Address);
151 if sig.all = -1 then
152 return errno;
153 end if;
155 return 0;
156 end sigwait;
158 --------------------------
159 -- POSIX.1c Section 11 --
160 --------------------------
162 -- For all the following functions, LynxOS threads has the POSIX Draft 4
163 -- begavior; it sets errno but the standard Posix requires it to be
164 -- returned.
166 function pthread_mutexattr_init
167 (attr : access pthread_mutexattr_t)
168 return int
170 function pthread_mutexattr_create
171 (attr : access pthread_mutexattr_t)
172 return int;
173 pragma Import (C, pthread_mutexattr_create, "pthread_mutexattr_create");
175 begin
176 if pthread_mutexattr_create (attr) /= 0 then
177 return errno;
178 end if;
180 return 0;
181 end pthread_mutexattr_init;
183 function pthread_mutexattr_destroy
184 (attr : access pthread_mutexattr_t)
185 return int
187 function pthread_mutexattr_delete
188 (attr : access pthread_mutexattr_t)
189 return int;
190 pragma Import (C, pthread_mutexattr_delete, "pthread_mutexattr_delete");
192 begin
193 if pthread_mutexattr_delete (attr) /= 0 then
194 return errno;
195 end if;
197 return 0;
198 end pthread_mutexattr_destroy;
200 function pthread_mutex_init
201 (mutex : access pthread_mutex_t;
202 attr : access pthread_mutexattr_t)
203 return int
205 function pthread_mutex_init_base
206 (mutex : access pthread_mutex_t;
207 attr : pthread_mutexattr_t)
208 return int;
209 pragma Import (C, pthread_mutex_init_base, "pthread_mutex_init");
211 begin
212 if pthread_mutex_init_base (mutex, attr.all) /= 0 then
213 return errno;
214 end if;
216 return 0;
217 end pthread_mutex_init;
219 function pthread_mutex_destroy
220 (mutex : access pthread_mutex_t)
221 return int
223 function pthread_mutex_destroy_base
224 (mutex : access pthread_mutex_t)
225 return int;
226 pragma Import (C, pthread_mutex_destroy_base, "pthread_mutex_destroy");
228 begin
229 if pthread_mutex_destroy_base (mutex) /= 0 then
230 return errno;
231 end if;
233 return 0;
234 end pthread_mutex_destroy;
236 function pthread_mutex_lock
237 (mutex : access pthread_mutex_t)
238 return int
240 function pthread_mutex_lock_base
241 (mutex : access pthread_mutex_t)
242 return int;
243 pragma Import (C, pthread_mutex_lock_base, "pthread_mutex_lock");
245 begin
246 if pthread_mutex_lock_base (mutex) /= 0 then
247 return errno;
248 end if;
250 return 0;
251 end pthread_mutex_lock;
253 function pthread_mutex_unlock
254 (mutex : access pthread_mutex_t)
255 return int
257 function pthread_mutex_unlock_base
258 (mutex : access pthread_mutex_t)
259 return int;
260 pragma Import (C, pthread_mutex_unlock_base, "pthread_mutex_unlock");
262 begin
263 if pthread_mutex_unlock_base (mutex) /= 0 then
264 return errno;
265 end if;
267 return 0;
268 end pthread_mutex_unlock;
270 function pthread_condattr_init
271 (attr : access pthread_condattr_t)
272 return int
274 function pthread_condattr_create
275 (attr : access pthread_condattr_t)
276 return int;
277 pragma Import (C, pthread_condattr_create, "pthread_condattr_create");
279 begin
280 if pthread_condattr_create (attr) /= 0 then
281 return errno;
282 end if;
284 return 0;
285 end pthread_condattr_init;
287 function pthread_condattr_destroy
288 (attr : access pthread_condattr_t)
289 return int
291 function pthread_condattr_delete
292 (attr : access pthread_condattr_t)
293 return int;
294 pragma Import (C, pthread_condattr_delete, "pthread_condattr_delete");
296 begin
297 if pthread_condattr_delete (attr) /= 0 then
298 return errno;
299 end if;
301 return 0;
302 end pthread_condattr_destroy;
304 function pthread_cond_init
305 (cond : access pthread_cond_t;
306 attr : access pthread_condattr_t)
307 return int
309 function pthread_cond_init_base
310 (cond : access pthread_cond_t;
311 attr : pthread_condattr_t)
312 return int;
313 pragma Import (C, pthread_cond_init_base, "pthread_cond_init");
315 begin
316 if pthread_cond_init_base (cond, attr.all) /= 0 then
317 return errno;
318 end if;
320 return 0;
321 end pthread_cond_init;
323 function pthread_cond_destroy
324 (cond : access pthread_cond_t)
325 return int
327 function pthread_cond_destroy_base
328 (cond : access pthread_cond_t)
329 return int;
330 pragma Import (C, pthread_cond_destroy_base, "pthread_cond_destroy");
332 begin
333 if pthread_cond_destroy_base (cond) /= 0 then
334 return errno;
335 end if;
337 return 0;
338 end pthread_cond_destroy;
340 function pthread_cond_signal
341 (cond : access pthread_cond_t)
342 return int
344 function pthread_cond_signal_base
345 (cond : access pthread_cond_t)
346 return int;
347 pragma Import (C, pthread_cond_signal_base, "pthread_cond_signal");
349 begin
350 if pthread_cond_signal_base (cond) /= 0 then
351 return errno;
352 end if;
354 return 0;
355 end pthread_cond_signal;
357 function pthread_cond_wait
358 (cond : access pthread_cond_t;
359 mutex : access pthread_mutex_t)
360 return int
362 function pthread_cond_wait_base
363 (cond : access pthread_cond_t;
364 mutex : access pthread_mutex_t)
365 return int;
366 pragma Import (C, pthread_cond_wait_base, "pthread_cond_wait");
368 begin
369 if pthread_cond_wait_base (cond, mutex) /= 0 then
370 return errno;
371 end if;
373 return 0;
374 end pthread_cond_wait;
376 function pthread_cond_timedwait
377 (cond : access pthread_cond_t;
378 mutex : access pthread_mutex_t;
379 reltime : access timespec) return int
381 function pthread_cond_timedwait_base
382 (cond : access pthread_cond_t;
383 mutex : access pthread_mutex_t;
384 reltime : access timespec) return int;
385 pragma Import (C, pthread_cond_timedwait_base, "pthread_cond_timedwait");
387 begin
388 if pthread_cond_timedwait_base (cond, mutex, reltime) /= 0 then
389 if errno = EAGAIN then
390 return ETIMEDOUT;
391 end if;
393 return errno;
394 end if;
396 return 0;
397 end pthread_cond_timedwait;
399 --------------------------
400 -- POSIX.1c Section 13 --
401 --------------------------
403 function pthread_setschedparam
404 (thread : pthread_t;
405 policy : int;
406 param : access struct_sched_param)
407 return int
409 function pthread_setscheduler
410 (thread : pthread_t;
411 policy : int;
412 prio : int)
413 return int;
414 pragma Import (C, pthread_setscheduler, "pthread_setscheduler");
416 begin
417 if pthread_setscheduler (thread, policy, param.sched_priority) = -1 then
418 return errno;
419 end if;
421 return 0;
422 end pthread_setschedparam;
424 function pthread_mutexattr_setprotocol
425 (attr : access pthread_mutexattr_t;
426 protocol : int)
427 return int
429 begin
430 return 0;
431 end pthread_mutexattr_setprotocol;
433 function pthread_mutexattr_setprioceiling
434 (attr : access pthread_mutexattr_t;
435 prioceiling : int)
436 return int
438 begin
439 return 0;
440 end pthread_mutexattr_setprioceiling;
442 function pthread_attr_setscope
443 (attr : access pthread_attr_t;
444 contentionscope : int)
445 return int
447 begin
448 return 0;
449 end pthread_attr_setscope;
451 function sched_yield return int is
452 procedure pthread_yield;
453 pragma Import (C, pthread_yield, "pthread_yield");
455 begin
456 pthread_yield;
457 return 0;
458 end sched_yield;
460 -----------------------------
461 -- P1003.1c - Section 16 --
462 -----------------------------
464 function pthread_attr_setdetachstate
465 (attr : access pthread_attr_t;
466 detachstate : int)
467 return int
469 begin
470 return 0;
471 end pthread_attr_setdetachstate;
473 function pthread_create
474 (thread : access pthread_t;
475 attributes : access pthread_attr_t;
476 start_routine : Thread_Body;
477 arg : System.Address)
478 return int
480 -- The LynxOS pthread_create doesn't seems to work.
481 -- Workaround : We're using st_new instead.
483 -- function pthread_create_base
484 -- (thread : access pthread_t;
485 -- attributes : pthread_attr_t;
486 -- start_routine : Thread_Body;
487 -- arg : System.Address)
488 -- return int;
489 -- pragma Import (C, pthread_create_base, "pthread_create");
491 St : aliased st_t := attributes.st;
493 function st_new
494 (start_routine : Thread_Body;
495 arg : System.Address;
496 attributes : access st_t;
497 thread : access pthread_t)
498 return int;
499 pragma Import (C, st_new, "st_new");
501 begin
502 -- Following code would be used if above commented function worked
504 -- if pthread_create_base
505 -- (thread, attributes.all, start_routine, arg) /= 0 then
507 if st_new (start_routine, arg, St'Access, thread) /= 0 then
508 return errno;
509 end if;
511 return 0;
512 end pthread_create;
514 function pthread_detach (thread : pthread_t) return int is
515 aliased_thread : aliased pthread_t := thread;
517 function pthread_detach_base (thread : access pthread_t) return int;
518 pragma Import (C, pthread_detach_base, "pthread_detach");
520 begin
521 if pthread_detach_base (aliased_thread'Access) /= 0 then
522 return errno;
523 end if;
525 return 0;
526 end pthread_detach;
528 --------------------------
529 -- POSIX.1c Section 17 --
530 --------------------------
532 function pthread_setspecific
533 (key : pthread_key_t;
534 value : System.Address)
535 return int
537 function pthread_setspecific_base
538 (key : pthread_key_t;
539 value : System.Address)
540 return int;
541 pragma Import (C, pthread_setspecific_base, "pthread_setspecific");
543 begin
544 if pthread_setspecific_base (key, value) /= 0 then
545 return errno;
546 end if;
548 return 0;
549 end pthread_setspecific;
551 function pthread_getspecific (key : pthread_key_t) return System.Address is
552 procedure pthread_getspecific_base
553 (key : pthread_key_t;
554 value : access System.Address);
555 pragma Import (C, pthread_getspecific_base, "pthread_getspecific");
557 value : aliased System.Address := System.Null_Address;
559 begin
560 pthread_getspecific_base (key, value'Unchecked_Access);
561 return value;
562 end pthread_getspecific;
564 function Get_Stack_Base (thread : pthread_t) return Address is
565 begin
566 return Null_Address;
567 end Get_Stack_Base;
569 function pthread_key_create
570 (key : access pthread_key_t;
571 destructor : destructor_pointer)
572 return int
574 function pthread_keycreate
575 (key : access pthread_key_t;
576 destructor : destructor_pointer)
577 return int;
578 pragma Import (C, pthread_keycreate, "pthread_keycreate");
580 begin
581 if pthread_keycreate (key, destructor) /= 0 then
582 return errno;
583 end if;
585 return 0;
586 end pthread_key_create;
588 procedure pthread_init is
589 begin
590 null;
591 end pthread_init;
593 end System.OS_Interface;