epoll.c 2.0 KB

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