From patchwork Sun Feb 7 18:40:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 77632 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 o17IdwXo006672 for ; Sun, 7 Feb 2010 18:39:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932968Ab0BGSj5 (ORCPT ); Sun, 7 Feb 2010 13:39:57 -0500 Received: from smtp.nokia.com ([192.100.122.230]:41855 "EHLO mgw-mx03.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932820Ab0BGSjz (ORCPT ); Sun, 7 Feb 2010 13:39:55 -0500 Received: from esebh106.NOE.Nokia.com (esebh106.ntc.nokia.com [172.21.138.213]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o17IdpT8012473; Sun, 7 Feb 2010 20:39:52 +0200 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by esebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 7 Feb 2010 20:39:50 +0200 Received: from mgw-da02.ext.nokia.com ([147.243.128.26]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sun, 7 Feb 2010 20:39:50 +0200 Received: from maxwell.research.nokia.com (maxwell.research.nokia.com [172.21.50.162]) by mgw-da02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o17Ididk030017 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 7 Feb 2010 20:39:45 +0200 Received: from lanttu (unknown [192.168.239.74]) by maxwell.research.nokia.com (Postfix) with ESMTPS id 12F217010D; Sun, 7 Feb 2010 20:39:44 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1NeC3t-000860-Nm; Sun, 07 Feb 2010 20:40:49 +0200 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, iivanov@mm-sol.com, gururaj.nagendra@intel.com, david.cohen@nokia.com, Sakari Ailus Subject: [PATCH v2 5/7] V4L: Events: Count event queue length Date: Sun, 7 Feb 2010 20:40:45 +0200 Message-Id: <1265568047-31073-5-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <4B6F0922.9070206@maxwell.research.nokia.com> References: <4B6F0922.9070206@maxwell.research.nokia.com> X-OriginalArrivalTime: 07 Feb 2010 18:39:50.0972 (UTC) FILETIME=[EEA76FC0:01CAA824] 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]); Sun, 07 Feb 2010 18:39:59 +0000 (UTC) diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index 6d57324..a95cde0 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -88,6 +88,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); @@ -109,10 +111,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_move(&kev->list, &events->free); - kev->event.count = !list_empty(&events->available); + kev->event.count = atomic_dec_return(&events->navailable); *event = kev->event; @@ -173,6 +177,8 @@ void v4l2_event_queue(struct video_device *vdev, struct v4l2_event *ev) kev->event = *ev; list_move_tail(&kev->list, &events->available); + atomic_inc(&events->navailable); + wake_up_all(&events->wait); } @@ -182,15 +188,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->vdev->fhs.lock, flags); - ret = !list_empty(&events->available); - spin_unlock_irqrestore(&fh->vdev->fhs.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 */ };