qemu-char: Re-apply style fixes from just reverted aad04cd0
[qemu/agraf.git] / qemu-coroutine-sleep.c
blobfd6527444666c7f9d3e0f4ea919e55a31c1ca389
1 /*
2 * QEMU coroutine sleep
4 * Copyright IBM, Corp. 2011
6 * Authors:
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-coroutine.h"
15 #include "qemu-timer.h"
17 typedef struct CoSleepCB {
18 QEMUTimer *ts;
19 Coroutine *co;
20 } CoSleepCB;
22 static void co_sleep_cb(void *opaque)
24 CoSleepCB *sleep_cb = opaque;
26 qemu_free_timer(sleep_cb->ts);
27 qemu_coroutine_enter(sleep_cb->co, NULL);
30 void coroutine_fn co_sleep_ns(QEMUClock *clock, int64_t ns)
32 CoSleepCB sleep_cb = {
33 .co = qemu_coroutine_self(),
35 sleep_cb.ts = qemu_new_timer(clock, SCALE_NS, co_sleep_cb, &sleep_cb);
36 qemu_mod_timer(sleep_cb.ts, qemu_get_clock_ns(clock) + ns);
37 qemu_coroutine_yield();