clock_nanosleep.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 defined(SINGLE_THREAD_P)
  31. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
  32. #else
  33. {
  34. int oldstate = LIBC_CANCEL_ASYNC ();
  35. r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
  36. rem);
  37. LIBC_CANCEL_RESET (oldstate);
  38. }
  39. #endif
  40. return (INTERNAL_SYSCALL_ERROR_P (r, err)
  41. ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
  42. }