Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / xbt / xbt_os_time.c
index 854c09f..8cccbf0 100644 (file)
@@ -1,6 +1,6 @@
 /* xbt_os_time.c -- portable interface to time-related functions            */
 
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -80,7 +80,7 @@ double xbt_os_time(void)
   return (double) (time(NULL));
 #endif                          /* HAVE_GETTIMEOFDAY? */
 
-  return (double) (tv.tv_sec + tv.tv_usec / 1000000.0);
+  return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
 }
 
 void xbt_os_sleep(double sec)
@@ -91,14 +91,14 @@ void xbt_os_sleep(double sec)
 
 #elif HAVE_NANOSLEEP
   struct timespec ts;
-  ts.tv_sec sec;
-  ts.tv_nsec = (sec - floor(sec)) * 1e9;
+  ts.tv_sec  = (time_t)sec;
+  ts.tv_nsec = (long)((sec - floor(sec)) * 1e9);
   nanosleep (&ts, NULL);
 #else                           /* don't have nanosleep. Use select to sleep less than one second */
   struct timeval timeout;
 
-  timeout.tv_sec = (unsigned long) (sec);
-  timeout.tv_usec = (sec - floor(sec)) * 1000000;
+  timeout.tv_sec  = (long)sec;
+  timeout.tv_usec = (long)(sec - floor(sec)) * 1e6);
 
   select(0, NULL, NULL, NULL, &timeout);
 #endif
@@ -110,7 +110,7 @@ void xbt_os_sleep(double sec)
  * @brief This section describes many macros/functions that can serve as  an OS abstraction.
  */
 struct s_xbt_os_timer {
-#if HAVE_POSIX_GETTIME
+#if HAVE_POSIX_GETTIME && defined (_POSIX_THREAD_CPUTIME)
   struct timespec start;
   struct timespec stop;
   struct timespec elapse;
@@ -140,7 +140,7 @@ void xbt_os_timer_free(xbt_os_timer_t timer)
   free(timer);
 }
 
-double xbt_os_timer_elapsed(xbt_os_timer_t timer)
+double xbt_os_timer_elapsed(const_xbt_os_timer_t timer)
 {
 #if HAVE_POSIX_GETTIME && defined (_POSIX_THREAD_CPUTIME)
   return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) + ((double) timer->elapse.tv_sec ) +
@@ -231,6 +231,8 @@ void xbt_os_cputimer_start(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->start, &kernelTime, &userTime);
+#else
+# error The cpu timers of SimGrid do not seem to work on your platform.
 #endif
 }
 
@@ -251,6 +253,8 @@ void xbt_os_cputimer_resume(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->start, &kernelTime, &userTime);
+#else
+# error The cpu timers of SimGrid do not seem to work on your platform.
 #endif
 }
 
@@ -265,6 +269,8 @@ void xbt_os_cputimer_stop(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->stop, &kernelTime, &userTime);
+#else
+# error The cpu timers of SimGrid do not seem to work on your platform.
 #endif
 }
 
@@ -292,6 +298,8 @@ void xbt_os_threadtimer_start(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->start, &kernelTime, &userTime);
+#else
+# error The thread timers of SimGrid do not seem to work on your platform.
 #endif
 }
 
@@ -321,6 +329,8 @@ void xbt_os_threadtimer_resume(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->start, &kernelTime, &userTime);
+#else
+# error The thread timers of SimGrid do not seem to work on your platform.
 #endif
 }
 
@@ -342,5 +352,7 @@ void xbt_os_threadtimer_stop(xbt_os_timer_t timer)
   FILETIME creationTime, exitTime, kernelTime, userTime;
   GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime);
   w32_times_to_timeval(&timer->stop, &kernelTime, &userTime);
+#else
+# error The thread timers of SimGrid do not seem to work on your platform.
 #endif
 }