本文整理汇总了C++中VirtioBusClass::ioeventfd_assign方法的典型用法代码示例。如果您正苦于以下问题:C++ VirtioBusClass::ioeventfd_assign方法的具体用法?C++ VirtioBusClass::ioeventfd_assign怎么用?C++ VirtioBusClass::ioeventfd_assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VirtioBusClass
的用法示例。
在下文中一共展示了VirtioBusClass::ioeventfd_assign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_host_notifier_internal
/*
* This function handles both assigning the ioeventfd handler and
* registering it with the kernel.
* assign: register/deregister ioeventfd with the kernel
* set_handler: use the generic ioeventfd handler
*/
static int set_host_notifier_internal(DeviceState *proxy, VirtioBusState *bus,
int n, bool assign, bool set_handler)
{
VirtIODevice *vdev = virtio_bus_get_device(bus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(bus);
VirtQueue *vq = virtio_get_queue(vdev, n);
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
int r = 0;
if (assign) {
r = event_notifier_init(notifier, 1);
if (r < 0) {
error_report("%s: unable to init event notifier: %d", __func__, r);
return r;
}
virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
r = k->ioeventfd_assign(proxy, notifier, n, assign);
if (r < 0) {
error_report("%s: unable to assign ioeventfd: %d", __func__, r);
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
event_notifier_cleanup(notifier);
return r;
}
} else {
k->ioeventfd_assign(proxy, notifier, n, assign);
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
event_notifier_cleanup(notifier);
}
return r;
}
示例2: virtio_bus_set_host_notifier
/*
* This function switches ioeventfd on/off in the device.
* The caller must set or clear the handlers for the EventNotifier.
*/
int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
{
VirtIODevice *vdev = virtio_bus_get_device(bus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(bus);
DeviceState *proxy = DEVICE(BUS(bus)->parent);
VirtQueue *vq = virtio_get_queue(vdev, n);
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
int r = 0;
if (!k->ioeventfd_assign) {
return -ENOSYS;
}
if (assign) {
assert(!bus->ioeventfd_started);
r = event_notifier_init(notifier, 1);
if (r < 0) {
error_report("%s: unable to init event notifier: %s (%d)",
__func__, strerror(-r), r);
return r;
}
r = k->ioeventfd_assign(proxy, notifier, n, true);
if (r < 0) {
error_report("%s: unable to assign ioeventfd: %d", __func__, r);
goto cleanup_event_notifier;
}
return 0;
} else {
if (!bus->ioeventfd_started) {
return 0;
}
k->ioeventfd_assign(proxy, notifier, n, false);
}
cleanup_event_notifier:
/* Test and clear notifier after disabling event,
* in case poll callback didn't have time to run.
*/
virtio_queue_host_notifier_read(notifier);
event_notifier_cleanup(notifier);
return r;
}