@@ -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);
@@ -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);