From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTqeU-0006fl-Pv for qemu-devel@nongnu.org; Wed, 09 Oct 2013 06:06:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTqeL-0000gu-Na for qemu-devel@nongnu.org; Wed, 09 Oct 2013 06:05:58 -0400 Received: from mail-ee0-x233.google.com ([2a00:1450:4013:c00::233]:38911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTqeL-0000gc-G8 for qemu-devel@nongnu.org; Wed, 09 Oct 2013 06:05:49 -0400 Received: by mail-ee0-f51.google.com with SMTP id c1so271971eek.24 for ; Wed, 09 Oct 2013 03:05:48 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <52552A77.7030504@redhat.com> Date: Wed, 09 Oct 2013 12:05:43 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1381312531-28723-1-git-send-email-stefanha@redhat.com> <1381312531-28723-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1381312531-28723-2-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] rfifolock: add recursive FIFO lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , xiawenc@linux.vnet.ibm.com, qemu-devel@nongnu.org, Michael Roth 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? Otherwise, the code is very nice. It's very interesting that no pthread mutex is held in the rfifolock critical section, so that the thread that holds the next ticket has a chance to be woken up. Paolo