]>
Commit | Line | Data |
---|---|---|
c5b2a8ae AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3084fecd | 3 | -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- |
c5b2a8ae AC |
4 | -- -- |
5 | -- S Y S T E M . O S _ I N T E R F A C E -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
8a7988f5 | 9 | -- Copyright (C) 1991-1994, Florida State University -- |
0b5b2bbc | 10 | -- Copyright (C) 1995-2011, Free Software Foundation, Inc. -- |
c5b2a8ae | 11 | -- -- |
607d0635 | 12 | -- GNAT is free software; you can redistribute it and/or modify it under -- |
c5b2a8ae | 13 | -- terms of the GNU General Public License as published by the Free Soft- -- |
607d0635 AC |
14 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
15 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- | |
c5b2a8ae | 16 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
607d0635 AC |
17 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- |
18 | -- -- | |
19 | -- As a special exception under Section 7 of GPL version 3, you are granted -- | |
20 | -- additional permissions described in the GCC Runtime Library Exception, -- | |
21 | -- version 3.1, as published by the Free Software Foundation. -- | |
22 | -- -- | |
23 | -- You should have received a copy of the GNU General Public License and -- | |
24 | -- a copy of the GCC Runtime Library Exception along with this program; -- | |
25 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- | |
26 | -- <http://www.gnu.org/licenses/>. -- | |
c5b2a8ae AC |
27 | -- -- |
28 | -- GNARL was developed by the GNARL team at Florida State University. It is -- | |
29 | -- now maintained by Ada Core Technologies Inc. in cooperation with Florida -- | |
30 | -- State University (http://www.gnat.com). -- | |
31 | -- -- | |
32 | ------------------------------------------------------------------------------ | |
33 | ||
34 | -- This is the FreeBSD PTHREADS version of this package | |
35 | ||
8a7988f5 | 36 | -- This package encapsulates all direct interfaces to OS services |
366b8af7 | 37 | -- that are needed by the tasking run-time (libgnarl). |
8a7988f5 AC |
38 | |
39 | -- PLEASE DO NOT add any with-clauses to this package or remove the pragma | |
40 | -- Preelaborate. This package is designed to be a bottom-level (leaf) package. | |
41 | ||
dae22b53 | 42 | with Ada.Unchecked_Conversion; |
8a7988f5 | 43 | |
366b8af7 RD |
44 | with Interfaces.C; |
45 | ||
c5b2a8ae AC |
46 | package System.OS_Interface is |
47 | pragma Preelaborate; | |
48 | ||
49 | pragma Linker_Options ("-pthread"); | |
50 | ||
51 | subtype int is Interfaces.C.int; | |
52 | subtype short is Interfaces.C.short; | |
53 | subtype long is Interfaces.C.long; | |
54 | subtype unsigned is Interfaces.C.unsigned; | |
55 | subtype unsigned_short is Interfaces.C.unsigned_short; | |
56 | subtype unsigned_long is Interfaces.C.unsigned_long; | |
57 | subtype unsigned_char is Interfaces.C.unsigned_char; | |
58 | subtype plain_char is Interfaces.C.plain_char; | |
59 | subtype size_t is Interfaces.C.size_t; | |
60 | ||
61 | ----------- | |
62 | -- Errno -- | |
63 | ----------- | |
64 | ||
65 | function Errno return int; | |
66 | pragma Inline (Errno); | |
67 | ||
79a776a8 TQ |
68 | EAGAIN : constant := 35; |
69 | EINTR : constant := 4; | |
70 | EINVAL : constant := 22; | |
71 | ENOMEM : constant := 12; | |
72 | ETIMEDOUT : constant := 60; | |
c5b2a8ae AC |
73 | |
74 | ------------- | |
75 | -- Signals -- | |
76 | ------------- | |
77 | ||
78 | Max_Interrupt : constant := 31; | |
79 | type Signal is new int range 0 .. Max_Interrupt; | |
80 | for Signal'Size use int'Size; | |
81 | ||
82 | SIGHUP : constant := 1; -- hangup | |
83 | SIGINT : constant := 2; -- interrupt (rubout) | |
84 | SIGQUIT : constant := 3; -- quit (ASCD FS) | |
85 | SIGILL : constant := 4; -- illegal instruction (not reset) | |
86 | SIGTRAP : constant := 5; -- trace trap (not reset) | |
87 | SIGIOT : constant := 6; -- IOT instruction | |
88 | SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future | |
89 | SIGEMT : constant := 7; -- EMT instruction | |
90 | SIGFPE : constant := 8; -- floating point exception | |
91 | SIGKILL : constant := 9; -- kill (cannot be caught or ignored) | |
92 | SIGBUS : constant := 10; -- bus error | |
93 | SIGSEGV : constant := 11; -- segmentation violation | |
94 | SIGSYS : constant := 12; -- bad argument to system call | |
95 | SIGPIPE : constant := 13; -- write on a pipe with no one to read it | |
96 | SIGALRM : constant := 14; -- alarm clock | |
97 | SIGTERM : constant := 15; -- software termination signal from kill | |
98 | SIGURG : constant := 16; -- urgent condition on IO channel | |
99 | SIGSTOP : constant := 17; -- stop (cannot be caught or ignored) | |
100 | SIGTSTP : constant := 18; -- user stop requested from tty | |
101 | SIGCONT : constant := 19; -- stopped process has been continued | |
102 | SIGCLD : constant := 20; -- alias for SIGCHLD | |
103 | SIGCHLD : constant := 20; -- child status change | |
104 | SIGTTIN : constant := 21; -- background tty read attempted | |
105 | SIGTTOU : constant := 22; -- background tty write attempted | |
106 | SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias) | |
107 | SIGXCPU : constant := 24; -- CPU time limit exceeded | |
108 | SIGXFSZ : constant := 25; -- filesize limit exceeded | |
109 | SIGVTALRM : constant := 26; -- virtual timer expired | |
110 | SIGPROF : constant := 27; -- profiling timer expired | |
111 | SIGWINCH : constant := 28; -- window size change | |
112 | SIGINFO : constant := 29; -- information request (NetBSD/FreeBSD) | |
113 | SIGUSR1 : constant := 30; -- user defined signal 1 | |
114 | SIGUSR2 : constant := 31; -- user defined signal 2 | |
115 | ||
116 | SIGADAABORT : constant := SIGABRT; | |
117 | -- Change this if you want to use another signal for task abort. | |
118 | -- SIGTERM might be a good one. | |
119 | ||
120 | type Signal_Set is array (Natural range <>) of Signal; | |
121 | ||
122 | -- Interrupts that must be unmasked at all times. FreeBSD | |
123 | -- pthreads will not allow an application to mask out any | |
124 | -- interrupt needed by the threads library. | |
125 | Unmasked : constant Signal_Set := | |
126 | (SIGTRAP, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP); | |
127 | ||
128 | -- FreeBSD will uses SIGPROF for timing. Do not allow a | |
129 | -- handler to attach to this signal. | |
130 | Reserved : constant Signal_Set := (0 .. 0 => SIGPROF); | |
131 | ||
132 | type sigset_t is private; | |
133 | ||
134 | function sigaddset | |
135 | (set : access sigset_t; | |
136 | sig : Signal) return int; | |
137 | pragma Import (C, sigaddset, "sigaddset"); | |
138 | ||
139 | function sigdelset | |
140 | (set : access sigset_t; | |
141 | sig : Signal) return int; | |
142 | pragma Import (C, sigdelset, "sigdelset"); | |
143 | ||
144 | function sigfillset (set : access sigset_t) return int; | |
145 | pragma Import (C, sigfillset, "sigfillset"); | |
146 | ||
147 | function sigismember | |
148 | (set : access sigset_t; | |
149 | sig : Signal) return int; | |
150 | pragma Import (C, sigismember, "sigismember"); | |
151 | ||
152 | function sigemptyset (set : access sigset_t) return int; | |
153 | pragma Import (C, sigemptyset, "sigemptyset"); | |
154 | ||
155 | -- sigcontext is architecture dependent, so define it private | |
156 | type struct_sigcontext is private; | |
157 | ||
158 | type old_struct_sigaction is record | |
159 | sa_handler : System.Address; | |
160 | sa_mask : sigset_t; | |
161 | sa_flags : int; | |
162 | end record; | |
163 | pragma Convention (C, old_struct_sigaction); | |
164 | ||
165 | type new_struct_sigaction is record | |
166 | sa_handler : System.Address; | |
167 | sa_flags : int; | |
168 | sa_mask : sigset_t; | |
169 | end record; | |
170 | pragma Convention (C, new_struct_sigaction); | |
171 | ||
172 | subtype struct_sigaction is new_struct_sigaction; | |
173 | type struct_sigaction_ptr is access all struct_sigaction; | |
174 | ||
175 | SIG_BLOCK : constant := 1; | |
176 | SIG_UNBLOCK : constant := 2; | |
177 | SIG_SETMASK : constant := 3; | |
178 | ||
179 | SIG_DFL : constant := 0; | |
180 | SIG_IGN : constant := 1; | |
181 | ||
5b4994bc | 182 | SA_SIGINFO : constant := 16#0040#; |
770db697 | 183 | SA_ONSTACK : constant := 16#0001#; |
5b4994bc | 184 | |
c5b2a8ae AC |
185 | function sigaction |
186 | (sig : Signal; | |
187 | act : struct_sigaction_ptr; | |
188 | oact : struct_sigaction_ptr) return int; | |
189 | pragma Import (C, sigaction, "sigaction"); | |
190 | ||
191 | ---------- | |
192 | -- Time -- | |
193 | ---------- | |
194 | ||
195 | Time_Slice_Supported : constant Boolean := True; | |
276e95ca | 196 | -- Indicates whether time slicing is supported (i.e SCHED_RR is supported) |
c5b2a8ae AC |
197 | |
198 | type timespec is private; | |
199 | ||
200 | function nanosleep (rqtp, rmtp : access timespec) return int; | |
201 | pragma Import (C, nanosleep, "nanosleep"); | |
202 | ||
203 | type clockid_t is private; | |
204 | ||
0b5b2bbc AC |
205 | CLOCK_REALTIME : constant clockid_t; |
206 | CLOCK_MONOTONIC : constant clockid_t; | |
c5b2a8ae AC |
207 | |
208 | function clock_gettime | |
209 | (clock_id : clockid_t; | |
210 | tp : access timespec) | |
211 | return int; | |
212 | pragma Import (C, clock_gettime, "clock_gettime"); | |
213 | ||
214 | function To_Duration (TS : timespec) return Duration; | |
215 | pragma Inline (To_Duration); | |
216 | ||
217 | function To_Timespec (D : Duration) return timespec; | |
218 | pragma Inline (To_Timespec); | |
219 | ||
220 | type struct_timezone is record | |
221 | tz_minuteswest : int; | |
222 | tz_dsttime : int; | |
223 | end record; | |
224 | pragma Convention (C, struct_timezone); | |
c5b2a8ae AC |
225 | |
226 | procedure usleep (useconds : unsigned_long); | |
227 | pragma Import (C, usleep, "usleep"); | |
228 | ||
229 | ------------------------- | |
230 | -- Priority Scheduling -- | |
231 | ------------------------- | |
232 | ||
233 | SCHED_FIFO : constant := 1; | |
234 | SCHED_OTHER : constant := 2; | |
235 | SCHED_RR : constant := 3; | |
236 | ||
ec946d18 AC |
237 | function To_Target_Priority |
238 | (Prio : System.Any_Priority) return Interfaces.C.int; | |
835d23b2 | 239 | -- Maps System.Any_Priority to a POSIX priority |
ec946d18 | 240 | |
c5b2a8ae AC |
241 | ------------- |
242 | -- Process -- | |
243 | ------------- | |
244 | ||
245 | type pid_t is private; | |
246 | ||
247 | Self_PID : constant pid_t; | |
248 | ||
249 | function kill (pid : pid_t; sig : Signal) return int; | |
250 | pragma Import (C, kill, "kill"); | |
251 | ||
252 | function getpid return pid_t; | |
253 | pragma Import (C, getpid, "getpid"); | |
254 | ||
255 | --------- | |
256 | -- LWP -- | |
257 | --------- | |
258 | ||
259 | function lwp_self return System.Address; | |
260 | -- lwp_self does not exist on this thread library, revert to pthread_self | |
261 | -- which is the closest approximation (with getpid). This function is | |
262 | -- needed to share 7staprop.adb across POSIX-like targets. | |
263 | pragma Import (C, lwp_self, "pthread_self"); | |
264 | ||
265 | ------------- | |
266 | -- Threads -- | |
267 | ------------- | |
268 | ||
269 | type Thread_Body is access | |
270 | function (arg : System.Address) return System.Address; | |
def46b54 | 271 | pragma Convention (C, Thread_Body); |
c5b2a8ae | 272 | |
8a7988f5 | 273 | function Thread_Body_Access is new |
dae22b53 | 274 | Ada.Unchecked_Conversion (System.Address, Thread_Body); |
8a7988f5 | 275 | |
c5b2a8ae AC |
276 | type pthread_t is private; |
277 | subtype Thread_Id is pthread_t; | |
278 | ||
279 | type pthread_mutex_t is limited private; | |
280 | type pthread_cond_t is limited private; | |
281 | type pthread_attr_t is limited private; | |
282 | type pthread_mutexattr_t is limited private; | |
283 | type pthread_condattr_t is limited private; | |
284 | type pthread_key_t is private; | |
285 | ||
286 | PTHREAD_CREATE_DETACHED : constant := 1; | |
287 | PTHREAD_CREATE_JOINABLE : constant := 0; | |
288 | ||
c5173b1a AC |
289 | PTHREAD_SCOPE_PROCESS : constant := 0; |
290 | PTHREAD_SCOPE_SYSTEM : constant := 2; | |
291 | ||
6f5add73 AC |
292 | -- Read/Write lock not supported on freebsd. To add support both types |
293 | -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined | |
294 | -- with the associated routines pthread_rwlock_[init/destroy] and | |
295 | -- pthread_rwlock_[rdlock/wrlock/unlock]. | |
296 | ||
297 | subtype pthread_rwlock_t is pthread_mutex_t; | |
298 | subtype pthread_rwlockattr_t is pthread_mutexattr_t; | |
299 | ||
c5b2a8ae AC |
300 | ----------- |
301 | -- Stack -- | |
302 | ----------- | |
303 | ||
770db697 EB |
304 | type stack_t is record |
305 | ss_sp : System.Address; | |
306 | ss_size : size_t; | |
307 | ss_flags : int; | |
308 | end record; | |
309 | pragma Convention (C, stack_t); | |
310 | ||
311 | function sigaltstack | |
312 | (ss : not null access stack_t; | |
313 | oss : access stack_t) return int; | |
314 | pragma Import (C, sigaltstack, "sigaltstack"); | |
315 | ||
316 | Alternate_Stack : aliased System.Address; | |
317 | -- This is a dummy definition, never used (Alternate_Stack_Size is null) | |
318 | ||
319 | Alternate_Stack_Size : constant := 0; | |
320 | -- No alternate signal stack is used on this platform | |
321 | ||
c5b2a8ae | 322 | Stack_Base_Available : constant Boolean := False; |
276e95ca RW |
323 | -- Indicates whether the stack base is available on this target. This |
324 | -- allows us to share s-osinte.adb between all the FSU run time. Note that | |
325 | -- this value can only be true if pthread_t has a complete definition that | |
770db697 | 326 | -- corresponds exactly to the C header files. |
c5b2a8ae AC |
327 | |
328 | function Get_Stack_Base (thread : pthread_t) return Address; | |
329 | pragma Inline (Get_Stack_Base); | |
770db697 EB |
330 | -- returns the stack base of the specified thread. Only call this function |
331 | -- when Stack_Base_Available is True. | |
c5b2a8ae AC |
332 | |
333 | function Get_Page_Size return size_t; | |
334 | function Get_Page_Size return Address; | |
335 | pragma Import (C, Get_Page_Size, "getpagesize"); | |
6a2afd13 | 336 | -- Returns the size of a page |
c5b2a8ae AC |
337 | |
338 | PROT_NONE : constant := 0; | |
339 | PROT_READ : constant := 1; | |
340 | PROT_WRITE : constant := 2; | |
341 | PROT_EXEC : constant := 4; | |
342 | PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC; | |
c5b2a8ae AC |
343 | PROT_ON : constant := PROT_NONE; |
344 | PROT_OFF : constant := PROT_ALL; | |
345 | ||
770db697 | 346 | function mprotect (addr : Address; len : size_t; prot : int) return int; |
c5b2a8ae AC |
347 | pragma Import (C, mprotect); |
348 | ||
15ce9ca2 AC |
349 | --------------------------------------- |
350 | -- Nonstandard Thread Initialization -- | |
351 | --------------------------------------- | |
352 | ||
770db697 EB |
353 | -- FSU_THREADS requires pthread_init, which is nonstandard and this should |
354 | -- be invoked during the elaboration of s-taprop.adb. | |
15ce9ca2 AC |
355 | |
356 | -- FreeBSD does not require this so we provide an empty Ada body | |
357 | ||
c5b2a8ae AC |
358 | procedure pthread_init; |
359 | ||
15ce9ca2 AC |
360 | ------------------------- |
361 | -- POSIX.1c Section 3 -- | |
362 | ------------------------- | |
c5b2a8ae AC |
363 | |
364 | function sigwait | |
365 | (set : access sigset_t; | |
366 | sig : access Signal) return int; | |
367 | pragma Import (C, sigwait, "sigwait"); | |
368 | ||
369 | function pthread_kill | |
370 | (thread : pthread_t; | |
15ce9ca2 | 371 | sig : Signal) return int; |
c5b2a8ae AC |
372 | pragma Import (C, pthread_kill, "pthread_kill"); |
373 | ||
c5b2a8ae AC |
374 | function pthread_sigmask |
375 | (how : int; | |
1dd5ad55 AC |
376 | set : access sigset_t; |
377 | oset : access sigset_t) return int; | |
c5b2a8ae AC |
378 | pragma Import (C, pthread_sigmask, "pthread_sigmask"); |
379 | ||
15ce9ca2 AC |
380 | -------------------------- |
381 | -- POSIX.1c Section 11 -- | |
382 | -------------------------- | |
c5b2a8ae AC |
383 | |
384 | function pthread_mutexattr_init | |
385 | (attr : access pthread_mutexattr_t) return int; | |
386 | pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); | |
387 | ||
388 | function pthread_mutexattr_destroy | |
389 | (attr : access pthread_mutexattr_t) return int; | |
390 | pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); | |
391 | ||
392 | function pthread_mutex_init | |
393 | (mutex : access pthread_mutex_t; | |
394 | attr : access pthread_mutexattr_t) return int; | |
395 | pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); | |
396 | ||
397 | function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; | |
398 | pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); | |
399 | ||
400 | function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; | |
401 | pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); | |
402 | ||
403 | function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; | |
404 | pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); | |
405 | ||
406 | function pthread_condattr_init | |
407 | (attr : access pthread_condattr_t) return int; | |
408 | pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); | |
409 | ||
410 | function pthread_condattr_destroy | |
411 | (attr : access pthread_condattr_t) return int; | |
412 | pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); | |
413 | ||
414 | function pthread_cond_init | |
415 | (cond : access pthread_cond_t; | |
416 | attr : access pthread_condattr_t) return int; | |
417 | pragma Import (C, pthread_cond_init, "pthread_cond_init"); | |
418 | ||
419 | function pthread_cond_destroy (cond : access pthread_cond_t) return int; | |
420 | pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); | |
421 | ||
422 | function pthread_cond_signal (cond : access pthread_cond_t) return int; | |
423 | pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); | |
424 | ||
425 | function pthread_cond_wait | |
426 | (cond : access pthread_cond_t; | |
427 | mutex : access pthread_mutex_t) return int; | |
428 | pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); | |
429 | ||
430 | function pthread_cond_timedwait | |
431 | (cond : access pthread_cond_t; | |
432 | mutex : access pthread_mutex_t; | |
433 | abstime : access timespec) return int; | |
434 | pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); | |
435 | ||
436 | Relative_Timed_Wait : constant Boolean := False; | |
437 | -- pthread_cond_timedwait requires an absolute delay time | |
438 | ||
15ce9ca2 AC |
439 | -------------------------- |
440 | -- POSIX.1c Section 13 -- | |
441 | -------------------------- | |
c5b2a8ae AC |
442 | |
443 | PTHREAD_PRIO_NONE : constant := 0; | |
444 | PTHREAD_PRIO_PROTECT : constant := 2; | |
445 | PTHREAD_PRIO_INHERIT : constant := 1; | |
446 | ||
447 | function pthread_mutexattr_setprotocol | |
448 | (attr : access pthread_mutexattr_t; | |
449 | protocol : int) return int; | |
450 | pragma Import | |
451 | (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol"); | |
452 | ||
453 | function pthread_mutexattr_getprotocol | |
454 | (attr : access pthread_mutexattr_t; | |
455 | protocol : access int) return int; | |
456 | pragma Import | |
457 | (C, pthread_mutexattr_getprotocol, "pthread_mutexattr_getprotocol"); | |
458 | ||
459 | function pthread_mutexattr_setprioceiling | |
460 | (attr : access pthread_mutexattr_t; | |
461 | prioceiling : int) return int; | |
462 | pragma Import | |
463 | (C, pthread_mutexattr_setprioceiling, | |
464 | "pthread_mutexattr_setprioceiling"); | |
465 | ||
466 | function pthread_mutexattr_getprioceiling | |
467 | (attr : access pthread_mutexattr_t; | |
468 | prioceiling : access int) return int; | |
469 | pragma Import | |
470 | (C, pthread_mutexattr_getprioceiling, | |
471 | "pthread_mutexattr_getprioceiling"); | |
472 | ||
473 | type struct_sched_param is record | |
474 | sched_priority : int; | |
475 | end record; | |
476 | pragma Convention (C, struct_sched_param); | |
477 | ||
478 | function pthread_getschedparam | |
479 | (thread : pthread_t; | |
480 | policy : access int; | |
481 | param : access struct_sched_param) return int; | |
482 | pragma Import (C, pthread_getschedparam, "pthread_getschedparam"); | |
483 | ||
484 | function pthread_setschedparam | |
485 | (thread : pthread_t; | |
486 | policy : int; | |
487 | param : access struct_sched_param) return int; | |
488 | pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); | |
489 | ||
490 | function pthread_attr_setscope | |
491 | (attr : access pthread_attr_t; | |
492 | contentionscope : int) return int; | |
493 | pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); | |
494 | ||
495 | function pthread_attr_getscope | |
496 | (attr : access pthread_attr_t; | |
497 | contentionscope : access int) return int; | |
498 | pragma Import (C, pthread_attr_getscope, "pthread_attr_getscope"); | |
499 | ||
500 | function pthread_attr_setinheritsched | |
501 | (attr : access pthread_attr_t; | |
502 | inheritsched : int) return int; | |
503 | pragma Import | |
504 | (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched"); | |
505 | ||
506 | function pthread_attr_getinheritsched | |
507 | (attr : access pthread_attr_t; | |
508 | inheritsched : access int) return int; | |
509 | pragma Import | |
510 | (C, pthread_attr_getinheritsched, "pthread_attr_getinheritsched"); | |
511 | ||
512 | function pthread_attr_setschedpolicy | |
513 | (attr : access pthread_attr_t; | |
514 | policy : int) return int; | |
515 | pragma Import (C, pthread_attr_setschedpolicy, | |
516 | "pthread_attr_setschedpolicy"); | |
517 | ||
518 | function pthread_attr_getschedpolicy | |
519 | (attr : access pthread_attr_t; | |
520 | policy : access int) return int; | |
521 | pragma Import (C, pthread_attr_getschedpolicy, | |
522 | "pthread_attr_getschedpolicy"); | |
523 | ||
524 | function pthread_attr_setschedparam | |
525 | (attr : access pthread_attr_t; | |
526 | sched_param : int) return int; | |
527 | pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam"); | |
528 | ||
529 | function pthread_attr_getschedparam | |
530 | (attr : access pthread_attr_t; | |
531 | sched_param : access int) return int; | |
532 | pragma Import (C, pthread_attr_getschedparam, "pthread_attr_getschedparam"); | |
533 | ||
534 | function sched_yield return int; | |
535 | pragma Import (C, sched_yield, "pthread_yield"); | |
536 | ||
15ce9ca2 AC |
537 | -------------------------- |
538 | -- P1003.1c Section 16 -- | |
539 | -------------------------- | |
c5b2a8ae AC |
540 | |
541 | function pthread_attr_init (attributes : access pthread_attr_t) return int; | |
542 | pragma Import (C, pthread_attr_init, "pthread_attr_init"); | |
543 | ||
544 | function pthread_attr_destroy | |
545 | (attributes : access pthread_attr_t) return int; | |
546 | pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); | |
547 | ||
548 | function pthread_attr_setdetachstate | |
549 | (attr : access pthread_attr_t; | |
550 | detachstate : int) return int; | |
551 | pragma Import | |
552 | (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate"); | |
553 | ||
554 | function pthread_attr_getdetachstate | |
555 | (attr : access pthread_attr_t; | |
556 | detachstate : access int) return int; | |
557 | pragma Import | |
558 | (C, pthread_attr_getdetachstate, "pthread_attr_getdetachstate"); | |
559 | ||
560 | function pthread_attr_getstacksize | |
561 | (attr : access pthread_attr_t; | |
562 | stacksize : access size_t) return int; | |
563 | pragma Import | |
564 | (C, pthread_attr_getstacksize, "pthread_attr_getstacksize"); | |
565 | ||
566 | function pthread_attr_setstacksize | |
567 | (attr : access pthread_attr_t; | |
568 | stacksize : size_t) return int; | |
569 | pragma Import | |
570 | (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); | |
571 | ||
572 | function pthread_create | |
573 | (thread : access pthread_t; | |
574 | attributes : access pthread_attr_t; | |
575 | start_routine : Thread_Body; | |
576 | arg : System.Address) return int; | |
577 | pragma Import (C, pthread_create, "pthread_create"); | |
578 | ||
579 | function pthread_detach (thread : pthread_t) return int; | |
580 | pragma Import (C, pthread_detach, "pthread_detach"); | |
581 | ||
582 | procedure pthread_exit (status : System.Address); | |
583 | pragma Import (C, pthread_exit, "pthread_exit"); | |
584 | ||
585 | function pthread_self return pthread_t; | |
586 | pragma Import (C, pthread_self, "pthread_self"); | |
587 | ||
15ce9ca2 AC |
588 | -------------------------- |
589 | -- POSIX.1c Section 17 -- | |
590 | -------------------------- | |
c5b2a8ae AC |
591 | |
592 | function pthread_setspecific | |
593 | (key : pthread_key_t; | |
594 | value : System.Address) return int; | |
595 | pragma Import (C, pthread_setspecific, "pthread_setspecific"); | |
596 | ||
597 | function pthread_getspecific (key : pthread_key_t) return System.Address; | |
598 | pragma Import (C, pthread_getspecific, "pthread_getspecific"); | |
599 | ||
def46b54 RD |
600 | type destructor_pointer is access procedure (arg : System.Address); |
601 | pragma Convention (C, destructor_pointer); | |
c5b2a8ae AC |
602 | |
603 | function pthread_key_create | |
604 | (key : access pthread_key_t; | |
605 | destructor : destructor_pointer) return int; | |
606 | pragma Import (C, pthread_key_create, "pthread_key_create"); | |
607 | ||
15ce9ca2 AC |
608 | ------------------------------------ |
609 | -- Non-portable Pthread Functions -- | |
610 | ------------------------------------ | |
c5b2a8ae AC |
611 | |
612 | function pthread_set_name_np | |
613 | (thread : pthread_t; | |
614 | name : System.Address) return int; | |
615 | pragma Import (C, pthread_set_name_np, "pthread_set_name_np"); | |
616 | ||
617 | private | |
618 | ||
619 | type sigset_t is array (1 .. 4) of unsigned; | |
620 | ||
621 | -- In FreeBSD the component sa_handler turns out to | |
622 | -- be one a union type, and the selector is a macro: | |
623 | -- #define sa_handler __sigaction_u._handler | |
624 | -- #define sa_sigaction __sigaction_u._sigaction | |
625 | ||
15ce9ca2 AC |
626 | -- Should we add a signal_context type here ??? |
627 | -- How could it be done independent of the CPU architecture ??? | |
c5b2a8ae AC |
628 | -- sigcontext type is opaque, so it is architecturally neutral. |
629 | -- It is always passed as an access type, so define it as an empty record | |
630 | -- since the contents are not used anywhere. | |
15ce9ca2 | 631 | |
c5b2a8ae AC |
632 | type struct_sigcontext is null record; |
633 | pragma Convention (C, struct_sigcontext); | |
634 | ||
635 | type pid_t is new int; | |
636 | Self_PID : constant pid_t := 0; | |
637 | ||
638 | type time_t is new long; | |
639 | ||
640 | type timespec is record | |
641 | ts_sec : time_t; | |
642 | ts_nsec : long; | |
643 | end record; | |
644 | pragma Convention (C, timespec); | |
645 | ||
646 | type clockid_t is new int; | |
0b5b2bbc | 647 | CLOCK_REALTIME : constant clockid_t := 0; |
885c4871 AC |
648 | CLOCK_MONOTONIC : constant clockid_t := 0; |
649 | -- On FreeBSD, pthread_cond_timedwait assumes a CLOCK_REALTIME time by | |
650 | -- default (unless pthread_condattr_setclock is used to set an alternate | |
651 | -- clock). | |
c5b2a8ae | 652 | |
c5b2a8ae AC |
653 | type pthread_t is new System.Address; |
654 | type pthread_attr_t is new System.Address; | |
655 | type pthread_mutex_t is new System.Address; | |
656 | type pthread_mutexattr_t is new System.Address; | |
657 | type pthread_cond_t is new System.Address; | |
658 | type pthread_condattr_t is new System.Address; | |
659 | type pthread_key_t is new int; | |
660 | ||
661 | end System.OS_Interface; |