1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . T A S K _ I N F O --
8 -- (Compiler Interface) --
12 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
14 -- GNAT is free software; you can redistribute it and/or modify it under --
15 -- terms of the GNU General Public License as published by the Free Soft- --
16 -- ware Foundation; either version 2, or (at your option) any later ver- --
17 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
20 -- for more details. You should have received a copy of the GNU General --
21 -- Public License distributed with GNAT; see file COPYING. If not, write --
22 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
23 -- MA 02111-1307, USA. --
25 -- As a special exception, if other files instantiate generics from this --
26 -- unit, or you link this unit with other files to produce an executable, --
27 -- this unit does not by itself cause the resulting executable to be --
28 -- covered by the GNU General Public License. This exception does not --
29 -- however invalidate any other reasons why the executable file might be --
30 -- covered by the GNU Public License. --
32 -- GNAT was originally developed by the GNAT team at New York University. --
33 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 ------------------------------------------------------------------------------
37 -- This package contains the definitions and routines associated with the
38 -- implementation of the Task_Info pragma. It is specialized appropriately
39 -- for targets that make use of this pragma.
41 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
42 -- Any changes to this interface may require corresponding compiler changes.
45 with System
.OS_Interface
;
46 with Unchecked_Deallocation
;
48 package System
.Task_Info
is
49 pragma Elaborate_Body
;
50 -- To ensure that a body is allowed
52 package OSI
renames System
.OS_Interface
;
54 -----------------------------------------
55 -- Implementation of Task_Info Feature --
56 -----------------------------------------
58 -- Pragma Task_Info allows an application to set the underlying
59 -- pthread scheduling attributes for a specific task.
65 type Thread_Scheduling_Scope
is
66 (PTHREAD_SCOPE_PROCESS
, PTHREAD_SCOPE_SYSTEM
);
68 for Thread_Scheduling_Scope
'Size use Interfaces
.C
.int
'Size;
70 type Thread_Scheduling_Inheritance
is
71 (PTHREAD_EXPLICIT_SCHED
, PTHREAD_INHERIT_SCHED
);
73 for Thread_Scheduling_Inheritance
'Size use Interfaces
.C
.int
'Size;
75 type Thread_Scheduling_Policy
is
76 (SCHED_FIFO
, -- The first-in-first-out real-time policy
77 SCHED_RR
, -- The round-robin real-time scheduling policy
78 SCHED_TS
); -- The timeshare earnings based scheduling policy
80 for Thread_Scheduling_Policy
'Size use Interfaces
.C
.int
'Size;
81 for Thread_Scheduling_Policy
use
86 function SCHED_OTHER
return Thread_Scheduling_Policy
renames SCHED_TS
;
88 No_Specified_Priority
: constant := -1;
90 subtype Thread_Scheduling_Priority
is Integer range
91 No_Specified_Priority
.. 255;
93 function Min
(Policy
: Interfaces
.C
.int
) return Interfaces
.C
.int
94 renames OSI
.sched_get_priority_min
;
96 function Max
(Policy
: Interfaces
.C
.int
) return Interfaces
.C
.int
97 renames OSI
.sched_get_priority_max
;
99 subtype FIFO_Priority
is Thread_Scheduling_Priority
range
100 Thread_Scheduling_Priority
(Min
(OSI
.SCHED_FIFO
)) ..
101 Thread_Scheduling_Priority
(Max
(OSI
.SCHED_FIFO
));
103 subtype RR_Priority
is Thread_Scheduling_Priority
range
104 Thread_Scheduling_Priority
(Min
(OSI
.SCHED_RR
)) ..
105 Thread_Scheduling_Priority
(Max
(OSI
.SCHED_RR
));
107 subtype TS_Priority
is Thread_Scheduling_Priority
range
108 Thread_Scheduling_Priority
(Min
(OSI
.SCHED_TS
)) ..
109 Thread_Scheduling_Priority
(Max
(OSI
.SCHED_TS
));
111 subtype OTHER_Priority
is Thread_Scheduling_Priority
range
112 Thread_Scheduling_Priority
(Min
(OSI
.SCHED_OTHER
)) ..
113 Thread_Scheduling_Priority
(Max
(OSI
.SCHED_OTHER
));
115 subtype CPU_Number
is Integer range -1 .. Integer'Last;
116 ANY_CPU
: constant CPU_Number
:= CPU_Number
'First;
118 type Thread_Attributes
is record
119 Scope
: Thread_Scheduling_Scope
:= PTHREAD_SCOPE_PROCESS
;
120 Inheritance
: Thread_Scheduling_Inheritance
:= PTHREAD_EXPLICIT_SCHED
;
121 Policy
: Thread_Scheduling_Policy
:= SCHED_RR
;
122 Priority
: Thread_Scheduling_Priority
:= No_Specified_Priority
;
123 Runon_CPU
: CPU_Number
:= ANY_CPU
;
126 Default_Thread_Attributes
: constant Thread_Attributes
:=
127 (PTHREAD_SCOPE_PROCESS
, PTHREAD_EXPLICIT_SCHED
, SCHED_RR
,
128 No_Specified_Priority
, ANY_CPU
);
130 type Task_Info_Type
is access all Thread_Attributes
;
132 type Task_Image_Type
is access String;
133 -- Used to generate a meaningful identifier for tasks that are variables
134 -- and components of variables.
136 procedure Free_Task_Image
is new
137 Unchecked_Deallocation
(String, Task_Image_Type
);
139 Unspecified_Task_Info
: constant Task_Info_Type
:= null;
140 -- Value passed to task in the absence of a Task_Info pragma
142 end System
.Task_Info
;