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