1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- G N A T . T H R E A D S --
11 -- Copyright (C) 1998-2000 Ada Core Technologies, Inc. --
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. --
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. --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 with Ada
.Task_Identification
; use Ada
.Task_Identification
;
36 with System
.Task_Primitives
.Operations
;
38 with System
.OS_Interface
;
39 with Unchecked_Conversion
;
41 package body GNAT
.Threads
is
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
);
57 pragma Priority
(Prio
);
58 pragma Storage_Size
(Stsz
);
63 Code
.all (To_Addr
(Current_Task
), Parm
);
66 type Tptr
is access Thread
;
72 function Create_Thread
76 Prio
: Integer) return System
.Address
80 function To_CP
is new Unchecked_Conversion
(Address
, Code_Proc
);
83 TP
:= new Thread
(Size
, Prio
, Parm
, To_CP
(Code
));
84 return To_Addr
(TP
'Identity);
91 procedure Destroy_Thread
(Id
: Address
) is
92 Tid
: Task_Id
:= To_Id
(Id
);
102 procedure Get_Thread
(Id
: Address
; Thread
: Address
) is
103 use System
.OS_Interface
;
106 for Thr
use at Thread
;
108 Thr
:= Task_Primitives
.Operations
.Get_Thread_Id
(To_Id
(Id
));