summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael K. Johnson <johnsonm@redhat.com>2003-06-18 12:12:45 +0000
committerMichael K. Johnson <johnsonm@redhat.com>2003-06-18 12:12:45 +0000
commit7cede5af5adf01ad26155061cc476aad0804d3fc (patch)
treea9428c6a11ef706f6e0e88bea48bedc9d302ff35
parent9cf630e720a200114bb3234b23ec48cabb9834a5 (diff)
downloadlibaio-7cede5af5adf01ad26155061cc476aad0804d3fc.tar.gz
optimize out unnecessary syscalls with 2.5 aio interface
-rw-r--r--src/io_getevents.c33
1 files changed, 32 insertions, 1 deletions
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 <time.h>
#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)