4 * Copyright IBM, Corp. 2011
7 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
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.
14 #include "qemu/osdep.h"
15 #include "qemu/coroutine.h"
16 #include "qemu/timer.h"
17 #include "block/aio.h"
19 typedef struct CoSleepCB
{
24 static void co_sleep_cb(void *opaque
)
26 CoSleepCB
*sleep_cb
= opaque
;
28 aio_co_wake(sleep_cb
->co
);
31 void coroutine_fn
co_aio_sleep_ns(AioContext
*ctx
, QEMUClockType type
,
34 CoSleepCB sleep_cb
= {
35 .co
= qemu_coroutine_self(),
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
);