1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT 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 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1991-1994, Florida State University --
|
10 |
|
|
-- Copyright (C) 1995-2008, 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, 51 Franklin Street, Fifth Floor, --
|
21 |
|
|
-- Boston, MA 02110-1301, 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 |
|
|
------------------------------------------------------------------------------
|
34 |
|
|
|
35 |
|
|
-- This is a GNU/Linux (GNU/LinuxThreads) version of this package
|
36 |
|
|
|
37 |
|
|
-- This package encapsulates all direct interfaces to OS services
|
38 |
|
|
-- that are needed by the tasking run-time (libgnarl).
|
39 |
|
|
|
40 |
|
|
-- PLEASE DO NOT add any with-clauses to this package or remove the pragma
|
41 |
|
|
-- Preelaborate. This package is designed to be a bottom-level (leaf) package.
|
42 |
|
|
|
43 |
|
|
with Ada.Unchecked_Conversion;
|
44 |
|
|
with Interfaces.C;
|
45 |
|
|
with System.Linux;
|
46 |
|
|
|
47 |
|
|
package System.OS_Interface is
|
48 |
|
|
pragma Preelaborate;
|
49 |
|
|
|
50 |
|
|
pragma Linker_Options ("-lpthread");
|
51 |
|
|
|
52 |
|
|
subtype int is Interfaces.C.int;
|
53 |
|
|
subtype char is Interfaces.C.char;
|
54 |
|
|
subtype short is Interfaces.C.short;
|
55 |
|
|
subtype long is Interfaces.C.long;
|
56 |
|
|
subtype unsigned is Interfaces.C.unsigned;
|
57 |
|
|
subtype unsigned_short is Interfaces.C.unsigned_short;
|
58 |
|
|
subtype unsigned_long is Interfaces.C.unsigned_long;
|
59 |
|
|
subtype unsigned_char is Interfaces.C.unsigned_char;
|
60 |
|
|
subtype plain_char is Interfaces.C.plain_char;
|
61 |
|
|
subtype size_t is Interfaces.C.size_t;
|
62 |
|
|
|
63 |
|
|
-----------
|
64 |
|
|
-- Errno --
|
65 |
|
|
-----------
|
66 |
|
|
|
67 |
|
|
function errno return int;
|
68 |
|
|
pragma Import (C, errno, "__get_errno");
|
69 |
|
|
|
70 |
|
|
EAGAIN : constant := System.Linux.EAGAIN;
|
71 |
|
|
EINTR : constant := System.Linux.EINTR;
|
72 |
|
|
EINVAL : constant := System.Linux.EINVAL;
|
73 |
|
|
ENOMEM : constant := System.Linux.ENOMEM;
|
74 |
|
|
EPERM : constant := System.Linux.EPERM;
|
75 |
|
|
ETIMEDOUT : constant := System.Linux.ETIMEDOUT;
|
76 |
|
|
|
77 |
|
|
-------------
|
78 |
|
|
-- Signals --
|
79 |
|
|
-------------
|
80 |
|
|
|
81 |
|
|
Max_Interrupt : constant := 63;
|
82 |
|
|
type Signal is new int range 0 .. Max_Interrupt;
|
83 |
|
|
for Signal'Size use int'Size;
|
84 |
|
|
|
85 |
|
|
SIGHUP : constant := System.Linux.SIGHUP;
|
86 |
|
|
SIGINT : constant := System.Linux.SIGINT;
|
87 |
|
|
SIGQUIT : constant := System.Linux.SIGQUIT;
|
88 |
|
|
SIGILL : constant := System.Linux.SIGILL;
|
89 |
|
|
SIGTRAP : constant := System.Linux.SIGTRAP;
|
90 |
|
|
SIGIOT : constant := System.Linux.SIGIOT;
|
91 |
|
|
SIGABRT : constant := System.Linux.SIGABRT;
|
92 |
|
|
SIGFPE : constant := System.Linux.SIGFPE;
|
93 |
|
|
SIGKILL : constant := System.Linux.SIGKILL;
|
94 |
|
|
SIGBUS : constant := System.Linux.SIGBUS;
|
95 |
|
|
SIGSEGV : constant := System.Linux.SIGSEGV;
|
96 |
|
|
SIGPIPE : constant := System.Linux.SIGPIPE;
|
97 |
|
|
SIGALRM : constant := System.Linux.SIGALRM;
|
98 |
|
|
SIGTERM : constant := System.Linux.SIGTERM;
|
99 |
|
|
SIGUSR1 : constant := System.Linux.SIGUSR1;
|
100 |
|
|
SIGUSR2 : constant := System.Linux.SIGUSR2;
|
101 |
|
|
SIGCLD : constant := System.Linux.SIGCLD;
|
102 |
|
|
SIGCHLD : constant := System.Linux.SIGCHLD;
|
103 |
|
|
SIGPWR : constant := System.Linux.SIGPWR;
|
104 |
|
|
SIGWINCH : constant := System.Linux.SIGWINCH;
|
105 |
|
|
SIGURG : constant := System.Linux.SIGURG;
|
106 |
|
|
SIGPOLL : constant := System.Linux.SIGPOLL;
|
107 |
|
|
SIGIO : constant := System.Linux.SIGIO;
|
108 |
|
|
SIGLOST : constant := System.Linux.SIGLOST;
|
109 |
|
|
SIGSTOP : constant := System.Linux.SIGSTOP;
|
110 |
|
|
SIGTSTP : constant := System.Linux.SIGTSTP;
|
111 |
|
|
SIGCONT : constant := System.Linux.SIGCONT;
|
112 |
|
|
SIGTTIN : constant := System.Linux.SIGTTIN;
|
113 |
|
|
SIGTTOU : constant := System.Linux.SIGTTOU;
|
114 |
|
|
SIGVTALRM : constant := System.Linux.SIGVTALRM;
|
115 |
|
|
SIGPROF : constant := System.Linux.SIGPROF;
|
116 |
|
|
SIGXCPU : constant := System.Linux.SIGXCPU;
|
117 |
|
|
SIGXFSZ : constant := System.Linux.SIGXFSZ;
|
118 |
|
|
SIGUNUSED : constant := System.Linux.SIGUNUSED;
|
119 |
|
|
SIGSTKFLT : constant := System.Linux.SIGSTKFLT;
|
120 |
|
|
SIGLTHRRES : constant := System.Linux.SIGLTHRRES;
|
121 |
|
|
SIGLTHRCAN : constant := System.Linux.SIGLTHRCAN;
|
122 |
|
|
SIGLTHRDBG : constant := System.Linux.SIGLTHRDBG;
|
123 |
|
|
|
124 |
|
|
SIGADAABORT : constant := SIGABRT;
|
125 |
|
|
-- Change this if you want to use another signal for task abort.
|
126 |
|
|
-- SIGTERM might be a good one.
|
127 |
|
|
|
128 |
|
|
type Signal_Set is array (Natural range <>) of Signal;
|
129 |
|
|
|
130 |
|
|
Unmasked : constant Signal_Set := (
|
131 |
|
|
SIGTRAP,
|
132 |
|
|
-- To enable debugging on multithreaded applications, mark SIGTRAP to
|
133 |
|
|
-- be kept unmasked.
|
134 |
|
|
|
135 |
|
|
SIGBUS,
|
136 |
|
|
|
137 |
|
|
SIGTTIN, SIGTTOU, SIGTSTP,
|
138 |
|
|
-- Keep these three signals unmasked so that background processes
|
139 |
|
|
-- and IO behaves as normal "C" applications
|
140 |
|
|
|
141 |
|
|
SIGPROF,
|
142 |
|
|
-- To avoid confusing the profiler
|
143 |
|
|
|
144 |
|
|
SIGKILL, SIGSTOP,
|
145 |
|
|
-- These two signals actually cannot be masked;
|
146 |
|
|
-- POSIX simply won't allow it.
|
147 |
|
|
|
148 |
|
|
SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
|
149 |
|
|
-- These three signals are used by GNU/LinuxThreads starting from
|
150 |
|
|
-- glibc 2.1 (future 2.2).
|
151 |
|
|
|
152 |
|
|
Reserved : constant Signal_Set :=
|
153 |
|
|
-- I am not sure why the following two signals are reserved.
|
154 |
|
|
-- I guess they are not supported by this version of GNU/Linux.
|
155 |
|
|
(SIGVTALRM, SIGUNUSED);
|
156 |
|
|
|
157 |
|
|
type sigset_t is private;
|
158 |
|
|
|
159 |
|
|
function sigaddset (set : access sigset_t; sig : Signal) return int;
|
160 |
|
|
pragma Import (C, sigaddset, "sigaddset");
|
161 |
|
|
|
162 |
|
|
function sigdelset (set : access sigset_t; sig : Signal) return int;
|
163 |
|
|
pragma Import (C, sigdelset, "sigdelset");
|
164 |
|
|
|
165 |
|
|
function sigfillset (set : access sigset_t) return int;
|
166 |
|
|
pragma Import (C, sigfillset, "sigfillset");
|
167 |
|
|
|
168 |
|
|
function sigismember (set : access sigset_t; sig : Signal) return int;
|
169 |
|
|
pragma Import (C, sigismember, "sigismember");
|
170 |
|
|
|
171 |
|
|
function sigemptyset (set : access sigset_t) return int;
|
172 |
|
|
pragma Import (C, sigemptyset, "sigemptyset");
|
173 |
|
|
|
174 |
|
|
type union_type_3 is new String (1 .. 116);
|
175 |
|
|
type siginfo_t is record
|
176 |
|
|
si_signo : int;
|
177 |
|
|
si_code : int;
|
178 |
|
|
si_errno : int;
|
179 |
|
|
X_data : union_type_3;
|
180 |
|
|
end record;
|
181 |
|
|
pragma Convention (C, siginfo_t);
|
182 |
|
|
|
183 |
|
|
type struct_sigaction is record
|
184 |
|
|
sa_handler : System.Address;
|
185 |
|
|
sa_mask : sigset_t;
|
186 |
|
|
sa_flags : Interfaces.C.unsigned_long;
|
187 |
|
|
sa_restorer : System.Address;
|
188 |
|
|
end record;
|
189 |
|
|
pragma Convention (C, struct_sigaction);
|
190 |
|
|
|
191 |
|
|
type struct_sigaction_ptr is access all struct_sigaction;
|
192 |
|
|
|
193 |
|
|
type Machine_State is record
|
194 |
|
|
eip : unsigned_long;
|
195 |
|
|
ebx : unsigned_long;
|
196 |
|
|
esp : unsigned_long;
|
197 |
|
|
ebp : unsigned_long;
|
198 |
|
|
esi : unsigned_long;
|
199 |
|
|
edi : unsigned_long;
|
200 |
|
|
end record;
|
201 |
|
|
type Machine_State_Ptr is access all Machine_State;
|
202 |
|
|
|
203 |
|
|
SA_SIGINFO : constant := System.Linux.SA_SIGINFO;
|
204 |
|
|
SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
|
205 |
|
|
|
206 |
|
|
SIG_BLOCK : constant := 0;
|
207 |
|
|
SIG_UNBLOCK : constant := 1;
|
208 |
|
|
SIG_SETMASK : constant := 2;
|
209 |
|
|
|
210 |
|
|
SIG_DFL : constant := 0;
|
211 |
|
|
SIG_IGN : constant := 1;
|
212 |
|
|
|
213 |
|
|
function sigaction
|
214 |
|
|
(sig : Signal;
|
215 |
|
|
act : struct_sigaction_ptr;
|
216 |
|
|
oact : struct_sigaction_ptr) return int;
|
217 |
|
|
pragma Import (C, sigaction, "sigaction");
|
218 |
|
|
|
219 |
|
|
----------
|
220 |
|
|
-- Time --
|
221 |
|
|
----------
|
222 |
|
|
|
223 |
|
|
type timespec is private;
|
224 |
|
|
|
225 |
|
|
function To_Duration (TS : timespec) return Duration;
|
226 |
|
|
pragma Inline (To_Duration);
|
227 |
|
|
|
228 |
|
|
function To_Timespec (D : Duration) return timespec;
|
229 |
|
|
pragma Inline (To_Timespec);
|
230 |
|
|
|
231 |
|
|
function sysconf (name : int) return long;
|
232 |
|
|
pragma Import (C, sysconf);
|
233 |
|
|
|
234 |
|
|
SC_CLK_TCK : constant := 2;
|
235 |
|
|
SC_NPROCESSORS_ONLN : constant := 84;
|
236 |
|
|
|
237 |
|
|
-------------------------
|
238 |
|
|
-- Priority Scheduling --
|
239 |
|
|
-------------------------
|
240 |
|
|
|
241 |
|
|
SCHED_OTHER : constant := 0;
|
242 |
|
|
SCHED_FIFO : constant := 1;
|
243 |
|
|
SCHED_RR : constant := 2;
|
244 |
|
|
|
245 |
|
|
function To_Target_Priority
|
246 |
|
|
(Prio : System.Any_Priority) return Interfaces.C.int;
|
247 |
|
|
-- Maps System.Any_Priority to a POSIX priority
|
248 |
|
|
|
249 |
|
|
-------------
|
250 |
|
|
-- Process --
|
251 |
|
|
-------------
|
252 |
|
|
|
253 |
|
|
type pid_t is private;
|
254 |
|
|
|
255 |
|
|
function kill (pid : pid_t; sig : Signal) return int;
|
256 |
|
|
pragma Import (C, kill, "kill");
|
257 |
|
|
|
258 |
|
|
function getpid return pid_t;
|
259 |
|
|
pragma Import (C, getpid, "getpid");
|
260 |
|
|
|
261 |
|
|
-------------
|
262 |
|
|
-- Threads --
|
263 |
|
|
-------------
|
264 |
|
|
|
265 |
|
|
type Thread_Body is access
|
266 |
|
|
function (arg : System.Address) return System.Address;
|
267 |
|
|
pragma Convention (C, Thread_Body);
|
268 |
|
|
|
269 |
|
|
function Thread_Body_Access is new
|
270 |
|
|
Ada.Unchecked_Conversion (System.Address, Thread_Body);
|
271 |
|
|
|
272 |
|
|
type pthread_t is new unsigned_long;
|
273 |
|
|
subtype Thread_Id is pthread_t;
|
274 |
|
|
|
275 |
|
|
function To_pthread_t is new Ada.Unchecked_Conversion
|
276 |
|
|
(unsigned_long, pthread_t);
|
277 |
|
|
|
278 |
|
|
type pthread_mutex_t is limited private;
|
279 |
|
|
type pthread_cond_t is limited private;
|
280 |
|
|
type pthread_attr_t is limited private;
|
281 |
|
|
type pthread_mutexattr_t is limited private;
|
282 |
|
|
type pthread_condattr_t is limited private;
|
283 |
|
|
type pthread_key_t is private;
|
284 |
|
|
|
285 |
|
|
PTHREAD_CREATE_DETACHED : constant := 1;
|
286 |
|
|
|
287 |
|
|
-----------
|
288 |
|
|
-- Stack --
|
289 |
|
|
-----------
|
290 |
|
|
|
291 |
|
|
type stack_t is record
|
292 |
|
|
ss_sp : System.Address;
|
293 |
|
|
ss_flags : int;
|
294 |
|
|
ss_size : size_t;
|
295 |
|
|
end record;
|
296 |
|
|
pragma Convention (C, stack_t);
|
297 |
|
|
|
298 |
|
|
function sigaltstack
|
299 |
|
|
(ss : not null access stack_t;
|
300 |
|
|
oss : access stack_t) return int;
|
301 |
|
|
pragma Import (C, sigaltstack, "sigaltstack");
|
302 |
|
|
|
303 |
|
|
Alternate_Stack : aliased System.Address;
|
304 |
|
|
pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
|
305 |
|
|
-- The alternate signal stack for stack overflows
|
306 |
|
|
|
307 |
|
|
Alternate_Stack_Size : constant := 16 * 1024;
|
308 |
|
|
-- This must be in keeping with init.c:__gnat_alternate_stack
|
309 |
|
|
|
310 |
|
|
function Get_Stack_Base (thread : pthread_t) return Address;
|
311 |
|
|
pragma Inline (Get_Stack_Base);
|
312 |
|
|
-- This is a dummy procedure to share some GNULLI files
|
313 |
|
|
|
314 |
|
|
---------------------------------------
|
315 |
|
|
-- Nonstandard Thread Initialization --
|
316 |
|
|
---------------------------------------
|
317 |
|
|
|
318 |
|
|
procedure pthread_init;
|
319 |
|
|
pragma Inline (pthread_init);
|
320 |
|
|
-- This is a dummy procedure to share some GNULLI files
|
321 |
|
|
|
322 |
|
|
-------------------------
|
323 |
|
|
-- POSIX.1c Section 3 --
|
324 |
|
|
-------------------------
|
325 |
|
|
|
326 |
|
|
function sigwait (set : access sigset_t; sig : access Signal) return int;
|
327 |
|
|
pragma Import (C, sigwait, "sigwait");
|
328 |
|
|
|
329 |
|
|
function pthread_kill (thread : pthread_t; sig : Signal) return int;
|
330 |
|
|
pragma Import (C, pthread_kill, "pthread_kill");
|
331 |
|
|
|
332 |
|
|
function pthread_sigmask
|
333 |
|
|
(how : int;
|
334 |
|
|
set : access sigset_t;
|
335 |
|
|
oset : access sigset_t) return int;
|
336 |
|
|
pragma Import (C, pthread_sigmask, "pthread_sigmask");
|
337 |
|
|
|
338 |
|
|
--------------------------
|
339 |
|
|
-- POSIX.1c Section 11 --
|
340 |
|
|
--------------------------
|
341 |
|
|
|
342 |
|
|
function pthread_mutexattr_init
|
343 |
|
|
(attr : access pthread_mutexattr_t) return int;
|
344 |
|
|
pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
|
345 |
|
|
|
346 |
|
|
function pthread_mutexattr_destroy
|
347 |
|
|
(attr : access pthread_mutexattr_t) return int;
|
348 |
|
|
pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
|
349 |
|
|
|
350 |
|
|
function pthread_mutex_init
|
351 |
|
|
(mutex : access pthread_mutex_t;
|
352 |
|
|
attr : access pthread_mutexattr_t) return int;
|
353 |
|
|
pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
|
354 |
|
|
|
355 |
|
|
function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
|
356 |
|
|
pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
|
357 |
|
|
|
358 |
|
|
function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
|
359 |
|
|
pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
|
360 |
|
|
|
361 |
|
|
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
|
362 |
|
|
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
|
363 |
|
|
|
364 |
|
|
function pthread_condattr_init
|
365 |
|
|
(attr : access pthread_condattr_t) return int;
|
366 |
|
|
pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
|
367 |
|
|
|
368 |
|
|
function pthread_condattr_destroy
|
369 |
|
|
(attr : access pthread_condattr_t) return int;
|
370 |
|
|
pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
|
371 |
|
|
|
372 |
|
|
function pthread_cond_init
|
373 |
|
|
(cond : access pthread_cond_t;
|
374 |
|
|
attr : access pthread_condattr_t) return int;
|
375 |
|
|
pragma Import (C, pthread_cond_init, "pthread_cond_init");
|
376 |
|
|
|
377 |
|
|
function pthread_cond_destroy (cond : access pthread_cond_t) return int;
|
378 |
|
|
pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
|
379 |
|
|
|
380 |
|
|
function pthread_cond_signal (cond : access pthread_cond_t) return int;
|
381 |
|
|
pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
|
382 |
|
|
|
383 |
|
|
function pthread_cond_wait
|
384 |
|
|
(cond : access pthread_cond_t;
|
385 |
|
|
mutex : access pthread_mutex_t) return int;
|
386 |
|
|
pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
|
387 |
|
|
|
388 |
|
|
function pthread_cond_timedwait
|
389 |
|
|
(cond : access pthread_cond_t;
|
390 |
|
|
mutex : access pthread_mutex_t;
|
391 |
|
|
abstime : access timespec) return int;
|
392 |
|
|
pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
|
393 |
|
|
|
394 |
|
|
--------------------------
|
395 |
|
|
-- POSIX.1c Section 13 --
|
396 |
|
|
--------------------------
|
397 |
|
|
|
398 |
|
|
type struct_sched_param is record
|
399 |
|
|
sched_priority : int; -- scheduling priority
|
400 |
|
|
end record;
|
401 |
|
|
pragma Convention (C, struct_sched_param);
|
402 |
|
|
|
403 |
|
|
function pthread_setschedparam
|
404 |
|
|
(thread : pthread_t;
|
405 |
|
|
policy : int;
|
406 |
|
|
param : access struct_sched_param) return int;
|
407 |
|
|
pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
|
408 |
|
|
|
409 |
|
|
function pthread_attr_setschedpolicy
|
410 |
|
|
(attr : access pthread_attr_t;
|
411 |
|
|
policy : int) return int;
|
412 |
|
|
pragma Import
|
413 |
|
|
(C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
|
414 |
|
|
|
415 |
|
|
function sched_yield return int;
|
416 |
|
|
pragma Import (C, sched_yield, "sched_yield");
|
417 |
|
|
|
418 |
|
|
---------------------------
|
419 |
|
|
-- P1003.1c - Section 16 --
|
420 |
|
|
---------------------------
|
421 |
|
|
|
422 |
|
|
function pthread_attr_init
|
423 |
|
|
(attributes : access pthread_attr_t) return int;
|
424 |
|
|
pragma Import (C, pthread_attr_init, "pthread_attr_init");
|
425 |
|
|
|
426 |
|
|
function pthread_attr_destroy
|
427 |
|
|
(attributes : access pthread_attr_t) return int;
|
428 |
|
|
pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
|
429 |
|
|
|
430 |
|
|
function pthread_attr_setdetachstate
|
431 |
|
|
(attr : access pthread_attr_t;
|
432 |
|
|
detachstate : int) return int;
|
433 |
|
|
pragma Import
|
434 |
|
|
(C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
|
435 |
|
|
|
436 |
|
|
function pthread_attr_setstacksize
|
437 |
|
|
(attr : access pthread_attr_t;
|
438 |
|
|
stacksize : size_t) return int;
|
439 |
|
|
pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
|
440 |
|
|
|
441 |
|
|
function pthread_create
|
442 |
|
|
(thread : access pthread_t;
|
443 |
|
|
attributes : access pthread_attr_t;
|
444 |
|
|
start_routine : Thread_Body;
|
445 |
|
|
arg : System.Address) return int;
|
446 |
|
|
pragma Import (C, pthread_create, "pthread_create");
|
447 |
|
|
|
448 |
|
|
procedure pthread_exit (status : System.Address);
|
449 |
|
|
pragma Import (C, pthread_exit, "pthread_exit");
|
450 |
|
|
|
451 |
|
|
function pthread_self return pthread_t;
|
452 |
|
|
pragma Import (C, pthread_self, "pthread_self");
|
453 |
|
|
|
454 |
|
|
function lwp_self return System.Address;
|
455 |
|
|
pragma Import (C, lwp_self, "__gnat_lwp_self");
|
456 |
|
|
|
457 |
|
|
--------------------------
|
458 |
|
|
-- POSIX.1c Section 17 --
|
459 |
|
|
--------------------------
|
460 |
|
|
|
461 |
|
|
function pthread_setspecific
|
462 |
|
|
(key : pthread_key_t;
|
463 |
|
|
value : System.Address) return int;
|
464 |
|
|
pragma Import (C, pthread_setspecific, "pthread_setspecific");
|
465 |
|
|
|
466 |
|
|
function pthread_getspecific (key : pthread_key_t) return System.Address;
|
467 |
|
|
pragma Import (C, pthread_getspecific, "pthread_getspecific");
|
468 |
|
|
|
469 |
|
|
type destructor_pointer is access procedure (arg : System.Address);
|
470 |
|
|
pragma Convention (C, destructor_pointer);
|
471 |
|
|
|
472 |
|
|
function pthread_key_create
|
473 |
|
|
(key : access pthread_key_t;
|
474 |
|
|
destructor : destructor_pointer) return int;
|
475 |
|
|
pragma Import (C, pthread_key_create, "pthread_key_create");
|
476 |
|
|
|
477 |
|
|
CPU_SETSIZE : constant := 1_024;
|
478 |
|
|
|
479 |
|
|
type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
|
480 |
|
|
for bit_field'Size use CPU_SETSIZE;
|
481 |
|
|
pragma Pack (bit_field);
|
482 |
|
|
pragma Convention (C, bit_field);
|
483 |
|
|
|
484 |
|
|
type cpu_set_t is record
|
485 |
|
|
bits : bit_field;
|
486 |
|
|
end record;
|
487 |
|
|
pragma Convention (C, cpu_set_t);
|
488 |
|
|
|
489 |
|
|
function pthread_setaffinity_np
|
490 |
|
|
(thread : pthread_t;
|
491 |
|
|
cpusetsize : size_t;
|
492 |
|
|
cpuset : access cpu_set_t) return int;
|
493 |
|
|
pragma Import (C, pthread_setaffinity_np, "__gnat_pthread_setaffinity_np");
|
494 |
|
|
|
495 |
|
|
private
|
496 |
|
|
|
497 |
|
|
type sigset_t is array (0 .. 127) of Interfaces.C.unsigned_char;
|
498 |
|
|
pragma Convention (C, sigset_t);
|
499 |
|
|
for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
500 |
|
|
|
501 |
|
|
pragma Warnings (Off);
|
502 |
|
|
for struct_sigaction use record
|
503 |
|
|
sa_handler at Linux.sa_handler_pos range 0 .. Standard'Address_Size - 1;
|
504 |
|
|
sa_mask at Linux.sa_mask_pos range 0 .. 1023;
|
505 |
|
|
sa_flags at Linux.sa_flags_pos range 0 .. Standard'Address_Size - 1;
|
506 |
|
|
end record;
|
507 |
|
|
-- We intentionally leave sa_restorer unspecified and let the compiler
|
508 |
|
|
-- append it after the last field, so disable corresponding warning.
|
509 |
|
|
pragma Warnings (On);
|
510 |
|
|
|
511 |
|
|
type pid_t is new int;
|
512 |
|
|
|
513 |
|
|
type time_t is new long;
|
514 |
|
|
|
515 |
|
|
type timespec is record
|
516 |
|
|
tv_sec : time_t;
|
517 |
|
|
tv_nsec : long;
|
518 |
|
|
end record;
|
519 |
|
|
pragma Convention (C, timespec);
|
520 |
|
|
|
521 |
|
|
type pthread_attr_t is record
|
522 |
|
|
detachstate : int;
|
523 |
|
|
schedpolicy : int;
|
524 |
|
|
schedparam : struct_sched_param;
|
525 |
|
|
inheritsched : int;
|
526 |
|
|
scope : int;
|
527 |
|
|
guardsize : size_t;
|
528 |
|
|
stackaddr_set : int;
|
529 |
|
|
stackaddr : System.Address;
|
530 |
|
|
stacksize : size_t;
|
531 |
|
|
end record;
|
532 |
|
|
pragma Convention (C, pthread_attr_t);
|
533 |
|
|
|
534 |
|
|
type pthread_condattr_t is record
|
535 |
|
|
dummy : int;
|
536 |
|
|
end record;
|
537 |
|
|
pragma Convention (C, pthread_condattr_t);
|
538 |
|
|
|
539 |
|
|
type pthread_mutexattr_t is record
|
540 |
|
|
mutexkind : int;
|
541 |
|
|
end record;
|
542 |
|
|
pragma Convention (C, pthread_mutexattr_t);
|
543 |
|
|
|
544 |
|
|
type pthread_mutex_t is new System.Linux.pthread_mutex_t;
|
545 |
|
|
|
546 |
|
|
type pthread_cond_t is array (0 .. 47) of unsigned_char;
|
547 |
|
|
pragma Convention (C, pthread_cond_t);
|
548 |
|
|
|
549 |
|
|
type pthread_key_t is new unsigned;
|
550 |
|
|
|
551 |
|
|
end System.OS_Interface;
|