资源简介
qemu是一个虚拟机,可用来运行xv6系统
代码片段和文件信息
/*
* QEMU aio implementation
*
* Copyright IBM Corp. 2008
* Copyright Red Hat Inc. 2012
*
* Authors:
* Anthony Liguori
* Paolo Bonzini
*
* This work is licensed under the terms of the GNU GPL version 2. See
* the COPYING file in the top-level directory.
*
* Contributions after 2012-01-13 are licensed under the terms of the
* GNU GPL version 2 or (at your option) any later version.
*/
#include “qemu-common.h“
#include “block/block.h“
#include “qemu/queue.h“
#include “qemu/sockets.h“
struct AioHandler {
EventNotifier *e;
IOHandler *io_read;
IOHandler *io_write;
EventNotifierHandler *io_notify;
GPollFD pfd;
int deleted;
void *opaque;
QLIST_ENTRY(AioHandler) node;
};
void aio_set_fd_handler(AioContext *ctx
int fd
IOHandler *io_read
IOHandler *io_write
void *opaque)
{
/* fd is a SOCKET in our case */
AioHandler *node;
QLIST_FOREACH(node &ctx->aio_handlers node) {
if (node->pfd.fd == fd && !node->deleted) {
break;
}
}
/* Are we deleting the fd handler? */
if (!io_read && !io_write) {
if (node) {
/* 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 {
HANDLE event;
if (node == NULL) {
/* Alloc and insert if it‘s not already there */
node = g_new0(AioHandler 1);
node->pfd.fd = fd;
QLIST_INSERT_HEAD(&ctx->aio_handlers node node);
}
node->pfd.events = 0;
if (node->io_read) {
node->pfd.events |= G_IO_IN;
}
if (node->io_write) {
node->pfd.events |= G_IO_OUT;
}
node->e = &ctx->notifier;
/* Update handler with latest information */
node->opaque = opaque;
node->io_read = io_read;
node->io_write = io_write;
event = event_notifier_get_handle(&ctx->notifier);
WSAEventSelect(node->pfd.fd event
FD_READ | FD_ACCEPT | FD_CLOSE |
FD_CONNECT | FD_WRITE | FD_OOB);
}
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;
评论
共有 条评论