From 7cede5af5adf01ad26155061cc476aad0804d3fc Mon Sep 17 00:00:00 2001 From: "Michael K. Johnson" Date: Wed, 18 Jun 2003 12:12:45 +0000 Subject: optimize out unnecessary syscalls with 2.5 aio interface --- src/io_getevents.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/io_getevents.c b/src/io_getevents.c index 28d2e31..5b5ec1f 100644 --- a/src/io_getevents.c +++ b/src/io_getevents.c @@ -22,5 +22,36 @@ #include #include "syscall.h" -io_syscall5(int, io_getevents_0_4, io_getevents, io_context_t, ctx, long, min_nr, long, nr, struct io_event *, events, struct timespec *, timeout) +io_syscall5(static int, __io_getevents_0_4, io_getevents, io_context_t, ctx, long, min_nr, long, nr, struct io_event *, events, struct timespec *, timeout) + +#define AIO_RING_MAGIC 0xa10a10a1 + +/* Ben will hate me for this */ +struct aio_ring { + unsigned id; /* kernel internal index number */ + unsigned nr; /* number of io_events */ + unsigned head; + unsigned tail; + + unsigned magic; + unsigned compat_features; + unsigned incompat_features; + unsigned header_length; /* size of aio_ring */ +}; + +int io_getevents_0_4(io_context_t ctx, long min_nr, long nr, struct io_event * events, struct timespec * timeout) +{ + struct aio_ring *ring; + ring = (struct aio_ring*)ctx; + if (ring==NULL || ring->magic != AIO_RING_MAGIC) + goto do_syscall; + if (timeout!=NULL && timeout->tv_sec == 0 && timeout->tv_nsec == 0) { + if (ring->head == ring->tail) + return 0; + } + +do_syscall: + return __io_getevents_0_4(ctx, min_nr, nr, events, timeout); +} + DEFSYMVER(io_getevents_0_4, io_getevents, 0.4) -- cgit v1.2.1