1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . T A S K _ I N F O --
11 -- Copyright (C) 1992-2000 Free Software Foundation, 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 was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 -- This package contains the definitions and routines associated with the
37 -- implementation of the Task_Info pragma.
39 -- This is the Solaris (native) version of this module.
41 with System
.OS_Interface
;
42 with Unchecked_Deallocation
;
43 package System
.Task_Info
is
44 pragma Elaborate_Body
;
45 -- To ensure that a body is allowed
47 -----------------------------------------------------
48 -- Binding of Tasks to LWPs and LWPs to processors --
49 -----------------------------------------------------
51 -- The Solaris implementation of the GNU Low-Level Interface (GNULLI)
52 -- implements each Ada task as a Solaris thread. The Solaris thread
53 -- library distributes threads across one or more LWPs (Light Weight
54 -- Process) that are members of the same process. Solaris distributes
55 -- processes and LWPs across the available CPUs on a given machine. The
56 -- pragma Task_Info provides the mechanism to control the distribution
57 -- of tasks to LWPs, and LWPs to processors.
59 -- Each thread has a number of attributes that dictate it's scheduling.
60 -- These attributes are:
62 -- New_LWP: whether a new LWP is created for this thread.
64 -- Bound_To_LWP: whether the thread is bound to a specific LWP
65 -- for its entire lifetime.
67 -- CPU: the CPU number associated to the LWP
70 -- The Task_Info pragma:
72 -- pragma Task_Info (EXPRESSION);
74 -- allows the specification on a task by task basis of a value of type
75 -- System.Task_Info.Task_Info_Type to be passed to a task when it is
76 -- created. The specification of this type, and the effect on the task
77 -- that is created is target dependent.
79 -- The Task_Info pragma appears within a task definition (compare the
80 -- definition and implementation of pragma Priority). If no such pragma
81 -- appears, then the value Task_Info_Unspecified is passed. If a pragma
82 -- is present, then it supplies an alternative value. If the argument of
83 -- the pragma is a discriminant reference, then the value can be set on
84 -- a task by task basis by supplying the appropriate discriminant value.
86 -- Note that this means that the type used for Task_Info_Type must be
87 -- suitable for use as a discriminant (i.e. a scalar or access type).
89 -----------------------
90 -- Thread Attributes --
91 -----------------------
93 subtype CPU_Number
is System
.OS_Interface
.processorid_t
;
95 CPU_UNCHANGED
: constant CPU_Number
:= System
.OS_Interface
.PBIND_QUERY
;
96 -- Do not bind the LWP to a specific processor
98 ANY_CPU
: constant CPU_Number
:= System
.OS_Interface
.PBIND_NONE
;
99 -- Bind the LWP to any processor
101 Invalid_CPU_Number
: exception;
103 type Thread_Attributes
(New_LWP
: Boolean) is record
104 Bound_To_LWP
: Boolean := True;
109 CPU
: CPU_Number
:= CPU_UNCHANGED
;
113 Default_Thread_Attributes
: constant Thread_Attributes
:= (False, True);
115 function Unbound_Thread_Attributes
116 return Thread_Attributes
;
118 function Bound_Thread_Attributes
119 return Thread_Attributes
;
121 function Bound_Thread_Attributes
(CPU
: CPU_Number
)
122 return Thread_Attributes
;
124 type Task_Info_Type
is access all Thread_Attributes
;
126 function New_Unbound_Thread_Attributes
127 return Task_Info_Type
;
129 function New_Bound_Thread_Attributes
130 return Task_Info_Type
;
132 function New_Bound_Thread_Attributes
(CPU
: CPU_Number
)
133 return Task_Info_Type
;
135 type Task_Image_Type
is access String;
136 -- Used to generate a meaningful identifier for tasks that are variables
137 -- and components of variables.
139 procedure Free_Task_Image
is new
140 Unchecked_Deallocation
(String, Task_Image_Type
);
142 Unspecified_Task_Info
: constant Task_Info_Type
:= null;
144 end System
.Task_Info
;