[Mesa-dev] [PATCH] gallium/os: use CLOCK_MONOTONIC for sleeps

Nicolai Hähnle nhaehnle at gmail.com
Tue Jul 19 14:21:55 UTC 2016


With Eric's backslash comment addressed:

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

On 18.07.2016 14:14, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
>   src/gallium/auxiliary/os/os_time.c | 15 +++++++++++++--
>   src/gallium/auxiliary/os/os_time.h |  4 ----
>   2 files changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
> index 3d2e416..633ee3d 100644
> --- a/src/gallium/auxiliary/os/os_time.c
> +++ b/src/gallium/auxiliary/os/os_time.c
> @@ -81,19 +81,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; \
> +   clock_nanosleep(CLOCK_MONOTONIC, 0, &time, NULL); \
> +
> +#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 9312e02..ca0bdd5 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
>
>
>   /*
>


More information about the mesa-dev mailing list