summaryrefslogtreecommitdiff
path: root/gcc/ada/a-exetim-posix.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/a-exetim-posix.adb')
-rw-r--r--gcc/ada/a-exetim-posix.adb28
1 files changed, 23 insertions, 5 deletions
diff --git a/gcc/ada/a-exetim-posix.adb b/gcc/ada/a-exetim-posix.adb
index 9dc709ac61f..9c7ad57166e 100644
--- a/gcc/ada/a-exetim-posix.adb
+++ b/gcc/ada/a-exetim-posix.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2007-2012, Free Software Foundation, Inc. --
+-- Copyright (C) 2007-2015, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -34,8 +34,9 @@
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Unchecked_Conversion;
-with System.OS_Constants; use System.OS_Constants;
+with System.Tasking;
with System.OS_Interface; use System.OS_Interface;
+with System.Task_Primitives.Operations; use System.Task_Primitives.Operations;
with Interfaces.C; use Interfaces.C;
@@ -97,14 +98,18 @@ package body Ada.Execution_Time is
(T : Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task) return CPU_Time
is
- TS : aliased timespec;
- Result : Interfaces.C.int;
+ TS : aliased timespec;
+ Clock_Id : aliased Interfaces.C.int;
+ Result : Interfaces.C.int;
function To_CPU_Time is
new Ada.Unchecked_Conversion (Duration, CPU_Time);
-- Time is equal to Duration (although it is a private type) and
-- CPU_Time is equal to Time.
+ function Convert_Ids is new
+ Ada.Unchecked_Conversion (Task_Id, System.Tasking.Task_Id);
+
function clock_gettime
(clock_id : Interfaces.C.int;
tp : access timespec)
@@ -112,13 +117,26 @@ package body Ada.Execution_Time is
pragma Import (C, clock_gettime, "clock_gettime");
-- Function from the POSIX.1b Realtime Extensions library
+ function pthread_getcpuclockid
+ (tid : Thread_Id;
+ clock_id : access Interfaces.C.int)
+ return int;
+ pragma Import (C, pthread_getcpuclockid, "pthread_getcpuclockid");
+ -- Function from the Thread CPU-Time Clocks option
+
begin
if T = Ada.Task_Identification.Null_Task_Id then
raise Program_Error;
+ else
+ -- Get the CPU clock for the task passed as parameter
+
+ Result := pthread_getcpuclockid
+ (Get_Thread_Id (Convert_Ids (T)), Clock_Id'Access);
+ pragma Assert (Result = 0);
end if;
Result := clock_gettime
- (clock_id => CLOCK_THREAD_CPUTIME_ID, tp => TS'Unchecked_Access);
+ (clock_id => Clock_Id, tp => TS'Unchecked_Access);
pragma Assert (Result = 0);
return To_CPU_Time (To_Duration (TS));