From patchwork Sat Feb 6 18:02:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 77546 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 o16I2TpC032709 for ; Sat, 6 Feb 2010 18:02:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932405Ab0BFSC1 (ORCPT ); Sat, 6 Feb 2010 13:02:27 -0500 Received: from smtp.nokia.com ([192.100.105.134]:25174 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755773Ab0BFSCY (ORCPT ); Sat, 6 Feb 2010 13:02:24 -0500 Received: from vaebh106.NOE.Nokia.com (vaebh106.europe.nokia.com [10.160.244.32]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o16I2LTj023907; Sat, 6 Feb 2010 12:02:22 -0600 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by vaebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 6 Feb 2010 20:02:20 +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:19 +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 o16I2D5D029572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 6 Feb 2010 20:02:14 +0200 Received: from lanttu (unknown [192.168.239.74]) by maxwell.research.nokia.com (Postfix) with ESMTPS id 2D966700C3; Sat, 6 Feb 2010 20:02:13 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1Ndoyx-0005Mm-OJ; Sat, 06 Feb 2010 20:02:11 +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 2/8] V4L: File handles: Add refcount to v4l2_fh Date: Sat, 6 Feb 2010 20:02:05 +0200 Message-Id: <1265479331-20595-2-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:20.0035 (UTC) FILETIME=[8693F530: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:30 +0000 (UTC) diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c index 48bd32f..1728e1c 100644 --- a/drivers/media/video/v4l2-fh.c +++ b/drivers/media/video/v4l2-fh.c @@ -25,22 +25,32 @@ #include #include -int v4l2_fh_new(struct video_device *vdev, struct v4l2_fh *fh) +void v4l2_fh_new(struct video_device *vdev, struct v4l2_fh *fh) { unsigned long flags; + spin_lock_init(&fh->lock); + atomic_set(&fh->refcount, 1); + spin_lock_irqsave(&vdev->fhs.lock, flags); list_add(&fh->list, &vdev->fhs.list); spin_unlock_irqrestore(&vdev->fhs.lock, flags); - - return 0; } EXPORT_SYMBOL_GPL(v4l2_fh_new); +int v4l2_fh_get(struct video_device *vdev, struct v4l2_fh *fh) +{ + return !atomic_add_unless(&fh->refcount, 1, 0); +} +EXPORT_SYMBOL_GPL(v4l2_fh_get); + void v4l2_fh_put(struct video_device *vdev, struct v4l2_fh *fh) { unsigned long flags; + if (atomic_dec_return(&fh->refcount)) + return; + spin_lock_irqsave(&vdev->fhs.lock, flags); list_del(&fh->list); spin_unlock_irqrestore(&vdev->fhs.lock, flags); diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h index b9e277c..51d6508 100644 --- a/include/media/v4l2-fh.h +++ b/include/media/v4l2-fh.h @@ -28,8 +28,12 @@ #include #include +#include + struct v4l2_fh { struct list_head list; + atomic_t refcount; + spinlock_t lock; }; /* File handle related data for video_device. */ @@ -42,7 +46,8 @@ struct v4l2_fhs { struct video_device; -int v4l2_fh_new(struct video_device *vdev, struct v4l2_fh *fh); +void v4l2_fh_new(struct video_device *vdev, struct v4l2_fh *fh); +int v4l2_fh_get(struct video_device *vdev, struct v4l2_fh *fh); void v4l2_fh_put(struct video_device *vdev, struct v4l2_fh *fh); void v4l2_fh_init(struct video_device *vdev);