Signed-off-by: Sakari Ailus <[email protected]>
---
drivers/media/video/v4l2-fh.c | 16 +++++++++++++---
include/media/v4l2-fh.h | 7 ++++++-
2 files changed, 19 insertions(+), 4 deletions(-)
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 <media/v4l2-dev.h>
#include <media/v4l2-fh.h>
-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 <linux/types.h>
#include <linux/list.h>
+#include <asm/atomic.h>
+
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);
--
1.5.6.5
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html