summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2016-07-16 18:38:21 +0200
committerMarek Olšák <[email protected]>2016-07-22 22:34:49 +0200
commit4cdc482283f87b2325d51f5d6369fa44434902ae (patch)
treeb6638e12c81c7c1ba18f0b95e8f0e4d6a243be43 /src/gallium
parent4da9f7e7ce3e5fc62336dc6f041a30aabd2cacdc (diff)
gallium/os: use CLOCK_MONOTONIC for sleeps (v2)
v2: handle EINTR, remove backslashes Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/auxiliary/os/os_time.c16
-rw-r--r--src/gallium/auxiliary/os/os_time.h4
2 files changed, 14 insertions, 6 deletions
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
index 3d2e4167222..e169139034c 100644
--- a/src/gallium/auxiliary/os/os_time.c
+++ b/src/gallium/auxiliary/os/os_time.c
@@ -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
diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h
index 9312e028809..ca0bdd5a0c4 100644
--- a/src/gallium/auxiliary/os/os_time.h
+++ b/src/gallium/auxiliary/os/os_time.h
@@ -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
/*