@@ -329,8 +329,8 @@ int bdrv_create(BlockDriver *drv, const char* filename,
/* Fast-path if already in coroutine context */
bdrv_create_co_entry(&cco);
} else {
- co = qemu_coroutine_create(bdrv_create_co_entry);
- qemu_coroutine_enter(co, &cco);
+ co = qemu_coroutine_create(bdrv_create_co_entry, &cco);
+ qemu_coroutine_enter(co);
while (cco.ret == NOT_DONE) {
aio_poll(qemu_get_aio_context(), true);
}
@@ -575,9 +575,9 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
bdrv_op_block_all(target, job->common.blocker);
job->common.len = len;
- job->common.co = qemu_coroutine_create(backup_run);
+ job->common.co = qemu_coroutine_create(backup_run, job);
block_job_txn_add_job(txn, &job->common);
- qemu_coroutine_enter(job->common.co, job);
+ qemu_coroutine_enter(job->common.co);
return;
error:
@@ -620,7 +620,7 @@ static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) {
if (!strcmp(r->tag, tag)) {
- qemu_coroutine_enter(r->co, NULL);
+ qemu_coroutine_enter(r->co);
return 0;
}
}
@@ -646,7 +646,7 @@ static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
}
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) {
if (!strcmp(r->tag, tag)) {
- qemu_coroutine_enter(r->co, NULL);
+ qemu_coroutine_enter(r->co);
ret = 0;
}
}
@@ -65,7 +65,7 @@ static int64_t blkreplay_getlength(BlockDriverState *bs)
static void blkreplay_bh_cb(void *opaque)
{
Request *req = opaque;
- qemu_coroutine_enter(req->co, NULL);
+ qemu_coroutine_enter(req->co);
qemu_bh_delete(req->bh);
g_free(req);
}
@@ -836,8 +836,8 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
.ret = NOT_DONE,
};
- co = qemu_coroutine_create(co_entry);
- qemu_coroutine_enter(co, &rwco);
+ co = qemu_coroutine_create(co_entry, &rwco);
+ qemu_coroutine_enter(co);
aio_context = blk_get_aio_context(blk);
while (rwco.ret == NOT_DONE) {
@@ -945,8 +945,8 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
acb->bh = NULL;
acb->has_returned = false;
- co = qemu_coroutine_create(co_entry);
- qemu_coroutine_enter(co, acb);
+ co = qemu_coroutine_create(co_entry, acb);
+ qemu_coroutine_enter(co);
acb->has_returned = true;
if (acb->rwco.ret != NOT_DONE) {
@@ -277,8 +277,8 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
s->backing_file_str = g_strdup(backing_file_str);
s->on_error = on_error;
- s->common.co = qemu_coroutine_create(commit_run);
+ s->common.co = qemu_coroutine_create(commit_run, s);
trace_commit_start(bs, base, top, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co, s);
+ qemu_coroutine_enter(s->common.co);
}
@@ -233,7 +233,7 @@ static void qemu_gluster_complete_aio(void *opaque)
qemu_bh_delete(acb->bh);
acb->bh = NULL;
- qemu_coroutine_enter(acb->coroutine, NULL);
+ qemu_coroutine_enter(acb->coroutine);
}
/*
@@ -199,7 +199,7 @@ static void bdrv_co_drain_bh_cb(void *opaque)
qemu_bh_delete(data->bh);
bdrv_drain_poll(data->bs);
data->done = true;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
}
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs)
@@ -603,8 +603,8 @@ static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset,
} else {
AioContext *aio_context = bdrv_get_aio_context(bs);
- co = qemu_coroutine_create(bdrv_rw_co_entry);
- qemu_coroutine_enter(co, &rwco);
+ co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco);
+ qemu_coroutine_enter(co);
while (rwco.ret == NOT_DONE) {
aio_poll(aio_context, true);
}
@@ -803,7 +803,7 @@ static void bdrv_co_io_em_complete(void *opaque, int ret)
CoroutineIOCompletion *co = opaque;
co->ret = ret;
- qemu_coroutine_enter(co->coroutine, NULL);
+ qemu_coroutine_enter(co->coroutine);
}
static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
@@ -1743,8 +1743,9 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,
} else {
AioContext *aio_context = bdrv_get_aio_context(bs);
- co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry);
- qemu_coroutine_enter(co, &data);
+ co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry,
+ &data);
+ qemu_coroutine_enter(co);
while (!data.done) {
aio_poll(aio_context, true);
}
@@ -1892,9 +1893,9 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
.is_read = is_read,
.ret = -EINPROGRESS,
};
- Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry);
+ Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data);
- qemu_coroutine_enter(co, &data);
+ qemu_coroutine_enter(co);
while (data.ret == -EINPROGRESS) {
aio_poll(bdrv_get_aio_context(bs), true);
}
@@ -2103,8 +2104,8 @@ static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
acb->req.flags = flags;
acb->is_write = is_write;
- co = qemu_coroutine_create(bdrv_co_do_rw);
- qemu_coroutine_enter(co, acb);
+ co = qemu_coroutine_create(bdrv_co_do_rw, acb);
+ qemu_coroutine_enter(co);
bdrv_co_maybe_schedule_bh(acb);
return &acb->common;
@@ -2131,8 +2132,8 @@ BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs,
acb->need_bh = true;
acb->req.error = -EINPROGRESS;
- co = qemu_coroutine_create(bdrv_aio_flush_co_entry);
- qemu_coroutine_enter(co, acb);
+ co = qemu_coroutine_create(bdrv_aio_flush_co_entry, acb);
+ qemu_coroutine_enter(co);
bdrv_co_maybe_schedule_bh(acb);
return &acb->common;
@@ -2161,8 +2162,8 @@ BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs,
acb->req.error = -EINPROGRESS;
acb->req.sector = sector_num;
acb->req.nb_sectors = nb_sectors;
- co = qemu_coroutine_create(bdrv_aio_discard_co_entry);
- qemu_coroutine_enter(co, acb);
+ co = qemu_coroutine_create(bdrv_aio_discard_co_entry, acb);
+ qemu_coroutine_enter(co);
bdrv_co_maybe_schedule_bh(acb);
return &acb->common;
@@ -2297,8 +2298,8 @@ int bdrv_flush(BlockDriverState *bs)
} else {
AioContext *aio_context = bdrv_get_aio_context(bs);
- co = qemu_coroutine_create(bdrv_flush_co_entry);
- qemu_coroutine_enter(co, &rwco);
+ co = qemu_coroutine_create(bdrv_flush_co_entry, &rwco);
+ qemu_coroutine_enter(co);
while (rwco.ret == NOT_DONE) {
aio_poll(aio_context, true);
}
@@ -2424,8 +2425,8 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
} else {
AioContext *aio_context = bdrv_get_aio_context(bs);
- co = qemu_coroutine_create(bdrv_discard_co_entry);
- qemu_coroutine_enter(co, &rwco);
+ co = qemu_coroutine_create(bdrv_discard_co_entry, &rwco);
+ qemu_coroutine_enter(co);
while (rwco.ret == NOT_DONE) {
aio_poll(aio_context, true);
}
@@ -2487,9 +2488,9 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
/* Fast-path if already in coroutine context */
bdrv_co_ioctl_entry(&data);
} else {
- Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry);
+ Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry, &data);
- qemu_coroutine_enter(co, &data);
+ qemu_coroutine_enter(co);
while (data.ret == -EINPROGRESS) {
aio_poll(bdrv_get_aio_context(bs), true);
}
@@ -2517,8 +2518,8 @@ BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
acb->req.error = -EINPROGRESS;
acb->req.req = req;
acb->req.buf = buf;
- co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry);
- qemu_coroutine_enter(co, acb);
+ co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry, acb);
+ qemu_coroutine_enter(co);
bdrv_co_maybe_schedule_bh(acb);
return &acb->common;
@@ -153,7 +153,7 @@ static void iscsi_co_generic_bh_cb(void *opaque)
struct IscsiTask *iTask = opaque;
iTask->complete = 1;
qemu_bh_delete(iTask->bh);
- qemu_coroutine_enter(iTask->co, NULL);
+ qemu_coroutine_enter(iTask->co);
}
static void iscsi_retry_timer_expired(void *opaque)
@@ -161,7 +161,7 @@ static void iscsi_retry_timer_expired(void *opaque)
struct IscsiTask *iTask = opaque;
iTask->complete = 1;
if (iTask->co) {
- qemu_coroutine_enter(iTask->co, NULL);
+ qemu_coroutine_enter(iTask->co);
}
}
@@ -96,7 +96,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
laiocb->ret = ret;
if (laiocb->co) {
- qemu_coroutine_enter(laiocb->co, NULL);
+ qemu_coroutine_enter(laiocb->co);
} else {
laiocb->common.cb(laiocb->common.opaque, ret);
qemu_aio_unref(laiocb);
@@ -121,7 +121,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
g_free(op);
if (s->waiting_for_io) {
- qemu_coroutine_enter(s->common.co, NULL);
+ qemu_coroutine_enter(s->common.co);
}
}
@@ -900,9 +900,9 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
bdrv_op_block_all(target, s->common.blocker);
- s->common.co = qemu_coroutine_create(mirror_run);
+ s->common.co = qemu_coroutine_create(mirror_run, s);
trace_mirror_start(bs, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co, s);
+ qemu_coroutine_enter(s->common.co);
}
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
@@ -38,7 +38,7 @@ static void nbd_recv_coroutines_enter_all(NbdClientSession *s)
for (i = 0; i < MAX_NBD_REQUESTS; i++) {
if (s->recv_coroutine[i]) {
- qemu_coroutine_enter(s->recv_coroutine[i], NULL);
+ qemu_coroutine_enter(s->recv_coroutine[i]);
}
}
}
@@ -99,7 +99,7 @@ static void nbd_reply_ready(void *opaque)
}
if (s->recv_coroutine[i]) {
- qemu_coroutine_enter(s->recv_coroutine[i], NULL);
+ qemu_coroutine_enter(s->recv_coroutine[i]);
return;
}
@@ -111,7 +111,7 @@ static void nbd_restart_write(void *opaque)
{
BlockDriverState *bs = opaque;
- qemu_coroutine_enter(nbd_get_client_session(bs)->send_coroutine, NULL);
+ qemu_coroutine_enter(nbd_get_client_session(bs)->send_coroutine);
}
static int nbd_co_send_request(BlockDriverState *bs,
@@ -104,7 +104,7 @@ static void nfs_co_generic_bh_cb(void *opaque)
NFSRPC *task = opaque;
task->complete = 1;
qemu_bh_delete(task->bh);
- qemu_coroutine_enter(task->co, NULL);
+ qemu_coroutine_enter(task->co);
}
static void
@@ -708,7 +708,7 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l
}
if (cb->co) {
- qemu_coroutine_enter(cb->co, NULL);
+ qemu_coroutine_enter(cb->co);
}
}
@@ -1425,7 +1425,7 @@ static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret)
cb->done = true;
cb->ret = ret;
if (cb->co) {
- qemu_coroutine_enter(cb->co, NULL);
+ qemu_coroutine_enter(cb->co);
}
}
@@ -495,7 +495,7 @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req)
static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb)
{
- qemu_coroutine_enter(acb->coroutine, NULL);
+ qemu_coroutine_enter(acb->coroutine);
qemu_aio_unref(acb);
}
@@ -636,7 +636,7 @@ static void restart_co_req(void *opaque)
{
Coroutine *co = opaque;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
}
typedef struct SheepdogReqCo {
@@ -726,8 +726,8 @@ static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr,
if (qemu_in_coroutine()) {
do_co_req(&srco);
} else {
- co = qemu_coroutine_create(do_co_req);
- qemu_coroutine_enter(co, &srco);
+ co = qemu_coroutine_create(do_co_req, &srco);
+ qemu_coroutine_enter(co);
while (!srco.finished) {
aio_poll(aio_context, true);
}
@@ -925,17 +925,17 @@ static void co_read_response(void *opaque)
BDRVSheepdogState *s = opaque;
if (!s->co_recv) {
- s->co_recv = qemu_coroutine_create(aio_read_response);
+ s->co_recv = qemu_coroutine_create(aio_read_response, opaque);
}
- qemu_coroutine_enter(s->co_recv, opaque);
+ qemu_coroutine_enter(s->co_recv);
}
static void co_write_request(void *opaque)
{
BDRVSheepdogState *s = opaque;
- qemu_coroutine_enter(s->co_send, NULL);
+ qemu_coroutine_enter(s->co_send);
}
/*
@@ -777,7 +777,7 @@ static void restart_coroutine(void *opaque)
DPRINTF("co=%p", co);
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
}
static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs)
@@ -235,7 +235,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
s->backing_file_str = g_strdup(backing_file_str);
s->on_error = on_error;
- s->common.co = qemu_coroutine_create(stream_run);
+ s->common.co = qemu_coroutine_create(stream_run, s);
trace_stream_start(bs, base, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co, s);
+ qemu_coroutine_enter(s->common.co);
}
@@ -1690,8 +1690,8 @@ static int vmdk_write_compressed(BlockDriverState *bs,
.nb_sectors = nb_sectors,
.ret = -EINPROGRESS,
};
- co = qemu_coroutine_create(vmdk_co_write_compressed);
- qemu_coroutine_enter(co, &data);
+ co = qemu_coroutine_create(vmdk_co_write_compressed, &data);
+ qemu_coroutine_enter(co);
while (data.ret == -EINPROGRESS) {
aio_poll(aio_context, true);
}
@@ -346,7 +346,7 @@ void block_job_resume(BlockJob *job)
void block_job_enter(BlockJob *job)
{
if (job->co && !job->busy) {
- qemu_coroutine_enter(job->co, NULL);
+ qemu_coroutine_enter(job->co);
}
}
@@ -3278,8 +3278,8 @@ void pdu_submit(V9fsPDU *pdu)
if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) {
handler = v9fs_fs_ro;
}
- co = qemu_coroutine_create(handler);
- qemu_coroutine_enter(co, pdu);
+ co = qemu_coroutine_create(handler, pdu);
+ qemu_coroutine_enter(co);
}
/* Returns 0 on success, 1 on failure. */
@@ -22,14 +22,14 @@
static void coroutine_enter_cb(void *opaque, int ret)
{
Coroutine *co = opaque;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
}
/* Called from worker thread. */
static int coroutine_enter_func(void *arg)
{
Coroutine *co = arg;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
return 0;
}
@@ -61,16 +61,14 @@ typedef void coroutine_fn CoroutineEntry(void *opaque);
* Create a new coroutine
*
* Use qemu_coroutine_enter() to actually transfer control to the coroutine.
+ * The opaque argument is passed as the argument to the entry point.
*/
-Coroutine *qemu_coroutine_create(CoroutineEntry *entry);
+Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque);
/**
* Transfer control to a coroutine
- *
- * The opaque argument is passed as the argument to the entry point when
- * entering the coroutine for the first time. It is subsequently ignored.
*/
-void qemu_coroutine_enter(Coroutine *coroutine, void *opaque);
+void qemu_coroutine_enter(Coroutine *coroutine);
/**
* Transfer control back to a coroutine's caller
@@ -64,11 +64,11 @@ int qemu_init_main_loop(Error **errp);
*
* void enter_co_bh(void *opaque) {
* QEMUCoroutine *co = opaque;
- * qemu_coroutine_enter(co, NULL);
+ * qemu_coroutine_enter(co);
* }
*
* ...
- * QEMUCoroutine *co = qemu_coroutine_create(coroutine_entry);
+ * QEMUCoroutine *co = qemu_coroutine_create(coroutine_entry, NULL);
* QEMUBH *start_bh = qemu_bh_new(enter_co_bh, co);
* qemu_bh_schedule(start_bh);
* while (...) {
@@ -218,7 +218,7 @@ static gboolean qio_channel_yield_enter(QIOChannel *ioc,
gpointer opaque)
{
QIOChannelYieldData *data = opaque;
- qemu_coroutine_enter(data->co, NULL);
+ qemu_coroutine_enter(data->co);
return FALSE;
}
@@ -418,11 +418,11 @@ static void process_incoming_migration_co(void *opaque)
void migration_fd_process_incoming(QEMUFile *f)
{
- Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
+ Coroutine *co = qemu_coroutine_create(process_incoming_migration_co, f);
migrate_decompress_threads_create();
qemu_file_set_blocking(f, false);
- qemu_coroutine_enter(co, f);
+ qemu_coroutine_enter(co);
}
@@ -106,7 +106,7 @@ static gboolean nbd_negotiate_continue(QIOChannel *ioc,
GIOCondition condition,
void *opaque)
{
- qemu_coroutine_enter(opaque, NULL);
+ qemu_coroutine_enter(opaque);
return TRUE;
}
@@ -1230,9 +1230,9 @@ static void nbd_read(void *opaque)
NBDClient *client = opaque;
if (client->recv_coroutine) {
- qemu_coroutine_enter(client->recv_coroutine, NULL);
+ qemu_coroutine_enter(client->recv_coroutine);
} else {
- qemu_coroutine_enter(qemu_coroutine_create(nbd_trip), client);
+ qemu_coroutine_enter(qemu_coroutine_create(nbd_trip, client));
}
}
@@ -1240,7 +1240,7 @@ static void nbd_restart_write(void *opaque)
{
NBDClient *client = opaque;
- qemu_coroutine_enter(client->send_coroutine, NULL);
+ qemu_coroutine_enter(client->send_coroutine);
}
static void nbd_set_handlers(NBDClient *client)
@@ -1324,6 +1324,6 @@ void nbd_client_new(NBDExport *exp,
client->close = close_fn;
data->client = client;
- data->co = qemu_coroutine_create(nbd_co_client_start);
- qemu_coroutine_enter(data->co, data);
+ data->co = qemu_coroutine_create(nbd_co_client_start, data);
+ qemu_coroutine_enter(data->co);
}
@@ -483,8 +483,8 @@ static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
return -ERANGE;
}
- co = qemu_coroutine_create(co_pwrite_zeroes_entry);
- qemu_coroutine_enter(co, &data);
+ co = qemu_coroutine_create(co_pwrite_zeroes_entry, &data);
+ qemu_coroutine_enter(co);
while (!data.done) {
aio_poll(blk_get_aio_context(blk), true);
}
@@ -100,10 +100,10 @@ static BlockJob *test_block_job_start(unsigned int iterations,
s->use_timer = use_timer;
s->rc = rc;
s->result = result;
- s->common.co = qemu_coroutine_create(test_block_job_run);
+ s->common.co = qemu_coroutine_create(test_block_job_run, s);
data->job = s;
data->result = result;
- qemu_coroutine_enter(s->common.co, s);
+ qemu_coroutine_enter(s->common.co);
return &s->common;
}
@@ -30,8 +30,8 @@ static void test_in_coroutine(void)
g_assert(!qemu_in_coroutine());
- coroutine = qemu_coroutine_create(verify_in_coroutine);
- qemu_coroutine_enter(coroutine, NULL);
+ coroutine = qemu_coroutine_create(verify_in_coroutine, NULL);
+ qemu_coroutine_enter(coroutine);
}
/*
@@ -48,8 +48,8 @@ static void test_self(void)
{
Coroutine *coroutine;
- coroutine = qemu_coroutine_create(verify_self);
- qemu_coroutine_enter(coroutine, &coroutine);
+ coroutine = qemu_coroutine_create(verify_self, &coroutine);
+ qemu_coroutine_enter(coroutine);
}
/*
@@ -71,8 +71,8 @@ static void coroutine_fn nest(void *opaque)
if (nd->n_enter < nd->max) {
Coroutine *child;
- child = qemu_coroutine_create(nest);
- qemu_coroutine_enter(child, nd);
+ child = qemu_coroutine_create(nest, nd);
+ qemu_coroutine_enter(child);
}
nd->n_return++;
@@ -87,8 +87,8 @@ static void test_nesting(void)
.max = 128,
};
- root = qemu_coroutine_create(nest);
- qemu_coroutine_enter(root, &nd);
+ root = qemu_coroutine_create(nest, &nd);
+ qemu_coroutine_enter(root);
/* Must enter and return from max nesting level */
g_assert_cmpint(nd.n_enter, ==, nd.max);
@@ -116,9 +116,9 @@ static void test_yield(void)
bool done = false;
int i = -1; /* one extra time to return from coroutine */
- coroutine = qemu_coroutine_create(yield_5_times);
+ coroutine = qemu_coroutine_create(yield_5_times, &done);
while (!done) {
- qemu_coroutine_enter(coroutine, &done);
+ qemu_coroutine_enter(coroutine);
i++;
}
g_assert_cmpint(i, ==, 5); /* coroutine must yield 5 times */
@@ -132,7 +132,7 @@ static void coroutine_fn c2_fn(void *opaque)
static void coroutine_fn c1_fn(void *opaque)
{
Coroutine *c2 = opaque;
- qemu_coroutine_enter(c2, NULL);
+ qemu_coroutine_enter(c2);
}
static void test_co_queue(void)
@@ -140,12 +140,12 @@ static void test_co_queue(void)
Coroutine *c1;
Coroutine *c2;
- c1 = qemu_coroutine_create(c1_fn);
- c2 = qemu_coroutine_create(c2_fn);
+ c2 = qemu_coroutine_create(c2_fn, NULL);
+ c1 = qemu_coroutine_create(c1_fn, c2);
- qemu_coroutine_enter(c1, c2);
+ qemu_coroutine_enter(c1);
memset(c1, 0xff, sizeof(Coroutine));
- qemu_coroutine_enter(c2, NULL);
+ qemu_coroutine_enter(c2);
}
/*
@@ -165,14 +165,14 @@ static void test_lifecycle(void)
bool done = false;
/* Create, enter, and return from coroutine */
- coroutine = qemu_coroutine_create(set_and_exit);
- qemu_coroutine_enter(coroutine, &done);
+ coroutine = qemu_coroutine_create(set_and_exit, &done);
+ qemu_coroutine_enter(coroutine);
g_assert(done); /* expect done to be true (first time) */
/* Repeat to check that no state affects this test */
done = false;
- coroutine = qemu_coroutine_create(set_and_exit);
- qemu_coroutine_enter(coroutine, &done);
+ coroutine = qemu_coroutine_create(set_and_exit, &done);
+ qemu_coroutine_enter(coroutine);
g_assert(done); /* expect done to be true (second time) */
}
@@ -206,12 +206,12 @@ static void do_order_test(void)
{
Coroutine *co;
- co = qemu_coroutine_create(co_order_test);
+ co = qemu_coroutine_create(co_order_test, NULL);
record_push(1, 1);
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
record_push(1, 2);
g_assert(!qemu_in_coroutine());
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
record_push(1, 3);
g_assert(!qemu_in_coroutine());
}
@@ -248,8 +248,8 @@ static void perf_lifecycle(void)
g_test_timer_start();
for (i = 0; i < max; i++) {
- coroutine = qemu_coroutine_create(empty_coroutine);
- qemu_coroutine_enter(coroutine, NULL);
+ coroutine = qemu_coroutine_create(empty_coroutine, NULL);
+ qemu_coroutine_enter(coroutine);
}
duration = g_test_timer_elapsed();
@@ -272,8 +272,8 @@ static void perf_nesting(void)
.n_return = 0,
.max = maxnesting,
};
- root = qemu_coroutine_create(nest);
- qemu_coroutine_enter(root, &nd);
+ root = qemu_coroutine_create(nest, &nd);
+ qemu_coroutine_enter(root);
}
duration = g_test_timer_elapsed();
@@ -302,11 +302,11 @@ static void perf_yield(void)
maxcycles = 100000000;
i = maxcycles;
- Coroutine *coroutine = qemu_coroutine_create(yield_loop);
+ Coroutine *coroutine = qemu_coroutine_create(yield_loop, &i);
g_test_timer_start();
while (i > 0) {
- qemu_coroutine_enter(coroutine, &i);
+ qemu_coroutine_enter(coroutine);
}
duration = g_test_timer_elapsed();
@@ -352,9 +352,9 @@ static void perf_cost(void)
g_test_timer_start();
while (i++ < maxcycles) {
- co = qemu_coroutine_create(perf_cost_func);
- qemu_coroutine_enter(co, &i);
- qemu_coroutine_enter(co, NULL);
+ co = qemu_coroutine_create(perf_cost_func, &i);
+ qemu_coroutine_enter(co);
+ qemu_coroutine_enter(co);
}
duration = g_test_timer_elapsed();
ops = (long)(maxcycles / (duration * 1000));
@@ -91,9 +91,9 @@ static void co_test_cb(void *opaque)
static void test_submit_co(void)
{
WorkerTestData data;
- Coroutine *co = qemu_coroutine_create(co_test_cb);
+ Coroutine *co = qemu_coroutine_create(co_test_cb, &data);
- qemu_coroutine_enter(co, &data);
+ qemu_coroutine_enter(co);
/* Back here once the worker has started. */
@@ -267,7 +267,7 @@ static void thread_pool_co_cb(void *opaque, int ret)
ThreadPoolCo *co = opaque;
co->ret = ret;
- qemu_coroutine_enter(co->co, NULL);
+ qemu_coroutine_enter(co->co);
}
int coroutine_fn thread_pool_submit_co(ThreadPool *pool, ThreadPoolFunc *func,
@@ -75,7 +75,7 @@ static void fd_coroutine_enter(void *opaque)
{
FDYieldUntilData *data = opaque;
qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
- qemu_coroutine_enter(data->co, NULL);
+ qemu_coroutine_enter(data->co);
}
void coroutine_fn yield_until_fd_readable(int fd)
@@ -57,7 +57,7 @@ void qemu_co_queue_run_restart(Coroutine *co)
trace_qemu_co_queue_run_restart(co);
while ((next = QSIMPLEQ_FIRST(&co->co_queue_wakeup))) {
QSIMPLEQ_REMOVE_HEAD(&co->co_queue_wakeup, co_queue_next);
- qemu_coroutine_enter(next, NULL);
+ qemu_coroutine_enter(next);
}
}
@@ -103,7 +103,7 @@ bool qemu_co_enter_next(CoQueue *queue)
}
QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
- qemu_coroutine_enter(next, NULL);
+ qemu_coroutine_enter(next);
return true;
}
@@ -25,7 +25,7 @@ static void co_sleep_cb(void *opaque)
{
CoSleepCB *sleep_cb = opaque;
- qemu_coroutine_enter(sleep_cb->co, NULL);
+ qemu_coroutine_enter(sleep_cb->co);
}
void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
@@ -42,7 +42,7 @@ static void coroutine_pool_cleanup(Notifier *n, void *value)
}
}
-Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
+Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque)
{
Coroutine *co = NULL;
@@ -76,6 +76,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
}
co->entry = entry;
+ co->entry_arg = opaque;
QSIMPLEQ_INIT(&co->co_queue_wakeup);
return co;
}
@@ -100,12 +101,12 @@ static void coroutine_delete(Coroutine *co)
qemu_coroutine_delete(co);
}
-void qemu_coroutine_enter(Coroutine *co, void *opaque)
+void qemu_coroutine_enter(Coroutine *co)
{
Coroutine *self = qemu_coroutine_self();
CoroutineAction ret;
- trace_qemu_coroutine_enter(self, co, opaque);
+ trace_qemu_coroutine_enter(self, co, co->entry_arg);
if (co->caller) {
fprintf(stderr, "Co-routine re-entered recursively\n");
@@ -113,7 +114,6 @@ void qemu_coroutine_enter(Coroutine *co, void *opaque)
}
co->caller = self;
- co->entry_arg = opaque;
ret = qemu_coroutine_switch(self, co, COROUTINE_ENTER);
qemu_co_queue_run_restart(co);
In practice the entry argument is always known at creation time, and it is confusing that sometimes qemu_coroutine_enter is used with a non-NULL argument to re-enter a coroutine (this happens in block/sheepdog.c and tests/test-coroutine.c). So pass the opaque value at creation time, for consistency with e.g. aio_bh_new. Mostly done with the following semantic patch: @ entry1 @ expression entry, arg, co; @@ - co = qemu_coroutine_create(entry); + co = qemu_coroutine_create(entry, arg); ... - qemu_coroutine_enter(co, arg); + qemu_coroutine_enter(co); @ entry2 @ expression entry, arg; identifier co; @@ - Coroutine *co = qemu_coroutine_create(entry); + Coroutine *co = qemu_coroutine_create(entry, arg); ... - qemu_coroutine_enter(co, arg); + qemu_coroutine_enter(co); @ entry3 @ expression entry, arg; @@ - qemu_coroutine_enter(qemu_coroutine_create(entry), arg); + qemu_coroutine_enter(qemu_coroutine_create(entry, arg)); @ reentry @ expression co; @@ - qemu_coroutine_enter(co, NULL); + qemu_coroutine_enter(co); except for the aforementioned few places where the semantic patch stumbled (as expected) and for test_co_queue, which would otherwise produce an uninitialized variable warning. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- block.c | 4 +-- block/backup.c | 4 +-- block/blkdebug.c | 4 +-- block/blkreplay.c | 2 +- block/block-backend.c | 8 +++--- block/commit.c | 4 +-- block/gluster.c | 2 +- block/io.c | 45 ++++++++++++++++---------------- block/iscsi.c | 4 +-- block/linux-aio.c | 2 +- block/mirror.c | 6 ++--- block/nbd-client.c | 6 ++--- block/nfs.c | 2 +- block/qed.c | 4 +-- block/sheepdog.c | 14 +++++----- block/ssh.c | 2 +- block/stream.c | 4 +-- block/vmdk.c | 4 +-- blockjob.c | 2 +- hw/9pfs/9p.c | 4 +-- hw/9pfs/coth.c | 4 +-- include/qemu/coroutine.h | 8 +++--- include/qemu/main-loop.h | 4 +-- io/channel.c | 2 +- migration/migration.c | 4 +-- nbd/server.c | 12 ++++----- qemu-io-cmds.c | 4 +-- tests/test-blockjob-txn.c | 4 +-- tests/test-coroutine.c | 62 ++++++++++++++++++++++----------------------- tests/test-thread-pool.c | 4 +-- thread-pool.c | 2 +- util/qemu-coroutine-io.c | 2 +- util/qemu-coroutine-lock.c | 4 +-- util/qemu-coroutine-sleep.c | 2 +- util/qemu-coroutine.c | 8 +++--- 35 files changed, 126 insertions(+), 127 deletions(-)