* Use ppoll(2) where possible (Credit: Eric Wong)

* Reenable some additional unit tests



git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@610 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
mheily 2012-12-24 23:37:59 +00:00
parent a316fbb867
commit 3530b37e2a
3 changed files with 32 additions and 7 deletions

View File

@ -120,6 +120,7 @@ kq = Library.new(
if Platform.is_linux?
project.check_decl 'EPOLLRDHUP', :include => 'sys/epoll.h'
project.check_decl 'ppoll', :cflags => '#define _GNU_SOURCE', :include => '<poll.h>'
project.check_header('sys/epoll.h') or throw 'epoll is required'
@ -179,6 +180,16 @@ else
)
end
if project.check_header 'sys/event.h'
# TODO: test for non-standard kqueue things like EV_RECEIPT
# This will allow running the testsuite against the native
else
# Assume libkqueue
project.define 'HAVE_EVFILT_USER'
project.define 'HAVE_EV_RECEIPT'
project.define 'HAVE_EV_DISPATCH'
end
mc = Makeconf.new()
mc.configure(project)

View File

@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
# define _GNU_SOURCE
# include <poll.h>
#include "../common/private.h"
//XXX-FIXME TEMP
@ -90,25 +92,37 @@ linux_kevent_wait_hires(
struct kqueue *kq,
const struct timespec *timeout)
{
fd_set fds;
int n;
int epfd;
#if HAVE_DECL_PPOLL
struct pollfd fds;
dbg_printf("waiting for events (timeout=%ld sec %ld nsec)",
timeout->tv_sec, timeout->tv_nsec);
fds.fd = kqueue_epfd(kq);
fds.events = POLLIN;
n = ppoll(&fds, 1, timeout, NULL);
#else
int epfd;
fd_set fds;
dbg_printf("waiting for events (timeout=%ld sec %ld nsec)",
timeout->tv_sec, timeout->tv_nsec);
epfd = kqueue_epfd(kq);
FD_ZERO(&fds);
FD_SET(epfd, &fds);
n = pselect(epfd + 1, &fds, NULL , NULL, timeout, NULL);
#endif
if (n < 0) {
if (errno == EINTR) {
dbg_puts("signal caught");
return (-1);
}
dbg_perror("pselect(2)");
dbg_perror("ppoll(2) or pselect(2)");
return (-1);
}
return (n);
}
@ -120,13 +134,13 @@ linux_kevent_wait(
{
int timeout, nret;
/* Use pselect() if the timeout value is less than one millisecond. */
/* Use a high-resolution syscall if the timeout value is less than one millisecond. */
if (ts != NULL && ts->tv_sec == 0 && ts->tv_nsec > 0 && ts->tv_nsec < 1000000) {
nret = linux_kevent_wait_hires(kq, ts);
if (nret <= 0)
return (nret);
/* pselect() told us epoll_wait() should have ready events */
/* epoll_wait() should have ready events */
timeout = 0;
} else {
/* Convert timeout to the format used by epoll_wait() */

View File

@ -62,7 +62,7 @@ test_kevent_user_get_hires(struct test_context *ctx)
kev.fflags &= ~NOTE_FFCTRLMASK;
kev.fflags &= ~NOTE_TRIGGER;
kev.flags = EV_CLEAR;
kevent_get(&ret, ctx->kqfd); //FIXME: Shouldn't this be kevent_get_hires() ?
kevent_get_hires(&ret, ctx->kqfd);
kevent_cmp(&kev, &ret);
test_no_kevents(ctx->kqfd);