[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH 01/17] block: access copy_on_read with atomic op
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-block] [PATCH 01/17] block: access copy_on_read with atomic ops |
Date: |
Thu, 4 May 2017 13:51:20 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
On 04/05/2017 13:15, Stefan Hajnoczi wrote:
> On Thu, Apr 20, 2017 at 02:00:42PM +0200, Paolo Bonzini wrote:
>> void bdrv_disable_copy_on_read(BlockDriverState *bs)
>> {
>> - assert(bs->copy_on_read > 0);
>> - bs->copy_on_read--;
>> + assert(atomic_read(&bs->copy_on_read) > 0);
>> + atomic_dec(&bs->copy_on_read);
>> }
>
> To make this truly thread-safe:
>
> old = atomic_dec_fetch(&bs->copy_on_read);
> assert(old > 0);
Good point. It feels wrong to assert after the fact, but then so does
making the assertion not quite thread safe.
Paolo