1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                     S Y S T E M . T A S K _ I N F O                      --
6--                                                                          --
7--                                 B o d y                                  --
8--                                                                          --
9--          Copyright (C) 1992-2019, Free Software Foundation, Inc.         --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17--                                                                          --
18-- As a special exception under Section 7 of GPL version 3, you are granted --
19-- additional permissions described in the GCC Runtime Library Exception,   --
20-- version 3.1, as published by the Free Software Foundation.               --
21--                                                                          --
22-- You should have received a copy of the GNU General Public License and    --
23-- a copy of the GCC Runtime Library Exception along with this program;     --
24-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25-- <http://www.gnu.org/licenses/>.                                          --
26--                                                                          --
27-- GNAT was originally developed  by the GNAT team at  New York University. --
28-- Extensive contributions were provided by Ada Core Technologies Inc.      --
29--                                                                          --
30------------------------------------------------------------------------------
31
32--  This package body contains the routines associated with the implementation
33--  of the Task_Info pragma.
34
35--  This is the Solaris (native) version of this module
36
37package body System.Task_Info is
38
39   -----------------------------
40   -- Bound_Thread_Attributes --
41   -----------------------------
42
43   function Bound_Thread_Attributes return Thread_Attributes is
44   begin
45      return (False, True);
46   end Bound_Thread_Attributes;
47
48   function Bound_Thread_Attributes (CPU : CPU_Number)
49      return Thread_Attributes is
50   begin
51      return (True, True, CPU);
52   end Bound_Thread_Attributes;
53
54   ---------------------------------
55   -- New_Bound_Thread_Attributes --
56   ---------------------------------
57
58   function New_Bound_Thread_Attributes return Task_Info_Type is
59   begin
60      return new Thread_Attributes'(False, True);
61   end New_Bound_Thread_Attributes;
62
63   function New_Bound_Thread_Attributes (CPU : CPU_Number)
64      return Task_Info_Type is
65   begin
66      return new Thread_Attributes'(True, True, CPU);
67   end New_Bound_Thread_Attributes;
68
69   -----------------------------------
70   -- New_Unbound_Thread_Attributes --
71   -----------------------------------
72
73   function New_Unbound_Thread_Attributes return Task_Info_Type is
74   begin
75      return new Thread_Attributes'(False, False);
76   end New_Unbound_Thread_Attributes;
77
78   -------------------------------
79   -- Unbound_Thread_Attributes --
80   -------------------------------
81
82   function Unbound_Thread_Attributes return Thread_Attributes is
83   begin
84      return (False, False);
85   end Unbound_Thread_Attributes;
86
87   N_CPU : Natural := 0;
88   pragma Atomic (N_CPU);
89   --  Cache CPU number. Use pragma Atomic to avoid a race condition when
90   --  setting N_CPU in Number_Of_Processors below.
91
92   --------------------------
93   -- Number_Of_Processors --
94   --------------------------
95
96   function Number_Of_Processors return Positive is
97   begin
98      if N_CPU = 0 then
99         N_CPU := Natural
100           (OS_Interface.sysconf (OS_Interface.SC_NPROCESSORS_ONLN));
101      end if;
102
103      return N_CPU;
104   end Number_Of_Processors;
105
106end System.Task_Info;
107