gallium/os: use CLOCK_MONOTONIC for sleeps (v2)
authorMarek Olšák <marek.olsak@amd.com>
Sat, 16 Jul 2016 16:38:21 +0000 (18:38 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 22 Jul 2016 20:34:49 +0000 (22:34 +0200)
v2: handle EINTR, remove backslashes

Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
src/gallium/auxiliary/os/os_time.c
src/gallium/auxiliary/os/os_time.h

index 3d2e4167222a5c31d978d31047fbaf4e51a2b164..e169139034ce7cfa80806a3e9eef93419d1b60df 100644 (file)
@@ -40,6 +40,7 @@
 #  include <time.h> /* timeval */
 #  include <sys/time.h> /* timeval */
 #  include <sched.h> /* sched_yield */
+#  include <errno.h>
 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
 #  include <windows.h>
 #else
@@ -81,19 +82,30 @@ os_time_get_nano(void)
 }
 
 
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
 
 void
 os_time_sleep(int64_t usecs)
 {
+#if defined(PIPE_OS_LINUX)
+   struct timespec time;
+   time.tv_sec = usecs / 1000000;
+   time.tv_nsec = (usecs % 1000000) * 1000;
+   while (clock_nanosleep(CLOCK_MONOTONIC, 0, &time, &time) == EINTR);
+
+#elif defined(PIPE_OS_UNIX)
+   usleep(usecs);
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
    DWORD dwMilliseconds = (DWORD) ((usecs + 999) / 1000);
    /* Avoid Sleep(O) as that would cause to sleep for an undetermined duration */
    if (dwMilliseconds) {
       Sleep(dwMilliseconds);
    }
+#else
+#  error Unsupported OS
+#endif
 }
 
-#endif
 
 
 int64_t
index 9312e028809ddc2bba6432488ba5f5534fb2ca7b..ca0bdd5a0c414f6da0acdfa421dae6e6411abbde 100644 (file)
@@ -70,12 +70,8 @@ os_time_get(void)
 /*
  * Sleep.
  */
-#if defined(PIPE_OS_UNIX)
-#define os_time_sleep(_usecs) usleep(_usecs)
-#else
 void
 os_time_sleep(int64_t usecs);
-#endif
 
 
 /*