]> git.proxmox.com Git - mirror_qemu.git/commit - util/thread-pool.c
thread-pool: replace semaphore with condition variable
authorPaolo Bonzini <pbonzini@redhat.com>
Sat, 14 May 2022 06:50:11 +0000 (08:50 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 25 May 2022 19:26:13 +0000 (21:26 +0200)
commit900fa208f50623672a6f879374222a7fd4717791
treec69c05bc7c2031c08cc2c21bae67843e226c2614
parent3c7b72ddca9ce85a9d1e8a98fd0996b74597b5ae
thread-pool: replace semaphore with condition variable

Since commit f9fc8932b1 ("thread-posix: remove the posix semaphore
support", 2022-04-06) QemuSemaphore has its own mutex and condition
variable; this adds unnecessary overhead on I/O with small block sizes.

Check the QTAILQ directly instead of adding the indirection of a
semaphore's count.  Using a semaphore has not been necessary since
qemu_cond_timedwait was introduced; the new code has to be careful about
spurious wakeups but it is simpler, for example thread_pool_cancel does
not have to worry about synchronizing the semaphore count with the number
of elements of pool->request_list.

Note that the return value of qemu_cond_timedwait (0 for timeout, 1 for
signal or spurious wakeup) is different from that of qemu_sem_timedwait
(-1 for timeout, 0 for success).

Reported-by: Lukáš Doktor <ldoktor@redhat.com>
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Message-Id: <20220514065012.1149539-3-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/thread-pool.c