From patchwork Wed Feb 10 14:58:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 2682 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Wed, 10 Feb 2010 14:59:10 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Wed, 10 Feb 2010 13:00:06 -0200 (BRST) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NfE22-0000Cx-F4; Wed, 10 Feb 2010 14:59:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754531Ab0BJO7J (ORCPT + 1 other); Wed, 10 Feb 2010 09:59:09 -0500 Received: from smtp.nokia.com ([192.100.122.230]:43196 "EHLO mgw-mx03.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754517Ab0BJO7I (ORCPT ); Wed, 10 Feb 2010 09:59:08 -0500 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o1AEwsf3030594; Wed, 10 Feb 2010 16:59:04 +0200 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 10 Feb 2010 16:58:21 +0200 Received: from mgw-da01.ext.nokia.com ([147.243.128.24]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 10 Feb 2010 16:58:20 +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 o1AEwElY001490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 10 Feb 2010 16:58:15 +0200 Received: from lanttu (unknown [192.168.239.74]) by maxwell.research.nokia.com (Postfix) with ESMTPS id C619B7010D; Wed, 10 Feb 2010 16:58:13 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1NfE15-0004h7-JZ; Wed, 10 Feb 2010 16:58:11 +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 v4 5/7] V4L: Events: Count event queue length Date: Wed, 10 Feb 2010 16:58:07 +0200 Message-Id: <1265813889-17847-5-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1265813889-17847-4-git-send-email-sakari.ailus@maxwell.research.nokia.com> References: <4B72C965.7040204@maxwell.research.nokia.com> <1265813889-17847-1-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265813889-17847-2-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265813889-17847-3-git-send-email-sakari.ailus@maxwell.research.nokia.com> <1265813889-17847-4-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-OriginalArrivalTime: 10 Feb 2010 14:58:21.0200 (UTC) FILETIME=[7C926900:01CAAA61] X-Nokia-AV: Clean Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Update the count field properly by setting it to exactly to number of further available events. Signed-off-by: Sakari Ailus --- drivers/media/video/v4l2-event.c | 29 +++++++++++++++++------------ include/media/v4l2-event.h | 6 +++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index d13c1e9..bbdc149 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -41,7 +41,13 @@ int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n) return -ENOMEM; spin_lock_irqsave(&fh->vdev->fh_lock, flags); + if (events->max_alloc == 0) { + spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); + kfree(kev); + return -ENOMEM; + } list_add_tail(&kev->list, &events->free); + events->max_alloc--; spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); } @@ -73,7 +79,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_alloc) { int ret; @@ -87,6 +93,9 @@ int v4l2_event_init(struct v4l2_fh *fh, unsigned int n) INIT_LIST_HEAD(&fh->events->available); INIT_LIST_HEAD(&fh->events->subscribed); + fh->events->navailable = 0; + fh->events->max_alloc = max_alloc; + ret = v4l2_event_alloc(fh, n); if (ret < 0) v4l2_event_exit(fh); @@ -108,11 +117,13 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) return -ENOENT; } + WARN_ON(&events->navailable == 0); + kev = list_first_entry(&events->available, struct v4l2_kevent, list); list_move(&kev->list, &events->free); + events->navailable--; - kev->event.count = !list_empty(&events->available); - + kev->event.count = events->navailable; *event = kev->event; spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); @@ -175,6 +186,8 @@ void v4l2_event_queue(struct video_device *vdev, struct v4l2_event *ev) kev->event = *ev; list_move_tail(&kev->list, &events->available); + events->navailable++; + wake_up_all(&events->wait); } @@ -184,15 +197,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 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..671c8f7 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 */ + unsigned int navailable; + unsigned int max_alloc; /* 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(