epoll.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * epoll_create() / epoll_ctl() / epoll_wait() 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 <sys/epoll.h>
  11. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  12. # include <sysdep-cancel.h>
  13. #else
  14. # define SINGLE_THREAD_P 1
  15. #endif
  16. /*
  17. * epoll_create()
  18. */
  19. #ifdef __NR_epoll_create
  20. _syscall1(int, epoll_create, int, size)
  21. #endif
  22. /*
  23. * epoll_create1()
  24. */
  25. #ifdef __NR_epoll_create1
  26. _syscall1(int, epoll_create1, int, flags)
  27. #endif
  28. /*
  29. * epoll_ctl()
  30. */
  31. #ifdef __NR_epoll_ctl
  32. _syscall4(int,epoll_ctl, int, epfd, int, op, int, fd, struct epoll_event *, event)
  33. #endif
  34. /*
  35. * epoll_wait()
  36. */
  37. #ifdef __NR_epoll_wait
  38. extern __typeof(epoll_wait) __libc_epoll_wait;
  39. int __libc_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
  40. {
  41. if (SINGLE_THREAD_P)
  42. return INLINE_SYSCALL(epoll_wait, 4, epfd, events, maxevents, timeout);
  43. # ifdef __UCLIBC_HAS_THREADS_NATIVE__
  44. else {
  45. int oldtype = LIBC_CANCEL_ASYNC ();
  46. int result = INLINE_SYSCALL(epoll_wait, 4, epfd, events, maxevents, timeout);
  47. LIBC_CANCEL_RESET (oldtype);
  48. return result;
  49. }
  50. # endif
  51. }
  52. weak_alias(__libc_epoll_wait, epoll_wait)
  53. #endif
  54. /*
  55. * epoll_pwait()
  56. */
  57. #ifdef __NR_epoll_pwait
  58. # include <signal.h>
  59. extern __typeof(epoll_pwait) __libc_epoll_pwait;
  60. int __libc_epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
  61. int timeout, const sigset_t *set)
  62. {
  63. int nsig = _NSIG / 8;
  64. if (SINGLE_THREAD_P)
  65. return INLINE_SYSCALL(epoll_pwait, 6, epfd, events, maxevents, timeout, set, nsig);
  66. # ifdef __UCLIBC_HAS_THREADS_NATIVE__
  67. else {
  68. int oldtype = LIBC_CANCEL_ASYNC ();
  69. int result = INLINE_SYSCALL(epoll_pwait, 6, epfd, events, maxevents, timeout, set, nsig);
  70. LIBC_CANCEL_RESET (oldtype);
  71. return result;
  72. }
  73. # endif
  74. }
  75. weak_alias(__libc_epoll_pwait, epoll_pwait)
  76. #endif