File : a-exetim-bb.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . E X E C U T I O N _ T I M E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2007-2012, 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 -- --
19 -- --
20 -- --
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 is the Bare Board version of this package
33
34 with Ada.Task_Identification; use Ada.Task_Identification;
35 with Ada.Unchecked_Conversion;
36
37 with System.Tasking;
38 with System.Task_Primitives.Operations;
39 with System.OS_Interface; use System.OS_Interface;
40
41 with System.BB.Execution_Time;
42 with System.BB.Time;
43 with System.BB.Threads;
44
45 package body Ada.Execution_Time is
46
47 package BB_Exec_Time renames System.BB.Execution_Time;
48
49 function To_CPU_Time is new Ada.Unchecked_Conversion
50 (System.BB.Time.Time, CPU_Time);
51 -- Function to change the view from System.BB.Time.Time (unsigned 64-bit)
52 -- to CPU_Time (unsigned 64-bit).
53 --
54 -- CPU_Time is derived from Ada.Real_Time.Time which is derived from
55 -- System.BB.Time.Time. So CPU_Time and System.BB.Time.Time are the same
56 -- type, but Ada.Real_Time.Time is private so we don't have visibility.
57
58 ---------
59 -- "+" --
60 ---------
61
62 function "+"
63 (Left : CPU_Time;
64 Right : Ada.Real_Time.Time_Span) return CPU_Time
65 is
66 use type Ada.Real_Time.Time;
67 begin
68 return CPU_Time (Ada.Real_Time.Time (Left) + Right);
69 end "+";
70
71 function "+"
72 (Left : Ada.Real_Time.Time_Span;
73 Right : CPU_Time) return CPU_Time
74 is
75 use type Ada.Real_Time.Time;
76 begin
77 return CPU_Time (Left + Ada.Real_Time.Time (Right));
78 end "+";
79
80 ---------
81 -- "-" --
82 ---------
83
84 function "-"
85 (Left : CPU_Time;
86 Right : Ada.Real_Time.Time_Span) return CPU_Time
87 is
88 use type Ada.Real_Time.Time;
89 begin
90 return CPU_Time (Ada.Real_Time.Time (Left) - Right);
91 end "-";
92
93 function "-"
94 (Left : CPU_Time;
95 Right : CPU_Time) return Ada.Real_Time.Time_Span
96 is
97 use type Ada.Real_Time.Time;
98 begin
99 return (Ada.Real_Time.Time (Left) - Ada.Real_Time.Time (Right));
100 end "-";
101
102 -----------
103 -- Clock --
104 -----------
105
106 function Clock
107 (T : Ada.Task_Identification.Task_Id :=
108 Ada.Task_Identification.Current_Task) return CPU_Time
109 is
110 function To_Task_Id is new Ada.Unchecked_Conversion
111 (Ada.Task_Identification.Task_Id, System.Tasking.Task_Id);
112
113 Th : System.BB.Threads.Thread_Id;
114 begin
115 if T = Ada.Task_Identification.Null_Task_Id then
116 raise Program_Error;
117 end if;
118
119 Th := System.Task_Primitives.Operations.Get_Thread_Id (To_Task_Id (T));
120
121 return To_CPU_Time (BB_Exec_Time.Thread_Clock (Th));
122 end Clock;
123
124 -----------
125 -- Split --
126 -----------
127
128 procedure Split
129 (T : CPU_Time;
130 SC : out Ada.Real_Time.Seconds_Count;
131 TS : out Ada.Real_Time.Time_Span)
132 is
133 use type Ada.Real_Time.Time;
134 begin
135 Ada.Real_Time.Split (Ada.Real_Time.Time (T), SC, TS);
136 end Split;
137
138 -------------
139 -- Time_Of --
140 -------------
141
142 function Time_Of
143 (SC : Ada.Real_Time.Seconds_Count;
144 TS : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero)
145 return CPU_Time
146 is
147 begin
148 return CPU_Time (Ada.Real_Time.Time_Of (SC, TS));
149 end Time_Of;
150
151 --------------------------
152 -- Clock_For_Interrupts --
153 --------------------------
154
155 function Clock_For_Interrupts return CPU_Time is
156 begin
157 return To_CPU_Time (BB_Exec_Time.Global_Interrupt_Clock);
158 end Clock_For_Interrupts;
159
160 end Ada.Execution_Time;