OSDN Git Service

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