On 08/12/2017 16:13, Stefan Hajnoczi wrote: >> - qemu_mutex_lock(&pool->lock); >> + QEMU_LOCK_GUARD(QemuMutex, pool_guard, &pool->lock); >> if (pool->idle_threads == 0 && pool->cur_threads < pool->max_threads) { >> spawn_thread(pool); >> } >> QTAILQ_INSERT_TAIL(&pool->request_list, req, reqs); >> - qemu_mutex_unlock(&pool->lock); >> + qemu_lock_guard_unlock(&pool_guard); > Why not QEMU_WITH_LOCK()? Then you can get rid of the explicit unlock.
I agree that QEMU_WITH_LOCK_GUARD is better in this case. (IIRC I wrote this patch before coming up with the is_taken trick!). My main question for the series is what you think the balance should be between a more widely applicable API and a simpler one. Thanks, Paolo >> @@ -330,7 +326,7 @@ void thread_pool_free(ThreadPool *pool) >> >> assert(QLIST_EMPTY(&pool->head)); >> >> - qemu_mutex_lock(&pool->lock); >> + QEMU_LOCK_GUARD(QemuMutex, pool_guard, &pool->lock); >> >> /* Stop new threads from spawning */ >> qemu_bh_delete(pool->new_thread_bh); >> @@ -344,7 +340,7 @@ void thread_pool_free(ThreadPool *pool) >> qemu_cond_wait(&pool->worker_stopped, &pool->lock); >> } >> >> - qemu_mutex_unlock(&pool->lock); >> + qemu_lock_guard_unlock(&pool_guard); > Here too. I don't see the advantage of replacing a single lock/unlock > with QEMU_LOCK_GUARD/unlock, if it cannot be made shorter/safer then > it's fine to use QemuMutex directly.