16.01.2019 2:29, Paolo Bonzini wrote:
> On 08/01/19 18:06, Vladimir Sementsov-Ogievskiy wrote:
>> Signed-off-by: Vladimir Sementsov-Ogievskiy
>> ---
>> block/qcow2-threads.c | 10 +++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
>> index 20b2616529..156e0667be 100644
>> --- a/block/qcow2-threads.c
>> +++ b/block/qcow2-threads.c
>> @@ -158,15 +158,19 @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest,
>> size_t dest_size,
>> .func = func,
>> };
>>
>> +qemu_co_mutex_lock(>lock);
>> while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
>> -qemu_co_queue_wait(>compress_wait_queue, NULL);
>> +qemu_co_queue_wait(>compress_wait_queue, >lock);
>> }
>> -
>> s->nb_compress_threads++;
>> +qemu_co_mutex_unlock(>lock);
>> +
>> thread_pool_submit_co(pool, qcow2_compress_pool_func, );
>> -s->nb_compress_threads--;
>>
>> +qemu_co_mutex_lock(>lock);
>> +s->nb_compress_threads--;
>> qemu_co_queue_next(>compress_wait_queue);
>> +qemu_co_mutex_unlock(>lock);
>>
>> return arg.ret;
>> }
>>
>
> Reviewed-by: Paolo Bonzini
>
> but, some information would be nice to have in the commit message.
Could you suggest one?
Just, "To make it thread-safe."? I don't have good understanding
of moving from "AioContext lock usage" to other locks, as well as
I don't know how BlockDriverState is going to be used in parallel
threads, and how much of other code is already prepared to work
in multiple-threads environment.
I looked through your commit messages on patches which added protection
to similar places about co-queues, but didn't find detailed description.
>
> Paolo
>
--
Best regards,
Vladimir