orka_b455160b/orka/src/orka/implementation/orka-jobs-workers.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--  SPDX-License-Identifier: Apache-2.0
--
--  Copyright (c) 2017 onox <denkpadje@gmail.com>
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.

with System.Multiprocessors.Dispatching_Domains;

with Ada.Exceptions;
with Ada.Strings.Fixed;

with Orka.OS;

package body Orka.Jobs.Workers is

   task body Worker_Task is
      package SM renames System.Multiprocessors;
      package SF renames Ada.Strings.Fixed;

      use type SM.CPU;

      ID   : constant String := Data.ID'Image;
      Name : constant String := Task_Name & " #" & SF.Trim (ID, Ada.Strings.Left);
   begin
      --  Set the CPU affinity of the task to its corresponding CPU core
      SM.Dispatching_Domains.Set_CPU (SM.CPU (Data.ID) + 1);
      Orka.OS.Set_Task_Name (Name);

      Executors.Execute_Jobs (Name, Executors.Queues.CPU, Queue);
   exception
      when Error : others =>
         Orka.OS.Put_Line (Name & ": " & Ada.Exceptions.Exception_Information (Error));
   end Worker_Task;

   function Make_Workers return Worker_Array is
   begin
      return Result : Worker_Array (1 .. Positive (Count)) do
         for Index in Result'Range loop
            Result (Index).ID := Index;
         end loop;
      end return;
   end Make_Workers;

   procedure Shutdown is
   begin
      Queue.Shutdown;
   end Shutdown;

   Workers : constant Worker_Array := Make_Workers;

end Orka.Jobs.Workers;