1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
10 -- Copyright (C) 1999-2000 Free Software Foundation, Inc. --
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. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 -- This is a LynxOS (Native) version of this package
38 -- Turn off polling, we do not want ATC polling to take place during
39 -- tasking operations. It causes infinite loops and other problems.
43 package body System
.OS_Interface
is
51 function clock_gettime
52 (clock_id
: clockid_t
;
56 function clock_gettime_base
57 (clock_id
: clockid_t
;
60 pragma Import
(C
, clock_gettime_base
, "clock_gettime");
63 if clock_gettime_base
(clock_id
, tp
) /= 0 then
74 function To_Duration
(TS
: timespec
) return Duration is
76 return Duration (TS
.tv_sec
) + Duration (TS
.tv_nsec
) / 10#
1#E9
;
79 function To_Duration
(TV
: struct_timeval
) return Duration is
81 return Duration (TV
.tv_sec
) + Duration (TV
.tv_usec
) / 10#
1#E6
;
88 function To_Timespec
(D
: Duration) return timespec
is
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
104 return timespec
' (tv_sec => S,
105 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
112 function To_Timeval (D : Duration) return struct_timeval is
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
128 return struct_timeval' (tv_sec
=> S
,
129 tv_usec
=> time_t
(Long_Long_Integer (F
* 10#
1#E6
)));
132 -------------------------
133 -- POSIX.1c Section 3 --
134 -------------------------
137 (set
: access sigset_t
;
141 function sigwait_base
142 (set
: access sigset_t
;
143 value
: System
.Address
)
145 pragma Import
(C
, sigwait_base
, "sigwait");
148 sig
.all := sigwait_base
(set
, Null_Address
);
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
165 function pthread_mutexattr_init
166 (attr
: access pthread_mutexattr_t
)
169 function pthread_mutexattr_create
170 (attr
: access pthread_mutexattr_t
)
172 pragma Import
(C
, pthread_mutexattr_create
, "pthread_mutexattr_create");
175 if pthread_mutexattr_create
(attr
) /= 0 then
180 end pthread_mutexattr_init
;
182 function pthread_mutexattr_destroy
183 (attr
: access pthread_mutexattr_t
)
186 function pthread_mutexattr_delete
187 (attr
: access pthread_mutexattr_t
)
189 pragma Import
(C
, pthread_mutexattr_delete
, "pthread_mutexattr_delete");
192 if pthread_mutexattr_delete
(attr
) /= 0 then
197 end pthread_mutexattr_destroy
;
199 function pthread_mutex_init
200 (mutex
: access pthread_mutex_t
;
201 attr
: access pthread_mutexattr_t
)
204 function pthread_mutex_init_base
205 (mutex
: access pthread_mutex_t
;
206 attr
: pthread_mutexattr_t
)
208 pragma Import
(C
, pthread_mutex_init_base
, "pthread_mutex_init");
211 if pthread_mutex_init_base
(mutex
, attr
.all) /= 0 then
216 end pthread_mutex_init
;
218 function pthread_mutex_destroy
219 (mutex
: access pthread_mutex_t
)
222 function pthread_mutex_destroy_base
223 (mutex
: access pthread_mutex_t
)
225 pragma Import
(C
, pthread_mutex_destroy_base
, "pthread_mutex_destroy");
228 if pthread_mutex_destroy_base
(mutex
) /= 0 then
233 end pthread_mutex_destroy
;
235 function pthread_mutex_lock
236 (mutex
: access pthread_mutex_t
)
239 function pthread_mutex_lock_base
240 (mutex
: access pthread_mutex_t
)
242 pragma Import
(C
, pthread_mutex_lock_base
, "pthread_mutex_lock");
245 if pthread_mutex_lock_base
(mutex
) /= 0 then
250 end pthread_mutex_lock
;
252 function pthread_mutex_unlock
253 (mutex
: access pthread_mutex_t
)
256 function pthread_mutex_unlock_base
257 (mutex
: access pthread_mutex_t
)
259 pragma Import
(C
, pthread_mutex_unlock_base
, "pthread_mutex_unlock");
262 if pthread_mutex_unlock_base
(mutex
) /= 0 then
267 end pthread_mutex_unlock
;
269 function pthread_condattr_init
270 (attr
: access pthread_condattr_t
)
273 function pthread_condattr_create
274 (attr
: access pthread_condattr_t
)
276 pragma Import
(C
, pthread_condattr_create
, "pthread_condattr_create");
279 if pthread_condattr_create
(attr
) /= 0 then
284 end pthread_condattr_init
;
286 function pthread_condattr_destroy
287 (attr
: access pthread_condattr_t
)
290 function pthread_condattr_delete
291 (attr
: access pthread_condattr_t
)
293 pragma Import
(C
, pthread_condattr_delete
, "pthread_condattr_delete");
296 if pthread_condattr_delete
(attr
) /= 0 then
301 end pthread_condattr_destroy
;
303 function pthread_cond_init
304 (cond
: access pthread_cond_t
;
305 attr
: access pthread_condattr_t
)
308 function pthread_cond_init_base
309 (cond
: access pthread_cond_t
;
310 attr
: pthread_condattr_t
)
312 pragma Import
(C
, pthread_cond_init_base
, "pthread_cond_init");
315 if pthread_cond_init_base
(cond
, attr
.all) /= 0 then
320 end pthread_cond_init
;
322 function pthread_cond_destroy
323 (cond
: access pthread_cond_t
)
326 function pthread_cond_destroy_base
327 (cond
: access pthread_cond_t
)
329 pragma Import
(C
, pthread_cond_destroy_base
, "pthread_cond_destroy");
332 if pthread_cond_destroy_base
(cond
) /= 0 then
337 end pthread_cond_destroy
;
339 function pthread_cond_signal
340 (cond
: access pthread_cond_t
)
343 function pthread_cond_signal_base
344 (cond
: access pthread_cond_t
)
346 pragma Import
(C
, pthread_cond_signal_base
, "pthread_cond_signal");
349 if pthread_cond_signal_base
(cond
) /= 0 then
354 end pthread_cond_signal
;
356 function pthread_cond_wait
357 (cond
: access pthread_cond_t
;
358 mutex
: access pthread_mutex_t
)
361 function pthread_cond_wait_base
362 (cond
: access pthread_cond_t
;
363 mutex
: access pthread_mutex_t
)
365 pragma Import
(C
, pthread_cond_wait_base
, "pthread_cond_wait");
368 if pthread_cond_wait_base
(cond
, mutex
) /= 0 then
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");
387 if pthread_cond_timedwait_base
(cond
, mutex
, reltime
) /= 0 then
388 if errno
= EAGAIN
then
396 end pthread_cond_timedwait
;
398 --------------------------
399 -- POSIX.1c Section 13 --
400 --------------------------
402 function pthread_setschedparam
405 param
: access struct_sched_param
)
408 function pthread_setscheduler
413 pragma Import
(C
, pthread_setscheduler
, "pthread_setscheduler");
416 if pthread_setscheduler
(thread
, policy
, param
.sched_priority
) = -1 then
421 end pthread_setschedparam
;
423 function pthread_mutexattr_setprotocol
424 (attr
: access pthread_mutexattr_t
;
430 end pthread_mutexattr_setprotocol
;
432 function pthread_mutexattr_setprioceiling
433 (attr
: access pthread_mutexattr_t
;
439 end pthread_mutexattr_setprioceiling
;
441 function pthread_attr_setscope
442 (attr
: access pthread_attr_t
;
443 contentionscope
: int
)
448 end pthread_attr_setscope
;
450 function sched_yield
return int
is
451 procedure pthread_yield
;
452 pragma Import
(C
, pthread_yield
, "pthread_yield");
459 -----------------------------
460 -- P1003.1c - Section 16 --
461 -----------------------------
463 function pthread_attr_setdetachstate
464 (attr
: access pthread_attr_t
;
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
)
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)
488 -- pragma Import (C, pthread_create_base, "pthread_create");
490 St
: aliased st_t
:= attributes
.st
;
493 (start_routine
: Thread_Body
;
494 arg
: System
.Address
;
495 attributes
: access st_t
;
496 thread
: access pthread_t
)
498 pragma Import
(C
, st_new
, "st_new");
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
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");
520 if pthread_detach_base
(aliased_thread
'Access) /= 0 then
527 --------------------------
528 -- POSIX.1c Section 17 --
529 --------------------------
531 function pthread_setspecific
532 (key
: pthread_key_t
;
533 value
: System
.Address
)
536 function pthread_setspecific_base
537 (key
: pthread_key_t
;
538 value
: System
.Address
)
540 pragma Import
(C
, pthread_setspecific_base
, "pthread_setspecific");
543 if pthread_setspecific_base
(key
, value
) /= 0 then
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
;
559 pthread_getspecific_base
(key
, value
'Unchecked_Access);
561 end pthread_getspecific
;
563 function Get_Stack_Base
(thread
: pthread_t
) return Address
is
568 function pthread_key_create
569 (key
: access pthread_key_t
;
570 destructor
: destructor_pointer
)
573 function pthread_keycreate
574 (key
: access pthread_key_t
;
575 destructor
: destructor_pointer
)
577 pragma Import
(C
, pthread_keycreate
, "pthread_keycreate");
580 if pthread_keycreate
(key
, destructor
) /= 0 then
585 end pthread_key_create
;
587 procedure pthread_init
is
592 end System
.OS_Interface
;