clock_nanosleep.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #if defined(__UCLIBC_USE_TIME64__)
  19. #include "internal/time64_helpers.h"
  20. #endif
  21. /* We can simply use the syscall. The CPU clocks are not supported
  22. with this function. */
  23. int
  24. clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
  25. struct timespec *rem)
  26. {
  27. INTERNAL_SYSCALL_DECL (err);
  28. int r;
  29. if (clock_id == CLOCK_THREAD_CPUTIME_ID)
  30. return EINVAL;
  31. if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
  32. clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
  33. if (SINGLE_THREAD_P)
  34. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_nanosleep_time64)
  35. r = INTERNAL_SYSCALL (clock_nanosleep_time64, err, 4, clock_id, flags, TO_TS64_P(req), rem);
  36. #else
  37. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
  38. #endif
  39. else
  40. {
  41. #ifdef __NEW_THREADS
  42. int oldstate = LIBC_CANCEL_ASYNC ();
  43. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_nanosleep_time64)
  44. r = INTERNAL_SYSCALL (clock_nanosleep_time64, err, 4, clock_id, flags, TO_TS64_P(req), rem);
  45. #else
  46. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
  47. rem);
  48. #endif
  49. LIBC_CANCEL_RESET (oldstate);
  50. #endif
  51. }
  52. return (INTERNAL_SYSCALL_ERROR_P (r, err)
  53. ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
  54. }