qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 04/11] aio-win32: Implement aio_poll_clients


From: Fam Zheng
Subject: [Qemu-devel] [RFC PATCH 04/11] aio-win32: Implement aio_poll_clients
Date: Thu, 23 Jul 2015 14:32:11 +0800

This is the counterpart of for windows.

Signed-off-by: Fam Zheng <address@hidden>
---
 aio-win32.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/aio-win32.c b/aio-win32.c
index f5ecf57..c925085 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -149,7 +149,7 @@ void aio_set_event_notifier(AioContext *ctx,
     aio_notify(ctx);
 }
 
-bool aio_prepare(AioContext *ctx)
+static bool aio_prepare_clients(AioContext *ctx, int client_mask)
 {
     static struct timeval tv0;
     AioHandler *node;
@@ -160,6 +160,9 @@ bool aio_prepare(AioContext *ctx)
     FD_ZERO(&rfds);
     FD_ZERO(&wfds);
     QLIST_FOREACH(node, &ctx->aio_handlers, node) {
+        if ((node->type & client_mask) != node->type) {
+            continue;
+        }
         if (node->io_read) {
             FD_SET ((SOCKET)node->pfd.fd, &rfds);
         }
@@ -170,6 +173,9 @@ bool aio_prepare(AioContext *ctx)
 
     if (select(0, &rfds, &wfds, NULL, &tv0) > 0) {
         QLIST_FOREACH(node, &ctx->aio_handlers, node) {
+            if ((node->type & client_mask) != node->type) {
+                continue;
+            }
             node->pfd.revents = 0;
             if (FD_ISSET(node->pfd.fd, &rfds)) {
                 node->pfd.revents |= G_IO_IN;
@@ -186,6 +192,11 @@ bool aio_prepare(AioContext *ctx)
     return have_select_revents;
 }
 
+bool aio_prepare(AioContext *ctx)
+{
+    return aio_prepare_clients(ctx, AIO_CLIENT_MASK_ALL);
+}
+
 bool aio_pending(AioContext *ctx)
 {
     AioHandler *node;
@@ -206,7 +217,8 @@ bool aio_pending(AioContext *ctx)
     return false;
 }
 
-static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
+static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event,
+                                  int client_mask)
 {
     AioHandler *node;
     bool progress = false;
@@ -219,10 +231,11 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE 
event)
     while (node) {
         AioHandler *tmp;
         int revents = node->pfd.revents;
+        bool dispatch = (node->type & client_mask) == node->type;
 
         ctx->walking_handlers++;
 
-        if (!node->deleted &&
+        if (dispatch && !node->deleted &&
             (revents || event_notifier_get_handle(node->e) == event) &&
             node->io_notify) {
             node->pfd.revents = 0;
@@ -234,7 +247,7 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE 
event)
             }
         }
 
-        if (!node->deleted &&
+        if (dispatch && !node->deleted &&
             (node->io_read || node->io_write)) {
             node->pfd.revents = 0;
             if ((revents & G_IO_IN) && node->io_read) {
@@ -256,6 +269,7 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE 
event)
             }
         }
 
+next:
         tmp = node;
         node = QLIST_NEXT(node, node);
 
@@ -275,12 +289,13 @@ bool aio_dispatch(AioContext *ctx)
     bool progress;
 
     progress = aio_bh_poll(ctx);
-    progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
+    progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE,
+                                      AIO_CLIENT_MASK_ALL);
     progress |= timerlistgroup_run_timers(&ctx->tlg);
     return progress;
 }
 
-bool aio_poll(AioContext *ctx, bool blocking)
+bool aio_poll_clients(AioContext *ctx, bool blocking, int client_mask)
 {
     AioHandler *node;
     HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
@@ -302,13 +317,16 @@ bool aio_poll(AioContext *ctx, bool blocking)
         atomic_add(&ctx->notify_me, 2);
     }
 
-    have_select_revents = aio_prepare(ctx);
+    have_select_revents = aio_prepare_clients(ctx, client_mask);
 
     ctx->walking_handlers++;
 
     /* fill fd sets */
     count = 0;
     QLIST_FOREACH(node, &ctx->aio_handlers, node) {
+        if ((node->type & client_mask) != node->type) {
+            continue;
+        }
         if (!node->deleted && node->io_notify) {
             events[count++] = event_notifier_get_handle(node->e);
         }
@@ -360,7 +378,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
         have_select_revents = false;
         blocking = false;
 
-        progress |= aio_dispatch_handlers(ctx, event);
+        progress |= aio_dispatch_handlers(ctx, event, client_mask);
     } while (count > 0);
 
     progress |= timerlistgroup_run_timers(&ctx->tlg);
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]