157
void qio_channel_set_aio_fd_handler(QIOChannel *ioc,
163
QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
165
klass->io_set_aio_fd_handler(ioc, ctx, io_read, io_write, opaque);
157
168
guint qio_channel_add_watch(QIOChannel *ioc,
158
169
GIOCondition condition,
159
170
QIOChannelFunc func,
230
typedef struct QIOChannelYieldData QIOChannelYieldData;
231
struct QIOChannelYieldData {
237
static gboolean qio_channel_yield_enter(QIOChannel *ioc,
238
GIOCondition condition,
241
QIOChannelYieldData *data = opaque;
242
qemu_coroutine_enter(data->co);
241
static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc);
243
static void qio_channel_restart_read(void *opaque)
245
QIOChannel *ioc = opaque;
246
Coroutine *co = ioc->read_coroutine;
248
ioc->read_coroutine = NULL;
249
qio_channel_set_aio_fd_handlers(ioc);
253
static void qio_channel_restart_write(void *opaque)
255
QIOChannel *ioc = opaque;
256
Coroutine *co = ioc->write_coroutine;
258
ioc->write_coroutine = NULL;
259
qio_channel_set_aio_fd_handlers(ioc);
263
static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc)
265
IOHandler *rd_handler = NULL, *wr_handler = NULL;
268
if (ioc->read_coroutine) {
269
rd_handler = qio_channel_restart_read;
271
if (ioc->write_coroutine) {
272
wr_handler = qio_channel_restart_write;
275
ctx = ioc->ctx ? ioc->ctx : iohandler_get_aio_context();
276
qio_channel_set_aio_fd_handler(ioc, ctx, rd_handler, wr_handler, ioc);
279
void qio_channel_attach_aio_context(QIOChannel *ioc,
283
if (ioc->ctx == ctx) {
287
old_ctx = ioc->ctx ? ioc->ctx : iohandler_get_aio_context();
288
qio_channel_set_aio_fd_handler(ioc, old_ctx, NULL, NULL, NULL);
290
qio_channel_set_aio_fd_handlers(ioc);
293
void qio_channel_detach_aio_context(QIOChannel *ioc)
295
ioc->read_coroutine = NULL;
296
ioc->write_coroutine = NULL;
297
qio_channel_set_aio_fd_handlers(ioc);
247
301
void coroutine_fn qio_channel_yield(QIOChannel *ioc,
248
302
GIOCondition condition)
250
QIOChannelYieldData data;
252
304
assert(qemu_in_coroutine());
254
data.co = qemu_coroutine_self();
255
qio_channel_add_watch(ioc,
257
qio_channel_yield_enter,
305
if (condition == G_IO_IN) {
306
assert(!ioc->read_coroutine);
307
ioc->read_coroutine = qemu_coroutine_self();
308
} else if (condition == G_IO_OUT) {
309
assert(!ioc->write_coroutine);
310
ioc->write_coroutine = qemu_coroutine_self();
314
qio_channel_set_aio_fd_handlers(ioc);
260
315
qemu_coroutine_yield();