This patch takes advantage of CLOCK_MONOTONIC (when calling clock_gettime)
when supported by the OS (so far, only AIX and FreeBSD. Linux only supports
it on recent systems, so this is not enabled for now), and defaults to
CLOCK_REALTIME when not available.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-09-15  Arnaud Charlet  <char...@adacore.com>

        * s-osinte-aix.ads, s-osinte-darwin.ads, s-osinte-freebsd.ads,
        s-osinte-hpux.ads, s-osinte-lynxos.ads, s-osinte-solaris-posix.ads,
        s-taprop-posix.adb (CLOCK_MONOTONIC): New constant.
        (CLOCK_REALTIME): Fix wrong value on some OSes.
        * s-taprop-posix.adb (Monotonic_Clock): Use CLOCK_MONOTONIC.

Index: s-osinte-aix.ads
===================================================================
--- s-osinte-aix.ads    (revision 178876)
+++ s-osinte-aix.ads    (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, 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- --
@@ -199,7 +199,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -539,7 +540,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new int;
-   CLOCK_REALTIME : constant clockid_t := 0;
+   CLOCK_REALTIME  : constant clockid_t := 9;
+   CLOCK_MONOTONIC : constant clockid_t := 10;
 
    type pthread_attr_t is new System.Address;
    pragma Convention (C, pthread_attr_t);
Index: s-osinte-darwin.ads
===================================================================
--- s-osinte-darwin.ads (revision 178876)
+++ s-osinte-darwin.ads (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, 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- --
@@ -185,7 +185,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -516,7 +517,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new int;
-   CLOCK_REALTIME : constant clockid_t := 0;
+   CLOCK_REALTIME  : constant clockid_t := 0;
+   CLOCK_MONOTONIC : constant clockid_t := CLOCK_REALTIME;
 
    --
    --  Darwin specific signal implementation
Index: s-osinte-freebsd.ads
===================================================================
--- s-osinte-freebsd.ads        (revision 178876)
+++ s-osinte-freebsd.ads        (working copy)
@@ -7,7 +7,7 @@
 --                                   S p e c                                --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, 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- --
@@ -202,7 +202,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -635,7 +636,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new int;
-   CLOCK_REALTIME : constant clockid_t := 0;
+   CLOCK_REALTIME  : constant clockid_t := 0;
+   CLOCK_MONOTONIC : constant clockid_t := 4;
 
    type pthread_t           is new System.Address;
    type pthread_attr_t      is new System.Address;
Index: s-osinte-hpux.ads
===================================================================
--- s-osinte-hpux.ads   (revision 178876)
+++ s-osinte-hpux.ads   (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --               Copyright (C) 1991-1994, Florida State University          --
---            Copyright (C) 1995-2010, Free Software Foundation, Inc.       --
+--            Copyright (C) 1995-2011, 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- --
@@ -182,7 +182,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -521,7 +522,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new int;
-   CLOCK_REALTIME : constant clockid_t := 1;
+   CLOCK_REALTIME  : constant clockid_t := 1;
+   CLOCK_MONOTONIC : constant clockid_t := CLOCK_REALTIME;
 
    type pthread_attr_t is new int;
    type pthread_condattr_t is new int;
Index: s-osinte-lynxos.ads
===================================================================
--- s-osinte-lynxos.ads (revision 178876)
+++ s-osinte-lynxos.ads (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, 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- --
@@ -199,7 +199,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -517,7 +518,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new unsigned_char;
-   CLOCK_REALTIME : constant clockid_t := 0;
+   CLOCK_REALTIME  : constant clockid_t := 1;
+   CLOCK_MONOTONIC : constant clockid_t := CLOCK_REALTIME;
 
    type st_attr_t is record
       stksize      : int;
Index: s-osinte-solaris-posix.ads
===================================================================
--- s-osinte-solaris-posix.ads  (revision 178876)
+++ s-osinte-solaris-posix.ads  (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, 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- --
@@ -189,7 +189,8 @@
 
    type clockid_t is private;
 
-   CLOCK_REALTIME : constant clockid_t;
+   CLOCK_REALTIME  : constant clockid_t;
+   CLOCK_MONOTONIC : constant clockid_t;
 
    function clock_gettime
      (clock_id : clockid_t;
@@ -512,7 +513,8 @@
    pragma Convention (C, timespec);
 
    type clockid_t is new int;
-   CLOCK_REALTIME : constant clockid_t := 0;
+   CLOCK_REALTIME  : constant clockid_t := 3;
+   CLOCK_MONOTONIC : constant clockid_t := CLOCK_REALTIME;
 
    type pthread_attr_t is record
       pthread_attrp : System.Address;
Index: s-taprop-posix.adb
===================================================================
--- s-taprop-posix.adb  (revision 178876)
+++ s-taprop-posix.adb  (working copy)
@@ -666,7 +666,7 @@
       Result : Interfaces.C.int;
    begin
       Result := clock_gettime
-        (clock_id => CLOCK_REALTIME, tp => TS'Unchecked_Access);
+        (clock_id => CLOCK_MONOTONIC, tp => TS'Unchecked_Access);
       pragma Assert (Result = 0);
       return To_Duration (TS);
    end Monotonic_Clock;

Reply via email to