From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUpGd-0002IX-Vr for qemu-devel@nongnu.org; Fri, 11 Oct 2013 22:49:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUpGT-0002nP-US for qemu-devel@nongnu.org; Fri, 11 Oct 2013 22:49:23 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:52343) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUpGT-0002n3-8s for qemu-devel@nongnu.org; Fri, 11 Oct 2013 22:49:13 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 12 Oct 2013 12:49:08 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 9EE6B3578052 for ; Sat, 12 Oct 2013 13:49:06 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r9C2W0cf7340520 for ; Sat, 12 Oct 2013 13:32:06 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r9C2mx0s016255 for ; Sat, 12 Oct 2013 13:49:00 +1100 Message-ID: <5258B899.6000301@linux.vnet.ibm.com> Date: Sat, 12 Oct 2013 10:48:57 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1381312531-28723-1-git-send-email-stefanha@redhat.com> <1381312531-28723-2-git-send-email-stefanha@redhat.com> <5257BD03.6010808@linux.vnet.ibm.com> <20131011133538.GA22465@stefanha-thinkpad.redhat.com> In-Reply-To: <20131011133538.GA22465@stefanha-thinkpad.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 , Paolo Bonzini , qemu-devel@nongnu.org, Michael Roth 于 2013/10/11 21:35, Stefan Hajnoczi 写道: > On Fri, Oct 11, 2013 at 04:55:31PM +0800, Wenchao Xia wrote: >>> +/* Recursive FIFO lock >>> + * >>> + * This lock provides more features than a plain mutex: >>> + * >>> + * 1. Fairness - enforces FIFO order. >>> + * 2. Nesting - can be taken recursively. >>> + * 3. Contention callback - optional, called when thread must wait. >>> + * >>> + * The recursive FIFO lock is heavyweight so prefer other synchronization >>> + * primitives if you do not need its features. >>> + */ >>> +typedef struct { >>> + QemuMutex lock; /* protects all fields */ >>> + >>> + /* FIFO order */ >>> + unsigned int head; /* active ticket number */ >>> + unsigned int tail; /* waiting ticket number */ >>> + QemuCond cond; /* used to wait for our ticket number */ >>> + >>> + /* Nesting */ >>> + QemuThread owner_thread; /* thread that currently has ownership */ >>> + unsigned int nesting; /* amount of nesting levels */ >>> + >>> + /* Contention callback */ >>> + void (*cb)(void *); /* called when thread must wait, with ->lock >>> + * held so it may not recursively lock/unlock >>> + */ >>> + void *cb_opaque; >>> +} RFifoLock; >>> + >> If you respin, the define can be moved to util/rfifolock.c, leave >> typedef struct RFifoLock RFifoLock; >> in header. > Then the struct cannot be embedded as a field, it would require heap > allocation of all RFifoLocks. > > This is why I chose to include the definition in the header file. > > Stefan > OK, it is not serious problem, the patch looks good to me.