GPollFD pfd;
IOHandler *io_read;
IOHandler *io_write;
- AioFlushHandler *io_flush;
int deleted;
int pollfds_idx;
void *opaque;
/* Update handler with latest information */
node->io_read = io_read;
node->io_write = io_write;
- node->io_flush = io_flush;
node->opaque = opaque;
node->pollfds_idx = -1;
(revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
node->io_read) {
node->io_read(node->opaque);
- progress = true;
+
+ /* aio_notify() does not count as progress */
+ if (node->opaque != &ctx->notifier) {
+ progress = true;
+ }
}
if (!node->deleted &&
(revents & (G_IO_OUT | G_IO_ERR)) &&
{
AioHandler *node;
int ret;
- bool busy, progress;
+ bool progress;
progress = false;
g_array_set_size(ctx->pollfds, 0);
/* fill pollfds */
- busy = false;
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
node->pollfds_idx = -1;
-
- /* If there aren't pending AIO operations, don't invoke callbacks.
- * Otherwise, if there are no AIO requests, qemu_aio_wait() would
- * wait indefinitely.
- */
- if (!node->deleted && node->io_flush) {
- if (node->io_flush(node->opaque) == 0) {
- continue;
- }
- busy = true;
- }
if (!node->deleted && node->pfd.events) {
GPollFD pfd = {
.fd = node->pfd.fd,
ctx->walking_handlers--;
- /* No AIO operations? Get us out of here */
- if (!busy) {
+ /* early return if we only have the aio_notify() fd */
+ if (ctx->pollfds->len == 1) {
return progress;
}
}
}
- assert(progress || busy);
- return true;
+ return progress;
}
struct AioHandler {
EventNotifier *e;
EventNotifierHandler *io_notify;
- AioFlushEventNotifierHandler *io_flush;
GPollFD pfd;
int deleted;
QLIST_ENTRY(AioHandler) node;
}
/* Update handler with latest information */
node->io_notify = io_notify;
- node->io_flush = io_flush;
}
aio_notify(ctx);
{
AioHandler *node;
HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
- bool busy, progress;
+ bool progress;
int count;
progress = false;
if (node->pfd.revents && node->io_notify) {
node->pfd.revents = 0;
node->io_notify(node->e);
- progress = true;
+
+ /* aio_notify() does not count as progress */
+ if (node->opaque != &ctx->notifier) {
+ progress = true;
+ }
}
tmp = node;
ctx->walking_handlers++;
/* fill fd sets */
- busy = false;
count = 0;
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
- /* If there aren't pending AIO operations, don't invoke callbacks.
- * Otherwise, if there are no AIO requests, qemu_aio_wait() would
- * wait indefinitely.
- */
- if (!node->deleted && node->io_flush) {
- if (node->io_flush(node->e) == 0) {
- continue;
- }
- busy = true;
- }
if (!node->deleted && node->io_notify) {
events[count++] = event_notifier_get_handle(node->e);
}
ctx->walking_handlers--;
- /* No AIO operations? Get us out of here */
- if (!busy) {
+ /* early return if we only have the aio_notify() fd */
+ if (count == 1) {
return progress;
}
event_notifier_get_handle(node->e) == events[ret - WAIT_OBJECT_0] &&
node->io_notify) {
node->io_notify(node->e);
- progress = true;
+
+ /* aio_notify() does not count as progress */
+ if (node->opaque != &ctx->notifier) {
+ progress = true;
+ }
}
tmp = node;
events[ret - WAIT_OBJECT_0] = events[--count];
}
- assert(progress || busy);
- return true;
+ return progress;
}
EventNotifierTestData data = { .n = 0, .active = 1 };
event_notifier_init(&data.e, false);
aio_set_event_notifier(ctx, &data.e, event_ready_cb, event_active_cb);
- g_assert(aio_poll(ctx, false));
+ g_assert(!aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 0);
g_assert_cmpint(data.active, ==, 1);
EventNotifierTestData data = { .n = 0, .active = 10, .auto_set = true };
event_notifier_init(&data.e, false);
aio_set_event_notifier(ctx, &data.e, event_ready_cb, event_active_cb);
- g_assert(aio_poll(ctx, false));
+ g_assert(!aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 0);
g_assert_cmpint(data.active, ==, 10);
/* Until there is an active descriptor, aio_poll may or may not call
* event_ready_cb. Still, it must not block. */
event_notifier_set(&data.e);
- g_assert(!aio_poll(ctx, true));
+ g_assert(aio_poll(ctx, true));
data.n = 0;
/* An active event notifier forces aio_poll to look at EventNotifiers. */
event_notifier_set(&data.e);
g_assert(aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 1);
- g_assert(aio_poll(ctx, false));
+ g_assert(!aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 1);
event_notifier_set(&data.e);
g_assert(aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 2);
- g_assert(aio_poll(ctx, false));
+ g_assert(!aio_poll(ctx, false));
g_assert_cmpint(data.n, ==, 2);
event_notifier_set(&dummy.e);