aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-05-17 12:05:43 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2021-05-21 18:22:33 +0100
commit5b33e015d38acb00340b8310a24c9998138afbe6 (patch)
tree61d4c60103900ce2a0afe316bdefba0f9b7e3f28 /util
parent5c6ae58d4bdca71f0b63e854ceb6a8ee67cbddd8 (diff)
coroutine-sleep: use a stack-allocated timer
The lifetime of the timer is well-known (it cannot outlive qemu_co_sleep_ns_wakeable, because it's deleted by the time the coroutine resumes), so it is not necessary to place it on the heap. Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210517100548.28806-2-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-coroutine-sleep.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
index 8c4dac4fd7..eec6e81f3f 100644
--- a/util/qemu-coroutine-sleep.c
+++ b/util/qemu-coroutine-sleep.c
@@ -21,7 +21,7 @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
struct QemuCoSleepState {
Coroutine *co;
- QEMUTimer *ts;
+ QEMUTimer ts;
QemuCoSleepState **user_state_pointer;
};
@@ -35,7 +35,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
if (sleep_state->user_state_pointer) {
*sleep_state->user_state_pointer = NULL;
}
- timer_del(sleep_state->ts);
+ timer_del(&sleep_state->ts);
aio_co_wake(sleep_state->co);
}
@@ -50,7 +50,6 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
AioContext *ctx = qemu_get_current_aio_context();
QemuCoSleepState state = {
.co = qemu_coroutine_self(),
- .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state),
.user_state_pointer = sleep_state,
};
@@ -63,10 +62,11 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
abort();
}
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
if (sleep_state) {
*sleep_state = &state;
}
- timer_mod(state.ts, qemu_clock_get_ns(type) + ns);
+ timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
qemu_coroutine_yield();
if (sleep_state) {
/*
@@ -75,5 +75,4 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
*/
assert(*sleep_state == NULL);
}
- timer_free(state.ts);
}