clock_nanosleep.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2003-2018 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library; if not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #include <time.h>
  14. #include <errno.h>
  15. #include <cancel.h>
  16. #include <sys/syscall.h>
  17. #include "kernel-posix-cpu-timers.h"
  18. /* We can simply use the syscall. The CPU clocks are not supported
  19. with this function. */
  20. int
  21. clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
  22. struct timespec *rem)
  23. {
  24. INTERNAL_SYSCALL_DECL (err);
  25. int r;
  26. if (clock_id == CLOCK_THREAD_CPUTIME_ID)
  27. return EINVAL;
  28. if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
  29. clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
  30. if (SINGLE_THREAD_P)
  31. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_nanosleep_time64)
  32. r = INTERNAL_SYSCALL (clock_nanosleep_time64, err, 4, clock_id, flags, req, rem);
  33. #else
  34. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
  35. #endif
  36. else
  37. {
  38. #ifdef __NEW_THREADS
  39. int oldstate = LIBC_CANCEL_ASYNC ();
  40. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_nanosleep_time64)
  41. r = INTERNAL_SYSCALL (clock_nanosleep_time64, err, 4, clock_id, flags, req, rem);
  42. #else
  43. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
  44. rem);
  45. #endif
  46. LIBC_CANCEL_RESET (oldstate);
  47. #endif
  48. }
  49. return (INTERNAL_SYSCALL_ERROR_P (r, err)
  50. ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
  51. }