qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 5/5] thread-pool: convert to use lock guards


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 5/5] thread-pool: convert to use lock guards
Date: Fri, 8 Dec 2017 19:12:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]