a316afc592b6e2ec47663ebad72859c148cd6fa8
[gcc.git] / gcc / ada / s-thread.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . T H R E A D S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
33
34 -- This package provides facilities to register a thread to the runtime,
35 -- and allocate its task specific datas.
36
37 with Ada.Exceptions;
38
39 package System.Threads is
40
41 subtype EO is Ada.Exceptions.Exception_Occurrence;
42
43 subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
44
45 type ATSD is limited private;
46 -- Type of the Ada thread specific data. It contains datas needed
47 -- by the GNAT runtime.
48
49 type ATSD_Access is access ATSD;
50
51 -- Get/Set for the attributes of the current thread
52
53 function Get_Jmpbuf_Address return Address;
54 pragma Inline (Get_Jmpbuf_Address);
55
56 procedure Set_Jmpbuf_Address (Addr : Address);
57 pragma Inline (Get_Jmpbuf_Address);
58
59 function Get_Sec_Stack_Addr return Address;
60 pragma Inline (Get_Sec_Stack_Addr);
61
62 procedure Set_Sec_Stack_Addr (Addr : Address);
63 pragma Inline (Set_Sec_Stack_Addr);
64
65 function Get_Current_Excep return EOA;
66 pragma Inline (Get_Current_Excep);
67
68 --------------------------
69 -- Thread Body Handling --
70 --------------------------
71
72 -- The subprograms in this section are called by the expansion of a
73 -- subprogram body to which a Thread_Body pragma has been applied:
74
75 -- Given a subprogram body
76
77 -- procedure xyz (params ....) is -- can also be a function
78 -- <user declarations>
79 -- begin
80 -- <user statements>
81 -- <user exception handlers>
82 -- end xyz;
83
84 -- The expansion resulting from use of the Thread_Body pragma is:
85
86 -- procedure xyz (params ...) is
87
88 -- _Secondary_Stack : aliased
89 -- Storage_Elements.Storage_Array
90 -- (1 .. Storage_Offset (Sec_Stack_Size));
91 -- for _Secondary_Stack'Alignment use Standard'Maximum_Alignment;
92
93 -- _Process_ATSD : aliased System.Threads.ATSD;
94
95 -- begin
96 -- System.Threads.Thread_Body_Enter;
97 -- (_Secondary_Stack'Address,
98 -- _Secondary_Stack'Length,
99 -- _Process_ATSD'Address);
100
101 -- declare
102 -- <user declarations>
103 -- begin
104 -- <user statements>
105 -- <user exception handlers>
106 -- end;
107
108 -- System.Threads.Thread_Body_Leave;
109
110 -- exception
111 -- when E : others =>
112 -- System.Threads.Thread_Body_Exceptional_Exit (E);
113 -- end;
114
115 -- Note the exception handler is omitted if pragma Restriction
116 -- No_Exception_Handlers is currently active.
117
118 -- Note: the secondary stack size (Sec_Stack_Size) comes either from
119 -- the pragma, if specified, or is the default value taken from
120 -- the declaration in System.Secondary_Stack.
121
122 procedure Thread_Body_Enter
123 (Sec_Stack_Address : System.Address;
124 Sec_Stack_Size : Natural;
125 Process_ATSD_Address : System.Address);
126 -- Enter thread body, see above for details
127
128 procedure Thread_Body_Leave;
129 -- Leave thread body (normally), see above for details
130
131 procedure Thread_Body_Exceptional_Exit
132 (EO : Ada.Exceptions.Exception_Occurrence);
133 -- Leave thread body (abnormally on exception), see above for details
134
135 private
136
137 ------------------------
138 -- Task Specific Data --
139 ------------------------
140
141 type ATSD is limited record
142 Jmpbuf_Address : Address := Null_Address;
143 -- Address of jump buffer used to store the address of the
144 -- current longjmp/setjmp buffer for exception management.
145 -- These buffers are threaded into a stack, and the address
146 -- here is the top of the stack. A null address means that
147 -- no exception handler is currently active.
148
149 Sec_Stack_Addr : Address := Null_Address;
150 -- Address of currently allocated secondary stack
151
152 Current_Excep : aliased EO;
153 -- Exception occurrence that contains the information for the
154 -- current exception. Note that any exception in the same task
155 -- destroys this information, so the data in this variable must
156 -- be copied out before another exception can occur.
157
158 end record;
159
160 end System.Threads;