void aio_set_event_notifier(AioContext *ctx,

                            EventNotifier *e,

                            EventNotifierHandler *io_notify)

{

    AioHandler *node;



    QLIST_FOREACH(node, &ctx->aio_handlers, node) {

        if (node->e == e && !node->deleted) {

            break;

        }

    }



    /* Are we deleting the fd handler? */

    if (!io_notify) {

        if (node) {

            g_source_remove_poll(&ctx->source, &node->pfd);



            /* If the lock is held, just mark the node as deleted */

            if (ctx->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                /* Otherwise, delete it for real.  We can't just mark it as

                 * deleted because deleted nodes are only cleaned up after

                 * releasing the walking_handlers lock.

                 */

                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        if (node == NULL) {

            /* Alloc and insert if it's not already there */

            node = g_malloc0(sizeof(AioHandler));

            node->e = e;

            node->pfd.fd = (uintptr_t)event_notifier_get_handle(e);

            node->pfd.events = G_IO_IN;

            QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);



            g_source_add_poll(&ctx->source, &node->pfd);

        }

        /* Update handler with latest information */

        node->io_notify = io_notify;

    }



    aio_notify(ctx);

}

void aio_set_event_notifier(AioContext *ctx,

                            EventNotifier *e,

                            EventNotifierHandler *io_notify)

{

    AioHandler *node;



    QLIST_FOREACH(node, &ctx->aio_handlers, node) {

        if (node->e == e && !node->deleted) {

            break;

        }

    }



    

    if (!io_notify) {

        if (node) {

            g_source_remove_poll(&ctx->source, &node->pfd);



            

            if (ctx->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                







                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        if (node == NULL) {

            

            node = g_malloc0(sizeof(AioHandler));

            node->e = e;

            node->pfd.fd = (uintptr_t)event_notifier_get_handle(e);

            node->pfd.events = G_IO_IN;

            QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);



            g_source_add_poll(&ctx->source, &node->pfd);

        }

        

        node->io_notify = io_notify;

    }



    aio_notify(ctx);

}

void FUNC_0(AioContext *VAR_0,

                            EventNotifier *VAR_1,

                            EventNotifierHandler *VAR_2)

{

    AioHandler *node;



    QLIST_FOREACH(node, &VAR_0->aio_handlers, node) {

        if (node->VAR_1 == VAR_1 && !node->deleted) {

            break;

        }

    }



    

    if (!VAR_2) {

        if (node) {

            g_source_remove_poll(&VAR_0->source, &node->pfd);



            

            if (VAR_0->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                







                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        if (node == NULL) {

            

            node = g_malloc0(sizeof(AioHandler));

            node->VAR_1 = VAR_1;

            node->pfd.fd = (uintptr_t)event_notifier_get_handle(VAR_1);

            node->pfd.events = G_IO_IN;

            QLIST_INSERT_HEAD(&VAR_0->aio_handlers, node, node);



            g_source_add_poll(&VAR_0->source, &node->pfd);

        }

        

        node->VAR_2 = VAR_2;

    }



    aio_notify(VAR_0);

}

void FUNC_0(AioContext *VAR_0,
EventNotifier *VAR_1,
EventNotifierHandler *VAR_2)
{ AioHandler *node; QLIST_FOREACH(node, &VAR_0->aio_handlers, node) { if (node->VAR_1 == VAR_1 && !node->deleted) { break; } } if (!VAR_2) { if (node) { g_source_remove_poll(&VAR_0->source, &node->pfd); if (VAR_0->walking_handlers) { node->deleted = 1; node->pfd.revents = 0; } else { QLIST_REMOVE(node, node); g_free(node); } } } else { if (node == NULL) { node = g_malloc0(sizeof(AioHandler)); node->VAR_1 = VAR_1; node->pfd.fd = (uintptr_t)event_notifier_get_handle(VAR_1); node->pfd.events = G_IO_IN; QLIST_INSERT_HEAD(&VAR_0->aio_handlers, node, node); g_source_add_poll(&VAR_0->source, &node->pfd); } node->VAR_2 = VAR_2; } aio_notify(VAR_0); }