diff mbox series

[3/3] nptl: Refactor thrd_sleep in terms of clock_nanosleep

Message ID 20191106125245.28102-3-adhemerval.zanella@linaro.org
State Accepted
Commit 807edded258e888dbfa0d19ca967d6e42882d069
Headers show
Series [1/3] nptl: Move nanosleep implementation to libc | expand

Commit Message

Adhemerval Zanella Netto Nov. 6, 2019, 12:52 p.m. UTC
Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.
---
 nptl/thrd_sleep.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

-- 
2.17.1

Comments

Florian Weimer Nov. 6, 2019, 1:05 p.m. UTC | #1
* Adhemerval Zanella:

> Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.

> ---

>  nptl/thrd_sleep.c | 21 +++++++++------------

>  1 file changed, 9 insertions(+), 12 deletions(-)

>

> diff --git a/nptl/thrd_sleep.c b/nptl/thrd_sleep.c

> index 2e185dd748..3f5e307d56 100644

> --- a/nptl/thrd_sleep.c

> +++ b/nptl/thrd_sleep.c

> @@ -24,16 +24,13 @@

>  int

>  thrd_sleep (const struct timespec* time_point, struct timespec* remaining)

>  {

> -  INTERNAL_SYSCALL_DECL (err);

> -  int ret = INTERNAL_SYSCALL_CANCEL (nanosleep, err, time_point, remaining);

> -  if (INTERNAL_SYSCALL_ERROR_P (ret, err))

> -    {

> -      /* C11 states thrd_sleep function returns -1 if it has been interrupted

> -	 by a signal, or a negative value if it fails.  */

> -      ret = INTERNAL_SYSCALL_ERRNO (ret, err);

> -      if (ret == EINTR)

> -	return -1;

> -      return -2;

> -    }

> -  return 0;

> +  int ret = __clock_nanosleep (CLOCK_REALTIME, 0, time_point, remaining);

> +  /* C11 states thrd_sleep function returns -1 if it has been interrupted

> +     by a signal, or a negative value if it fails.  */

> +  switch (ret)

> +  {

> +     case 0:      return 0;

> +     case EINTR:  return -1;

> +     default:     return -2;

> +  }

>  }


This looks okay to me.

Thanks,
Florian
diff mbox series

Patch

diff --git a/nptl/thrd_sleep.c b/nptl/thrd_sleep.c
index 2e185dd748..3f5e307d56 100644
--- a/nptl/thrd_sleep.c
+++ b/nptl/thrd_sleep.c
@@ -24,16 +24,13 @@ 
 int
 thrd_sleep (const struct timespec* time_point, struct timespec* remaining)
 {
-  INTERNAL_SYSCALL_DECL (err);
-  int ret = INTERNAL_SYSCALL_CANCEL (nanosleep, err, time_point, remaining);
-  if (INTERNAL_SYSCALL_ERROR_P (ret, err))
-    {
-      /* C11 states thrd_sleep function returns -1 if it has been interrupted
-	 by a signal, or a negative value if it fails.  */
-      ret = INTERNAL_SYSCALL_ERRNO (ret, err);
-      if (ret == EINTR)
-	return -1;
-      return -2;
-    }
-  return 0;
+  int ret = __clock_nanosleep (CLOCK_REALTIME, 0, time_point, remaining);
+  /* C11 states thrd_sleep function returns -1 if it has been interrupted
+     by a signal, or a negative value if it fails.  */
+  switch (ret)
+  {
+     case 0:      return 0;
+     case EINTR:  return -1;
+     default:     return -2;
+  }
 }