* c-decl.c (duplicate_decls): Conditionalize DECL_SAVED_TREE copy.
[official-gcc.git] / gcc / ada / g-thread.adb
blobad6b754106d21542030eab353d14dc543f7f392c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- G N A T . T H R E A D S --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.6 $
10 -- --
11 -- Copyright (C) 1998-2000 Ada Core Technologies, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 with Ada.Task_Identification; use Ada.Task_Identification;
36 with System.Task_Primitives.Operations;
37 with System.Tasking;
38 with System.OS_Interface;
39 with Unchecked_Conversion;
41 package body GNAT.Threads is
43 use System;
45 function To_Addr is new Unchecked_Conversion (Task_Id, Address);
46 function To_Id is new Unchecked_Conversion (Address, Task_Id);
47 function To_Id is new Unchecked_Conversion (Address, Tasking.Task_ID);
49 type Code_Proc is access procedure (Id : Address; Parm : Void_Ptr);
51 task type Thread
52 (Stsz : Natural;
53 Prio : Any_Priority;
54 Parm : Void_Ptr;
55 Code : Code_Proc)
57 pragma Priority (Prio);
58 pragma Storage_Size (Stsz);
59 end Thread;
61 task body Thread is
62 begin
63 Code.all (To_Addr (Current_Task), Parm);
64 end Thread;
66 type Tptr is access Thread;
68 -------------------
69 -- Create_Thread --
70 -------------------
72 function Create_Thread
73 (Code : Address;
74 Parm : Void_Ptr;
75 Size : Natural;
76 Prio : Integer) return System.Address
78 TP : Tptr;
80 function To_CP is new Unchecked_Conversion (Address, Code_Proc);
82 begin
83 TP := new Thread (Size, Prio, Parm, To_CP (Code));
84 return To_Addr (TP'Identity);
85 end Create_Thread;
87 --------------------
88 -- Destroy_Thread --
89 --------------------
91 procedure Destroy_Thread (Id : Address) is
92 Tid : Task_Id := To_Id (Id);
94 begin
95 Abort_Task (Tid);
96 end Destroy_Thread;
98 ----------------
99 -- Get_Thread --
100 ----------------
102 procedure Get_Thread (Id : Address; Thread : Address) is
103 use System.OS_Interface;
105 Thr : Thread_Id;
106 for Thr use at Thread;
107 begin
108 Thr := Task_Primitives.Operations.Get_Thread_Id (To_Id (Id));
109 end Get_Thread;
111 end GNAT.Threads;