]> git.proxmox.com Git - qemu.git/blame - qemu-coroutine-sleep.c
sheepdog: reload inode outside of resend_aioreq
[qemu.git] / 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
737e150e 14#include "block/coroutine.h"
1de7afc9 15#include "qemu/timer.h"
7e624667
SH
16
17typedef struct CoSleepCB {
18 QEMUTimer *ts;
19 Coroutine *co;
20} CoSleepCB;
21
22static void co_sleep_cb(void *opaque)
23{
24 CoSleepCB *sleep_cb = opaque;
25
7e624667
SH
26 qemu_coroutine_enter(sleep_cb->co, NULL);
27}
28
7483d1e5 29void coroutine_fn co_sleep_ns(QEMUClockType type, int64_t ns)
7e624667
SH
30{
31 CoSleepCB sleep_cb = {
32 .co = qemu_coroutine_self(),
33 };
7483d1e5
AB
34 sleep_cb.ts = timer_new(type, SCALE_NS, co_sleep_cb, &sleep_cb);
35 timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns);
7e624667 36 qemu_coroutine_yield();
7483d1e5
AB
37 timer_del(sleep_cb.ts);
38 timer_free(sleep_cb.ts);
7e624667 39}