annotate gcc/ada/libgnarl/g-thread.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . T H R E A D S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1998-2018, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with Ada.Task_Identification; use Ada.Task_Identification;
kono
parents:
diff changeset
33 with System.Task_Primitives.Operations;
kono
parents:
diff changeset
34 with System.Tasking;
kono
parents:
diff changeset
35 with System.Tasking.Stages; use System.Tasking.Stages;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
36 with System.Tasking.Utilities;
111
kono
parents:
diff changeset
37 with System.OS_Interface; use System.OS_Interface;
kono
parents:
diff changeset
38 with System.Soft_Links; use System.Soft_Links;
kono
parents:
diff changeset
39 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package body GNAT.Threads is
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 use System;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package STPO renames System.Task_Primitives.Operations;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 type Thread_Id_Ptr is access all Thread_Id;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 pragma Warnings (Off);
kono
parents:
diff changeset
50 -- The following unchecked conversions are aliasing safe, since they
kono
parents:
diff changeset
51 -- are never used to create pointers to improperly aliased data.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 function To_Addr is new Ada.Unchecked_Conversion (Task_Id, Address);
kono
parents:
diff changeset
54 function To_Id is new Ada.Unchecked_Conversion (Address, Task_Id);
kono
parents:
diff changeset
55 function To_Id is new Ada.Unchecked_Conversion (Address, Tasking.Task_Id);
kono
parents:
diff changeset
56 function To_Tid is new Ada.Unchecked_Conversion
kono
parents:
diff changeset
57 (Address, Ada.Task_Identification.Task_Id);
kono
parents:
diff changeset
58 function To_Thread is new Ada.Unchecked_Conversion (Address, Thread_Id_Ptr);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 pragma Warnings (On);
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 type Code_Proc is access procedure (Id : Address; Parm : Void_Ptr);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 task type Thread
kono
parents:
diff changeset
65 (Stsz : Natural;
kono
parents:
diff changeset
66 Prio : Any_Priority;
kono
parents:
diff changeset
67 Parm : Void_Ptr;
kono
parents:
diff changeset
68 Code : Code_Proc)
kono
parents:
diff changeset
69 is
kono
parents:
diff changeset
70 pragma Priority (Prio);
kono
parents:
diff changeset
71 pragma Storage_Size (Stsz);
kono
parents:
diff changeset
72 end Thread;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 task body Thread is
kono
parents:
diff changeset
75 begin
kono
parents:
diff changeset
76 Code.all (To_Addr (Current_Task), Parm);
kono
parents:
diff changeset
77 end Thread;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 type Tptr is access Thread;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -------------------
kono
parents:
diff changeset
82 -- Create_Thread --
kono
parents:
diff changeset
83 -------------------
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 function Create_Thread
kono
parents:
diff changeset
86 (Code : Address;
kono
parents:
diff changeset
87 Parm : Void_Ptr;
kono
parents:
diff changeset
88 Size : Natural;
kono
parents:
diff changeset
89 Prio : Integer) return System.Address
kono
parents:
diff changeset
90 is
kono
parents:
diff changeset
91 TP : Tptr;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 function To_CP is new Ada.Unchecked_Conversion (Address, Code_Proc);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 begin
kono
parents:
diff changeset
96 TP := new Thread (Size, Prio, Parm, To_CP (Code));
kono
parents:
diff changeset
97 return To_Addr (TP'Identity);
kono
parents:
diff changeset
98 end Create_Thread;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 ---------------------
kono
parents:
diff changeset
101 -- Register_Thread --
kono
parents:
diff changeset
102 ---------------------
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 function Register_Thread return System.Address is
kono
parents:
diff changeset
105 begin
kono
parents:
diff changeset
106 return Task_Primitives.Operations.Register_Foreign_Thread.all'Address;
kono
parents:
diff changeset
107 end Register_Thread;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 -----------------------
kono
parents:
diff changeset
110 -- Unregister_Thread --
kono
parents:
diff changeset
111 -----------------------
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 procedure Unregister_Thread is
kono
parents:
diff changeset
114 Self_Id : constant Tasking.Task_Id := Task_Primitives.Operations.Self;
kono
parents:
diff changeset
115 begin
kono
parents:
diff changeset
116 Self_Id.Common.State := Tasking.Terminated;
kono
parents:
diff changeset
117 Destroy_TSD (Self_Id.Common.Compiler_Data);
kono
parents:
diff changeset
118 Free_Task (Self_Id);
kono
parents:
diff changeset
119 end Unregister_Thread;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 --------------------------
kono
parents:
diff changeset
122 -- Unregister_Thread_Id --
kono
parents:
diff changeset
123 --------------------------
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 procedure Unregister_Thread_Id (Thread : System.Address) is
kono
parents:
diff changeset
126 Thr : constant Thread_Id := To_Thread (Thread).all;
kono
parents:
diff changeset
127 T : Tasking.Task_Id;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 use type Tasking.Task_Id;
kono
parents:
diff changeset
130 -- This use clause should be removed once a visibility problem
kono
parents:
diff changeset
131 -- with the MaRTE run time has been fixed. ???
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 pragma Warnings (Off);
kono
parents:
diff changeset
134 use type System.OS_Interface.Thread_Id;
kono
parents:
diff changeset
135 pragma Warnings (On);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 begin
kono
parents:
diff changeset
138 STPO.Lock_RTS;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 T := Tasking.All_Tasks_List;
kono
parents:
diff changeset
141 loop
kono
parents:
diff changeset
142 exit when T = null or else STPO.Get_Thread_Id (T) = Thr;
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 T := T.Common.All_Tasks_Link;
kono
parents:
diff changeset
145 end loop;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 STPO.Unlock_RTS;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 if T /= null then
kono
parents:
diff changeset
150 T.Common.State := Tasking.Terminated;
kono
parents:
diff changeset
151 Destroy_TSD (T.Common.Compiler_Data);
kono
parents:
diff changeset
152 Free_Task (T);
kono
parents:
diff changeset
153 end if;
kono
parents:
diff changeset
154 end Unregister_Thread_Id;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 --------------------
kono
parents:
diff changeset
157 -- Destroy_Thread --
kono
parents:
diff changeset
158 --------------------
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 procedure Destroy_Thread (Id : Address) is
kono
parents:
diff changeset
161 Tid : constant Task_Id := To_Id (Id);
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163 Abort_Task (Tid);
kono
parents:
diff changeset
164 end Destroy_Thread;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 ----------------
kono
parents:
diff changeset
167 -- Get_Thread --
kono
parents:
diff changeset
168 ----------------
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 procedure Get_Thread (Id : Address; Thread : Address) is
kono
parents:
diff changeset
171 Thr : constant Thread_Id_Ptr := To_Thread (Thread);
kono
parents:
diff changeset
172 begin
kono
parents:
diff changeset
173 Thr.all := Task_Primitives.Operations.Get_Thread_Id (To_Id (Id));
kono
parents:
diff changeset
174 end Get_Thread;
kono
parents:
diff changeset
175
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
176 ----------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
177 -- Make_Independent --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178 ----------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 function Make_Independent return Boolean is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 return System.Tasking.Utilities.Make_Independent;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183 end Make_Independent;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
184
111
kono
parents:
diff changeset
185 ----------------
kono
parents:
diff changeset
186 -- To_Task_Id --
kono
parents:
diff changeset
187 ----------------
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 function To_Task_Id
kono
parents:
diff changeset
190 (Id : System.Address) return Ada.Task_Identification.Task_Id
kono
parents:
diff changeset
191 is
kono
parents:
diff changeset
192 begin
kono
parents:
diff changeset
193 return To_Tid (Id);
kono
parents:
diff changeset
194 end To_Task_Id;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 end GNAT.Threads;