[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] rfifolock: add recursive FIFO lock
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] rfifolock: add recursive FIFO lock |
Date: |
Wed, 09 Oct 2013 13:36:05 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9 |
Il 09/10/2013 13:26, Stefan Hajnoczi ha scritto:
> On Wed, Oct 09, 2013 at 12:05:43PM +0200, Paolo Bonzini wrote:
>> Il 09/10/2013 11:55, Stefan Hajnoczi ha scritto:
>>> + /* Take a ticket */
>>> + unsigned int ticket = r->tail++;
>>> +
>>> + if (r->nesting > 0) {
>>> + if (qemu_thread_is_self(&r->owner_thread)) {
>>> + r->tail--; /* put ticket back, we're nesting */
>>> + } else {
>>
>> ticket is dead in the "nested" path, why not move it (and the increment)
>> directly after the else?
>
> The increment cannot be moved because there are 3 cases:
>
> 1. Uncontended lock: r->tail++
> 2. Recursive lock: do not change tail
> 3. Wait for contended lock: r->tail++
>
> Case #1 needs r->tail++ too.
>
> I find this approach clearest:
>
> if (r->nesting == 0) {
> /* Uncontended, just take a ticket */
> r->tail++;
> } else if (qemu_thread_is_self(&r->owner_thread)) {
> /* Recursive lock, no need to take a ticket */
> } else {
> /* Contended case, take a ticket and wait for it */
> unsigned int ticket = r->tail++;
>
> while (ticket != r->head) {
> ...
> }
> }
I like this one too.
Paolo
[Qemu-devel] [PATCH 2/2] aio: add aio_context_acquire() and aio_context_release(), Stefan Hajnoczi, 2013/10/09
Re: [Qemu-devel] [PATCH 0/2] aio: add aio_context_acquire() and aio_context_release(), Paolo Bonzini, 2013/10/09