Received: from eggs.gnu.org ([208.118.235.92]:57033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UenBK-0005JE-79 for qemu-devel@nongnu.org; Tue, 21 May 2013 10:04:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UenBH-0001Im-Cq for qemu-devel@nongnu.org; Tue, 21 May 2013 10:04:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UenBH-0001IW-54 for qemu-devel@nongnu.org; Tue, 21 May 2013 10:04:47 -0400 Date: Tue, 21 May 2013 16:04:03 +0200 From: Stefan Hajnoczi Message-ID: <20130521140403.GC6650@stefanha-thinkpad.muc.redhat.com> References: <1367905622-21038-1-git-send-email-qemulist@gmail.com> <1367905622-21038-9-git-send-email-qemulist@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1367905622-21038-9-git-send-email-qemulist@gmail.com> Subject: Re: [Qemu-devel] [PATCH v1 08/14] net: introduce lock to protect NetQueue List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: mdroth , Jan Kiszka , qemu-devel@nongnu.org, Anthony Liguori , Paolo Bonzini On Tue, May 07, 2013 at 01:46:56PM +0800, Liu Ping Fan wrote: > From: Liu Ping Fan > > NetQueue will be accessed by nc and its peers at the same time, > need lock to protect it. > > Signed-off-by: Liu Ping Fan > --- > net/queue.c | 11 +++++++++++ > 1 files changed, 11 insertions(+), 0 deletions(-) > > diff --git a/net/queue.c b/net/queue.c > index 859d02a..2856c1d 100644 > --- a/net/queue.c > +++ b/net/queue.c > @@ -53,6 +53,7 @@ struct NetQueue { > uint32_t nq_maxlen; > uint32_t nq_count; > > + QemuMutex lock; > QTAILQ_HEAD(packets, NetPacket) packets; > > unsigned delivering : 1; > @@ -68,6 +69,7 @@ NetQueue *qemu_new_net_queue(void *opaque) > queue->nq_maxlen = 10000; > queue->nq_count = 0; > > + qemu_mutex_init(&queue->lock); > QTAILQ_INIT(&queue->packets); > > queue->delivering = 0; > @@ -107,7 +109,9 @@ static void qemu_net_queue_append(NetQueue *queue, > memcpy(packet->data, buf, size); > > queue->nq_count++; > + qemu_mutex_lock(&queue->lock); > QTAILQ_INSERT_TAIL(&queue->packets, packet, entry); > + qemu_mutex_unlock(&queue->lock); nq_count must be protected too.