nanosleep.c 957 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * nanosleep() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <time.h>
  11. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  12. #include <sysdep-cancel.h>
  13. #include <pthreadP.h>
  14. #else
  15. #define SINGLE_THREAD_P 1
  16. #endif
  17. #define __NR___syscall_nanosleep __NR_nanosleep
  18. static inline _syscall2(int, __syscall_nanosleep, const struct timespec *, req,
  19. struct timespec *, rem);
  20. extern __typeof(nanosleep) __libc_nanosleep;
  21. int __libc_nanosleep(const struct timespec *req, struct timespec *rem)
  22. {
  23. if (SINGLE_THREAD_P)
  24. return __syscall_nanosleep(req, rem);
  25. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  26. int oldtype = LIBC_CANCEL_ASYNC ();
  27. int result = __syscall_nanosleep(req, rem);
  28. LIBC_CANCEL_RESET (oldtype);
  29. return result;
  30. #endif
  31. }
  32. weak_alias(__libc_nanosleep,nanosleep)
  33. libc_hidden_weak(nanosleep)