mirror of
https://github.com/mii443/qemu.git
synced 2025-12-16 17:18:49 +00:00
qemu-thread: Add qemu_cond_timedwait
The new function is needed to implement conditional sleep for CPU throttling. It's possible to reuse qemu_sem_timedwait, but it's more difficult than just add qemu_cond_timedwait. Also moved compute_abs_deadline function up the code to reuse it in qemu_cond_timedwait_impl win32. Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru> Message-Id: <20190909131335.16848-2-yury-kotov@yandex-team.ru> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
committed by
Paolo Bonzini
parent
7a3df11c2a
commit
3dcc9c6ec4
@@ -145,6 +145,23 @@ void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, con
|
||||
qemu_mutex_post_lock(mutex, file, line);
|
||||
}
|
||||
|
||||
bool qemu_cond_timedwait_impl(QemuCond *cond, QemuMutex *mutex, int ms,
|
||||
const char *file, const int line)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
assert(cond->initialized);
|
||||
trace_qemu_mutex_unlock(mutex, file, line);
|
||||
if (!SleepConditionVariableSRW(&cond->var, &mutex->lock, ms, 0)) {
|
||||
rc = GetLastError();
|
||||
}
|
||||
trace_qemu_mutex_locked(mutex, file, line);
|
||||
if (rc && rc != ERROR_TIMEOUT) {
|
||||
error_exit(rc, __func__);
|
||||
}
|
||||
return rc != ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
void qemu_sem_init(QemuSemaphore *sem, int init)
|
||||
{
|
||||
/* Manual reset. */
|
||||
|
||||
Reference in New Issue
Block a user