From patchwork Sat Feb 6 18:02:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 77548 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o16I2X5R032753 for ; Sat, 6 Feb 2010 18:02:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932546Ab0BFSCa (ORCPT ); Sat, 6 Feb 2010 13:02:30 -0500 Received: from smtp.nokia.com ([192.100.105.134]:25181 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932342Ab0BFSC0 (ORCPT ); Sat, 6 Feb 2010 13:02:26 -0500 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o16I2NQU024080; Sat, 6 Feb 2010 12:02:24 -0600 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 6 Feb 2010 20:02:23 +0200 Received: from mgw-da01.ext.nokia.com ([147.243.128.24]) by vaebh104.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sat, 6 Feb 2010 20:02:21 +0200 Received: from maxwell.research.nokia.com (maxwell.research.nokia.com [172.21.50.162]) by mgw-da01.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o16I2FDx029587 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 6 Feb 2010 20:02:17 +0200 Received: from lanttu (unknown [192.168.239.74]) by maxwell.research.nokia.com (Postfix) with ESMTPS id BEEE77010E; Sat, 6 Feb 2010 20:02:14 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1Ndoyz-0005Mv-Fh; Sat, 06 Feb 2010 20:02:13 +0200 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: hans.verkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, gururaj.nagendra@intel.com, david.cohen@nokia.com, iivanov@mm-sol.com, Sakari Ailus Subject: [PATCH 6/8] V4L: Events: Count event queue length Date: Sat, 6 Feb 2010 20:02:09 +0200 Message-Id: <1265479331-20595-6-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <4B6DAE5A.5090508@maxwell.research.nokia.com> References: <4B6DAE5A.5090508@maxwell.research.nokia.com> X-OriginalArrivalTime: 06 Feb 2010 18:02:22.0629 (UTC) FILETIME=[881FC550:01CAA756] X-Nokia-AV: Clean Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 06 Feb 2010 18:02:33 +0000 (UTC) diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index 7ae763f..b921229 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -107,6 +107,8 @@ int v4l2_event_init(struct v4l2_fh *fh, unsigned int n) INIT_LIST_HEAD(&fh->events->available); INIT_LIST_HEAD(&fh->events->subscribed); + atomic_set(&fh->events->navailable, 0); + ret = v4l2_event_alloc(fh, n); if (ret < 0) v4l2_event_exit(fh); @@ -128,10 +130,12 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) return -ENOENT; } + BUG_ON(&events->navailable == 0); + kev = list_first_entry(&events->available, struct v4l2_kevent, list); list_del(&kev->list); - kev->event.count = !list_empty(&events->available); + kev->event.count = atomic_dec_return(&events->navailable); spin_unlock_irqrestore(&fh->lock, flags); @@ -225,6 +229,8 @@ void v4l2_event_queue(struct video_device *vdev, struct v4l2_event *ev) list_add_tail(&kev->list, &events->available); spin_unlock_irqrestore(&fh->lock, flags); + atomic_inc(&events->navailable); + wake_up_all(&events->wait); spin_lock_irqsave(&vdev->fhs.lock, flags); @@ -240,15 +246,7 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue); int v4l2_event_pending(struct v4l2_fh *fh) { - struct v4l2_events *events = fh->events; - unsigned long flags; - int ret; - - spin_lock_irqsave(&fh->lock, flags); - ret = !list_empty(&events->available); - spin_unlock_irqrestore(&fh->lock, flags); - - return ret; + return atomic_read(&fh->events->navailable); } EXPORT_SYMBOL_GPL(v4l2_event_pending); diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h index 580c9d4..282d215 100644 --- a/include/media/v4l2-event.h +++ b/include/media/v4l2-event.h @@ -28,6 +28,8 @@ #include #include +#include + struct v4l2_fh; struct video_device; @@ -45,6 +47,7 @@ struct v4l2_events { wait_queue_head_t wait; struct list_head subscribed; /* Subscribed events */ struct list_head available; /* Dequeueable event */ + atomic_t navailable; struct list_head free; /* Events ready for use */ };