aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libgfortran/ChangeLog7
-rw-r--r--libgfortran/intrinsics/dtime.c17
-rw-r--r--libgfortran/intrinsics/time_1.h6
3 files changed, 23 insertions, 7 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 848fc51..b1494ca 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-24 Steven G. Kargl <kargl@gcc.gnu.org>
+
+ PR fortran/41157
+ * dtime.c (dtime_sub): Fix computing time increment.
+ * time_1.h: Add <sys/types.h> header. Use RUSAGE_SELF macro instead
+ of a hardcoded 0.
+
2009-08-24 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* configure.ac (AC_PREREQ): Bump to 2.64.
diff --git a/libgfortran/intrinsics/dtime.c b/libgfortran/intrinsics/dtime.c
index 4b7000b..d1eb912 100644
--- a/libgfortran/intrinsics/dtime.c
+++ b/libgfortran/intrinsics/dtime.c
@@ -38,9 +38,10 @@ iexport_proto(dtime_sub);
void
dtime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
{
- static GFC_REAL_4 tu = 0.0, ts = 0.0, tt = 0.0;
GFC_REAL_4 *tp;
long user_sec, user_usec, system_sec, system_usec;
+ static long us = 0, uu = 0, ss = 0 , su = 0;
+ GFC_REAL_4 tu, ts, tt;
if (((GFC_DESCRIPTOR_EXTENT(t,0))) < 2)
runtime_error ("Insufficient number of elements in TARRAY.");
@@ -48,15 +49,19 @@ dtime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
__gthread_mutex_lock (&dtime_update_lock);
if (__time_1 (&user_sec, &user_usec, &system_sec, &system_usec) == 0)
{
- tu = (GFC_REAL_4)(user_sec + 1.e-6 * user_usec) - tu;
- ts = (GFC_REAL_4)(system_sec + 1.e-6 * system_usec) - ts;
+ tu = (GFC_REAL_4) ((user_sec - us) + 1.e-6 * (user_usec - uu));
+ ts = (GFC_REAL_4) ((system_sec - ss) + 1.e-6 * (system_usec - su));
tt = tu + ts;
+ us = user_sec;
+ uu = user_usec;
+ ss = system_sec;
+ su = system_usec;
}
else
{
- tu = (GFC_REAL_4)-1.0;
- ts = (GFC_REAL_4)-1.0;
- tt = (GFC_REAL_4)-1.0;
+ tu = -1;
+ ts = -1;
+ tt = -1;
}
tp = t->data;
diff --git a/libgfortran/intrinsics/time_1.h b/libgfortran/intrinsics/time_1.h
index a93b7e0..03e14ed 100644
--- a/libgfortran/intrinsics/time_1.h
+++ b/libgfortran/intrinsics/time_1.h
@@ -51,6 +51,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
# endif
#endif
+#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+#endif
+
/* The most accurate way to get the CPU time is getrusage (). */
#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
# include <sys/resource.h>
@@ -112,7 +116,7 @@ __time_1 (long *user_sec, long *user_usec, long *system_sec, long *system_usec)
{
#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
struct rusage usage;
- getrusage (0, &usage);
+ getrusage (RUSAGE_SELF, &usage);
*user_sec = usage.ru_utime.tv_sec;
*user_usec = usage.ru_utime.tv_usec;