diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2011-03-12 04:37:19 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 15:38:05 -0400 |
commit | bedf8bcf6b4f90a6e31add3721a2e71877289381 (patch) | |
tree | 855560191d12dc9f21db59fca801c67f036b5167 /include/media/v4l2-device.h | |
parent | a64bb4b7111e063154f97ff64dab03144cdfb5d9 (diff) |
[media] v4l2-device: add kref and a release function
The video_device struct has proper ref counting and its release function
will be called when the last user releases it. But no such support was
available for struct v4l2_device. This made it hard to determine when a
USB driver can release the device if it has multiple device nodes.
With one device node it is easy of course, since when the device node is
released, the whole device can be released.
This patch adds refcounting to v4l2_device. When registering device nodes
the v4l2_device refcount will be increased, when releasing device nodes
it will be decreased. The (optional) release function will be called when
the last device node was released.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'include/media/v4l2-device.h')
-rw-r--r-- | include/media/v4l2-device.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h index 3b723283da26..bd102cf509ac 100644 --- a/include/media/v4l2-device.h +++ b/include/media/v4l2-device.h | |||
@@ -60,8 +60,19 @@ struct v4l2_device { | |||
60 | struct v4l2_prio_state prio; | 60 | struct v4l2_prio_state prio; |
61 | /* BKL replacement mutex. Temporary solution only. */ | 61 | /* BKL replacement mutex. Temporary solution only. */ |
62 | struct mutex ioctl_lock; | 62 | struct mutex ioctl_lock; |
63 | /* Keep track of the references to this struct. */ | ||
64 | struct kref ref; | ||
65 | /* Release function that is called when the ref count goes to 0. */ | ||
66 | void (*release)(struct v4l2_device *v4l2_dev); | ||
63 | }; | 67 | }; |
64 | 68 | ||
69 | static inline void v4l2_device_get(struct v4l2_device *v4l2_dev) | ||
70 | { | ||
71 | kref_get(&v4l2_dev->ref); | ||
72 | } | ||
73 | |||
74 | int v4l2_device_put(struct v4l2_device *v4l2_dev); | ||
75 | |||
65 | /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. | 76 | /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. |
66 | dev may be NULL in rare cases (ISA devices). In that case you | 77 | dev may be NULL in rare cases (ISA devices). In that case you |
67 | must fill in the v4l2_dev->name field before calling this function. */ | 78 | must fill in the v4l2_dev->name field before calling this function. */ |