@@ -52,14 +52,17 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
}
EXPORT_SYMBOL_GPL(v4l2_fh_init);
-void v4l2_fh_add(struct v4l2_fh *fh)
+bool v4l2_fh_add(struct v4l2_fh *fh)
{
unsigned long flags;
+ bool is_first;
v4l2_prio_open(fh->vdev->prio, &fh->prio);
spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+ is_first = list_empty(&fh->vdev->fh_list);
list_add(&fh->list, &fh->vdev->fh_list);
spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+ return is_first;
}
EXPORT_SYMBOL_GPL(v4l2_fh_add);
@@ -77,14 +80,17 @@ int v4l2_fh_open(struct file *filp)
}
EXPORT_SYMBOL_GPL(v4l2_fh_open);
-void v4l2_fh_del(struct v4l2_fh *fh)
+bool v4l2_fh_del(struct v4l2_fh *fh)
{
unsigned long flags;
+ bool is_last;
spin_lock_irqsave(&fh->vdev->fh_lock, flags);
list_del_init(&fh->list);
+ is_last = list_empty(&fh->vdev->fh_list);
spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
v4l2_prio_close(fh->vdev->prio, fh->prio);
+ return is_last;
}
EXPORT_SYMBOL_GPL(v4l2_fh_del);
@@ -60,9 +60,10 @@ struct v4l2_fh {
void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
/*
* Add the fh to the list of file handles on a video_device. The file
- * handle must be initialised first.
+ * handle must be initialised first. This function will return true
+ * if the new filehandle was the first filehandle added and false otherwise.
*/
-void v4l2_fh_add(struct v4l2_fh *fh);
+bool v4l2_fh_add(struct v4l2_fh *fh);
/*
* Can be used as the open() op of v4l2_file_operations.
* It allocates a v4l2_fh and inits and adds it to the video_device associated
@@ -73,9 +74,10 @@ int v4l2_fh_open(struct file *filp);
* Remove file handle from the list of file handles. Must be called in
* v4l2_file_operations->release() handler if the driver uses v4l2_fh.
* On error filp->private_data will be NULL, otherwise it will point to
- * the v4l2_fh struct.
+ * the v4l2_fh struct. This function will return true if this was the
+ * last open filehandle and false otherwise.
*/
-void v4l2_fh_del(struct v4l2_fh *fh);
+bool v4l2_fh_del(struct v4l2_fh *fh);
/*
* Release resources related to a file handle. Parts of the V4L2
* framework using the v4l2_fh must release their resources here, too.