mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
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>
This commit is contained in:
parent
1485f0c24c
commit
29a6ea24eb
4 changed files with 40 additions and 44 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue