]> git.proxmox.com Git - mirror_qemu.git/blame - util/qemu-coroutine-sleep.c
target-i386: fix "info lapic" segfault on isapc
[mirror_qemu.git] / util / qemu-coroutine-sleep.c
CommitLineData
7e624667
SH
1/*
2 * QEMU coroutine sleep
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
aafd7584 14#include "qemu/osdep.h"
10817bf0 15#include "qemu/coroutine.h"
1de7afc9 16#include "qemu/timer.h"
3ab7bd19 17#include "block/aio.h"
7e624667
SH
18
19typedef struct CoSleepCB {
20 QEMUTimer *ts;
21 Coroutine *co;
22} CoSleepCB;
23
24static void co_sleep_cb(void *opaque)
25{
26 CoSleepCB *sleep_cb = opaque;
27
2f47da5f 28 aio_co_wake(sleep_cb->co);
7e624667
SH
29}
30
3ab7bd19
MK
31void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
32 int64_t ns)
33{
34 CoSleepCB sleep_cb = {
35 .co = qemu_coroutine_self(),
36 };
37 sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb);
38 timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns);
39 qemu_coroutine_yield();
40 timer_del(sleep_cb.ts);
41 timer_free(sleep_cb.ts);
42}