Browse files

upstream: aio

  • Loading branch information...
1 parent edd3396 commit 7627ed7924456c88d3e8631c2cddcc7d54107ffa @digit-android digit-android committed with digit-android Sep 9, 2010
Showing with 76 additions and 4 deletions.
  1. +34 −2 aio-android.c
  2. +34 −2 aio.c
  3. +8 −0 qemu-aio.h
View
36 aio-android.c
@@ -34,6 +34,7 @@ struct AioHandler
IOHandler *io_read;
IOHandler *io_write;
AioFlushHandler *io_flush;
+ AioProcessQueue *io_process_queue;
int deleted;
void *opaque;
QLIST_ENTRY(AioHandler) node;
@@ -56,6 +57,7 @@ int qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
+ AioProcessQueue *io_process_queue,
void *opaque)
{
AioHandler *node;
@@ -88,6 +90,7 @@ int qemu_aio_set_fd_handler(int fd,
node->io_read = io_read;
node->io_write = io_write;
node->io_flush = io_flush;
+ node->io_process_queue = io_process_queue;
node->opaque = opaque;
}
@@ -111,9 +114,31 @@ void qemu_aio_flush(void)
qemu_aio_wait();
QLIST_FOREACH(node, &aio_handlers, node) {
- ret |= node->io_flush(node->opaque);
+ if (node->io_flush) {
+ ret |= node->io_flush(node->opaque);
+ }
}
- } while (ret > 0);
+ } while (qemu_bh_poll() || ret > 0);
+}
+
+int qemu_aio_process_queue(void)
+{
+ AioHandler *node;
+ int ret = 0;
+
+ walking_handlers = 1;
+
+ QLIST_FOREACH(node, &aio_handlers, node) {
+ if (node->io_process_queue) {
+ if (node->io_process_queue(node->opaque)) {
+ ret = 1;
+ }
+ }
+ }
+
+ walking_handlers = 0;
+
+ return ret;
}
void qemu_aio_wait(void)
@@ -124,6 +149,13 @@ void qemu_aio_wait(void)
if (qemu_bh_poll())
return;
+ /*
+ * If there are callbacks left that have been queued, we need to call then.
+ * Return afterwards to avoid waiting needlessly in select().
+ */
+ if (qemu_aio_process_queue())
+ return;
+
looper = iolooper_new();
do {
View
36 aio.c
@@ -33,6 +33,7 @@ struct AioHandler
IOHandler *io_read;
IOHandler *io_write;
AioFlushHandler *io_flush;
+ AioProcessQueue *io_process_queue;
int deleted;
void *opaque;
QLIST_ENTRY(AioHandler) node;
@@ -55,6 +56,7 @@ int qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
+ AioProcessQueue *io_process_queue,
void *opaque)
{
AioHandler *node;
@@ -87,6 +89,7 @@ int qemu_aio_set_fd_handler(int fd,
node->io_read = io_read;
node->io_write = io_write;
node->io_flush = io_flush;
+ node->io_process_queue = io_process_queue;
node->opaque = opaque;
}
@@ -110,9 +113,31 @@ void qemu_aio_flush(void)
qemu_aio_wait();
QLIST_FOREACH(node, &aio_handlers, node) {
- ret |= node->io_flush(node->opaque);
+ if (node->io_flush) {
+ ret |= node->io_flush(node->opaque);
+ }
}
- } while (ret > 0);
+ } while (qemu_bh_poll() || ret > 0);
+}
+
+int qemu_aio_process_queue(void)
+{
+ AioHandler *node;
+ int ret = 0;
+
+ walking_handlers = 1;
+
+ QLIST_FOREACH(node, &aio_handlers, node) {
+ if (node->io_process_queue) {
+ if (node->io_process_queue(node->opaque)) {
+ ret = 1;
+ }
+ }
+ }
+
+ walking_handlers = 0;
+
+ return ret;
}
void qemu_aio_wait(void)
@@ -122,6 +147,13 @@ void qemu_aio_wait(void)
if (qemu_bh_poll())
return;
+ /*
+ * If there are callbacks left that have been queued, we need to call then.
+ * Return afterwards to avoid waiting needlessly in select().
+ */
+ if (qemu_aio_process_queue())
+ return;
+
do {
AioHandler *node;
fd_set rdfds, wrfds;
View
8 qemu-aio.h
@@ -35,6 +35,13 @@ void qemu_aio_flush(void);
* result of executing I/O completion or bh callbacks. */
void qemu_aio_wait(void);
+/*
+ * Runs all currently allowed AIO callbacks of completed requests. Returns 0
+ * if no requests were handled, non-zero if at least one request was
+ * processed.
+ */
+int qemu_aio_process_queue(void);
+
/* Register a file descriptor and associated callbacks. Behaves very similarly
* to qemu_set_fd_handler2. Unlike qemu_set_fd_handler2, these callbacks will
* be invoked when using either qemu_aio_wait() or qemu_aio_flush().
@@ -46,6 +53,7 @@ int qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
+ AioProcessQueue *io_process_queue,
void *opaque);
#endif

0 comments on commit 7627ed7

Please sign in to comment.