static void iothread_set_poll_param(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { IOThread *iothread = IOTHREAD(obj); PollParamInfo *info = opaque; int64_t *field = (void *)iothread + info->offset; Error *local_err = NULL; int64_t value; visit_type_int64(v, name, &value, &local_err); if (local_err) { goto out; } if (value < 0) { error_setg(&local_err, "%s value must be in range [0, %"PRId64"]", info->name, INT64_MAX); goto out; } *field = value; if (iothread->ctx) { aio_context_set_poll_params(iothread->ctx, iothread->poll_max_ns, iothread->poll_grow, iothread->poll_shrink, &local_err); } out: error_propagate(errp, local_err); }
static void iothread_complete(UserCreatable *obj, Error **errp) { Error *local_error = NULL; IOThread *iothread = IOTHREAD(obj); char *name, *thread_name; iothread->stopping = false; iothread->running = true; iothread->thread_id = -1; iothread->ctx = aio_context_new(&local_error); if (!iothread->ctx) { error_propagate(errp, local_error); return; } aio_context_set_poll_params(iothread->ctx, iothread->poll_max_ns, iothread->poll_grow, iothread->poll_shrink, &local_error); if (local_error) { error_propagate(errp, local_error); aio_context_unref(iothread->ctx); iothread->ctx = NULL; return; } qemu_mutex_init(&iothread->init_done_lock); qemu_cond_init(&iothread->init_done_cond); iothread->once = (GOnce) G_ONCE_INIT; /* This assumes we are called from a thread with useful CPU affinity for us * to inherit. */ name = object_get_canonical_path_component(OBJECT(obj)); thread_name = g_strdup_printf("IO %s", name); qemu_thread_create(&iothread->thread, thread_name, iothread_run, iothread, QEMU_THREAD_JOINABLE); g_free(thread_name); g_free(name); /* Wait for initialization to complete */ qemu_mutex_lock(&iothread->init_done_lock); while (iothread->thread_id == -1) { qemu_cond_wait(&iothread->init_done_cond, &iothread->init_done_lock); } qemu_mutex_unlock(&iothread->init_done_lock); }