2012-01-18 18:40:40 +04:00
|
|
|
/*
|
|
|
|
* QEMU coroutine sleep
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:49:55 +03:00
|
|
|
#include "qemu/osdep.h"
|
2015-09-01 16:48:02 +03:00
|
|
|
#include "qemu/coroutine.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2013-10-24 11:01:14 +04:00
|
|
|
#include "block/aio.h"
|
2012-01-18 18:40:40 +04:00
|
|
|
|
|
|
|
typedef struct CoSleepCB {
|
|
|
|
QEMUTimer *ts;
|
|
|
|
Coroutine *co;
|
|
|
|
} CoSleepCB;
|
|
|
|
|
|
|
|
static void co_sleep_cb(void *opaque)
|
|
|
|
{
|
|
|
|
CoSleepCB *sleep_cb = opaque;
|
|
|
|
|
coroutine: move entry argument to qemu_coroutine_create
In practice the entry argument is always known at creation time, and
it is confusing that sometimes qemu_coroutine_enter is used with a
non-NULL argument to re-enter a coroutine (this happens in
block/sheepdog.c and tests/test-coroutine.c). So pass the opaque value
at creation time, for consistency with e.g. aio_bh_new.
Mostly done with the following semantic patch:
@ entry1 @
expression entry, arg, co;
@@
- co = qemu_coroutine_create(entry);
+ co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry2 @
expression entry, arg;
identifier co;
@@
- Coroutine *co = qemu_coroutine_create(entry);
+ Coroutine *co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry3 @
expression entry, arg;
@@
- qemu_coroutine_enter(qemu_coroutine_create(entry), arg);
+ qemu_coroutine_enter(qemu_coroutine_create(entry, arg));
@ reentry @
expression co;
@@
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
except for the aforementioned few places where the semantic patch
stumbled (as expected) and for test_co_queue, which would otherwise
produce an uninitialized variable warning.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2016-07-04 20:10:01 +03:00
|
|
|
qemu_coroutine_enter(sleep_cb->co);
|
2012-01-18 18:40:40 +04:00
|
|
|
}
|
|
|
|
|
2013-10-24 11:01:14 +04:00
|
|
|
void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
|
|
|
|
int64_t ns)
|
|
|
|
{
|
|
|
|
CoSleepCB sleep_cb = {
|
|
|
|
.co = qemu_coroutine_self(),
|
|
|
|
};
|
|
|
|
sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb);
|
|
|
|
timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns);
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
timer_del(sleep_cb.ts);
|
|
|
|
timer_free(sleep_cb.ts);
|
|
|
|
}
|