diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2021-05-17 12:05:47 +0200 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2021-05-21 18:22:33 +0100 |
commit | 29a6ea24eb85d8400df1607a9e11d0ef9ec5e88d (patch) | |
tree | 86dbfa59f1ceb9324ee7937f457ac906e6b81069 /include | |
parent | 1485f0c24cfbef7a542ce13d49e9f68e285c57d8 (diff) | |
download | qemu-29a6ea24eb85d8400df1607a9e11d0ef9ec5e88d.zip qemu-29a6ea24eb85d8400df1607a9e11d0ef9ec5e88d.tar.gz qemu-29a6ea24eb85d8400df1607a9e11d0ef9ec5e88d.tar.bz2 |
coroutine-sleep: replace QemuCoSleepState pointer with struct in the API
Right now, users of qemu_co_sleep_ns_wakeable are simply passing
a pointer to QemuCoSleepState by reference to the function. But
QemuCoSleepState really is just a Coroutine*; making the
content of the struct public is just as efficient and lets us
skip the user_state_pointer indirection.
Since the usage is changed, take the occasion to rename the
struct to QemuCoSleep.
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20210517100548.28806-6-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/coroutine.h | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c5d7742..82c0671 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -291,21 +291,22 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock); */ void qemu_co_rwlock_unlock(CoRwlock *lock); -typedef struct QemuCoSleepState QemuCoSleepState; +typedef struct QemuCoSleep { + Coroutine *to_wake; +} QemuCoSleep; /** - * Yield the coroutine for a given duration. During this yield, @sleep_state - * is set to an opaque pointer, which may be used for - * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the - * timer fires. Don't save the obtained value to other variables and don't call - * qemu_co_sleep_wake from another aio context. + * Yield the coroutine for a given duration. Initializes @w so that, + * during this yield, it can be passed to qemu_co_sleep_wake() to + * terminate the sleep. */ -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, - QemuCoSleepState **sleep_state); +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns); + static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) { - QemuCoSleepState *unused = NULL; - qemu_co_sleep_ns_wakeable(type, ns, &unused); + QemuCoSleep w = { 0 }; + qemu_co_sleep_ns_wakeable(&w, type, ns); } /** @@ -314,7 +315,7 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) * qemu_co_sleep_ns() and should be checked to be non-NULL before calling * qemu_co_sleep_wake(). */ -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state); +void qemu_co_sleep_wake(QemuCoSleep *w); /** * Yield until a file descriptor becomes readable |