OSDN Git Service

2003-12-11 Ed Falis <falis@gnat.com>
[pf3gnuchains/gcc-fork.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 --  pragma Thread_Body is currently supported for:
38 --  VxWorks AE653 with the restricted / cert runtime
39
40 with Ada.Exceptions;
41 --  used for Exception_Occurrence
42
43 with System.Soft_Links;
44 --  used for TSD
45
46 package System.Threads is
47
48    subtype EO is Ada.Exceptions.Exception_Occurrence;
49
50    subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
51
52    type ATSD is limited private;
53    --  Type of the Ada thread specific data. It contains datas needed
54    --  by the GNAT runtime.
55
56    type ATSD_Access is access ATSD;
57
58    --  Get/Set for the attributes of the current thread
59
60    function  Get_Jmpbuf_Address return  Address;
61    pragma Inline (Get_Jmpbuf_Address);
62
63    procedure Set_Jmpbuf_Address (Addr : Address);
64    pragma Inline (Get_Jmpbuf_Address);
65
66    function  Get_Sec_Stack_Addr return  Address;
67    pragma Inline (Get_Sec_Stack_Addr);
68
69    procedure Set_Sec_Stack_Addr (Addr : Address);
70    pragma Inline (Set_Sec_Stack_Addr);
71
72    function Get_Current_Excep return EOA;
73    pragma Inline (Get_Current_Excep);
74
75    --------------------------
76    -- Thread Body Handling --
77    --------------------------
78
79    --  The subprograms in this section are called by the expansion of a
80    --  subprogram body to which a Thread_Body pragma has been applied:
81
82    --  Given a subprogram body
83
84    --     procedure xyz (params ....) is    -- can also be a function
85    --       <user declarations>
86    --     begin
87    --       <user statements>
88    --     <user exception handlers>
89    --     end xyz;
90
91    --  The expansion resulting from use of the Thread_Body pragma is:
92
93    --     procedure xyz (params ...) is
94
95    --       _Secondary_Stack : aliased
96    --          Storage_Elements.Storage_Array
97    --            (1 .. Storage_Offset (Sec_Stack_Size));
98    --       for _Secondary_Stack'Alignment use Standard'Maximum_Alignment;
99
100    --       _Process_ATSD : aliased System.Threads.ATSD;
101
102    --     begin
103    --        System.Threads.Thread_Body_Enter;
104    --          (_Secondary_Stack'Address,
105    --           _Secondary_Stack'Length,
106    --           _Process_ATSD'Address);
107
108    --        declare
109    --           <user declarations>
110    --        begin
111    --           <user statements>
112    --        <user exception handlers>
113    --        end;
114
115    --       System.Threads.Thread_Body_Leave;
116
117    --     exception
118    --        when E : others =>
119    --          System.Threads.Thread_Body_Exceptional_Exit (E);
120    --     end;
121
122    --  Note the exception handler is omitted if pragma Restriction
123    --  No_Exception_Handlers is currently active.
124
125    --  Note: the secondary stack size (Sec_Stack_Size) comes either from
126    --  the pragma, if specified, or is the default value taken from
127    --  the declaration in System.Secondary_Stack.
128
129    procedure Thread_Body_Enter
130      (Sec_Stack_Address    : System.Address;
131       Sec_Stack_Size       : Natural;
132       Process_ATSD_Address : System.Address);
133    --  Enter thread body, see above for details
134
135    procedure Thread_Body_Leave;
136    --  Leave thread body (normally), see above for details
137
138    procedure Thread_Body_Exceptional_Exit
139      (EO : Ada.Exceptions.Exception_Occurrence);
140    --  Leave thread body (abnormally on exception), see above for details
141
142 private
143
144    type ATSD is new System.Soft_Links.TSD;
145
146 end System.Threads;