From patchwork Tue Feb 9 18:26:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 78088 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 o19IRJpC017821 for ; Tue, 9 Feb 2010 18:27:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751451Ab0BIS1R (ORCPT ); Tue, 9 Feb 2010 13:27:17 -0500 Received: from smtp.nokia.com ([192.100.105.134]:55760 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751198Ab0BIS1I (ORCPT ); Tue, 9 Feb 2010 13:27:08 -0500 Received: from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com [10.160.244.31]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o19IQDkS027353; Tue, 9 Feb 2010 12:27:06 -0600 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by vaebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 9 Feb 2010 20:26:57 +0200 Received: from mgw-sa02.ext.nokia.com ([147.243.1.48]) by vaebh104.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Tue, 9 Feb 2010 20:26:54 +0200 Received: from maxwell.research.nokia.com (maxwell.research.nokia.com [172.21.50.162]) by mgw-sa02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o19IQqp9003290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 Feb 2010 20:26:52 +0200 Received: from lanttu (lanttu.localdomain [192.168.239.4]) by maxwell.research.nokia.com (Postfix) with ESMTPS id D171A7012A; Tue, 9 Feb 2010 20:26:50 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1NeunS-0006IH-HB; Tue, 09 Feb 2010 20:26:50 +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 Subject: [PATCH v3 5/7] V4L: Events: Count event queue length Date: Tue, 9 Feb 2010 20:26:48 +0200 Message-Id: <1265740010-24144-5-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1265740010-24144-4-git-send-email-sakari.ailus@maxwell.research.nokia.com> References: <4B71A8DF.8070907@maxwell.research.nokia.com> <1265740010-24144-1-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265740010-24144-2-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265740010-24144-3-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265740010-24144-4-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-OriginalArrivalTime: 09 Feb 2010 18:26:54.0301 (UTC) FILETIME=[748C58D0:01CAA9B5] 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]); Tue, 09 Feb 2010 18:27:20 +0000 (UTC) diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index 9f5be94..eeaba4c 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -36,6 +36,9 @@ int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n) for (; n > 0; n--) { struct v4l2_kevent *kev; + if (atomic_read(&events->max_events) <= 0) + return -ENOMEM; + kev = kzalloc(sizeof(*kev), GFP_KERNEL); if (kev == NULL) return -ENOMEM; @@ -43,9 +46,10 @@ int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n) spin_lock_irqsave(&fh->vdev->fh_lock, flags); list_add_tail(&kev->list, &events->free); spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); + atomic_dec(&events->max_events); } - return n; + return 0; } EXPORT_SYMBOL_GPL(v4l2_event_alloc); @@ -73,7 +77,7 @@ void v4l2_event_exit(struct v4l2_fh *fh) } EXPORT_SYMBOL_GPL(v4l2_event_exit); -int v4l2_event_init(struct v4l2_fh *fh, unsigned int n) +int v4l2_event_init(struct v4l2_fh *fh, unsigned int n, unsigned int max_events) { int ret; @@ -87,6 +91,9 @@ 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); + atomic_set(&fh->events->max_events, max_events); + ret = v4l2_event_alloc(fh, n); if (ret < 0) v4l2_event_exit(fh); @@ -108,10 +115,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; @@ -172,6 +181,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); } @@ -181,15 +192,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->fh_lock, flags); - ret = !list_empty(&events->available); - spin_unlock_irqrestore(&fh->vdev->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..a9d0333 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,11 +47,13 @@ struct v4l2_events { wait_queue_head_t wait; struct list_head subscribed; /* Subscribed events */ struct list_head available; /* Dequeueable event */ + atomic_t navailable; + atomic_t max_events; /* Never allocate more. */ struct list_head free; /* Events ready for use */ }; int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n); -int v4l2_event_init(struct v4l2_fh *fh, unsigned int n); +int v4l2_event_init(struct v4l2_fh *fh, unsigned int n, unsigned int max_alloc); void v4l2_event_exit(struct v4l2_fh *fh); int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event); struct v4l2_subscribed_event *v4l2_event_subscribed(