cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / compat_epoll_pwait.h
blobd8cbdb9c006c292b2cc970544a9e9f119851e5e3
1 /*
2 * fake epoll_pwait() implemented using ppoll + epoll_wait.
3 * This is only for Linux 2.6.18 / glibc 2.5 systems (Enterprise distros :P)
5 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
6 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
7 */
9 #if !defined(HAVE_EPOLL_PWAIT) \
10 && defined(HAVE_PPOLL) && defined(HAVE_EPOLL_WAIT)
11 static int my_epoll_pwait(int epfd, struct epoll_event *events,
12 int maxevents, int timeout, const sigset_t *sigmask)
14 struct pollfd pfds = { .fd = epfd, .events = POLLIN };
15 int rc;
16 struct timespec ts;
17 struct timespec *tsp;
19 if (timeout < 0) {
20 tsp = NULL;
21 } else {
22 ts.tv_sec = timeout / 1000;
23 ts.tv_nsec = (timeout % 1000) * 1000000;
24 tsp = &ts;
27 /* wait on just the epoll descriptor itself */
28 rc = ppoll(&pfds, 1, tsp, sigmask);
29 if (rc < 0)
30 assert((errno == EINTR || errno == ENOMEM)
31 && "ppoll usage bug");
33 /* no sleep for the actual epoll call */
34 return rc > 0 ? epoll_wait(epfd, events, maxevents, 0) : 0;
36 #define epoll_pwait(epfd,events,maxevents,timeout,sigmask) \
37 my_epoll_pwait((epfd),(events),(maxevents),(timeout),(sigmask))
38 #endif /* epoll_pwait */