On 11/08/2017 11:36 AM, Stefan Hajnoczi wrote: >> This function uses timers and hence needs to know the event loop >> (#AioContext) to place the timer on. After the time elapses, the >> current coroutine will restart with the same #AioContext it is currently >> running in, even if that is different than the timer context passed to >> co_aio_sleep_ns(). > > These complicated semantics are a clue that the API should be > simplified. QEMU has changed since this function was first introduced. > Now we can do the following: > > void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) > { > AioContext *ctx = qemu_get_current_aio_context(); > 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); > } > > I don't see a reason for the caller to pass in an AioContext. > > Any objections? Will send a patch if this is okay.
Makes sense to me. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature