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