Message ID | 20200227200407.490616-5-nicolas.dufresne@collabora.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Nicolas, Thank you for the patch. On Thu, Feb 27, 2020 at 03:03:44PM -0500, Nicolas Dufresne wrote: > While GLib has locker implementation already using g_autoptr(), recursive mutext s/mutext/mutex/ > locker was onmly introduced in recent GLib. Implement a simple locker for GMutex s/onmly/only/ > and GRectMutex in order to allow making locking simplier and safer. s/simplier/simpler/ > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > src/gstreamer/gstlibcamera-utils.h | 51 ++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > > diff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h > index 33160b8..737ca63 100644 > --- a/src/gstreamer/gstlibcamera-utils.h > +++ b/src/gstreamer/gstlibcamera-utils.h > @@ -15,4 +15,55 @@ > > GstCaps *gst_libcamera_stream_formats_to_caps(const libcamera::StreamFormats &formats); > > +/** > + * \class GLibLocker > + * \brief A simple scoped mutex locker for GMutex > + */ > +class GLibLocker > +{ > +public: > + GLibLocker(GMutex *mutex) > + : mutex_(mutex) > + { > + g_mutex_lock(mutex_); > + } > + > + GLibLocker(GstObject *object) > + : mutex_(GST_OBJECT_GET_LOCK(object)) > + { > + g_mutex_lock(mutex_); > + } > + > + ~GLibLocker() > + { > + g_mutex_unlock(mutex_); > + } > + > +private: > + GMutex *mutex_; > +}; > + > +/** > + * \class GLibRecLocker > + * \brief A simple scoped mutex locker for GRecMutex > + */ > +class GLibRecLocker > +{ > +public: > + GLibRecLocker(GRecMutex *mutex) > + : mutex_(mutex) > + { > + g_rec_mutex_lock(mutex_); > + } > + > + ~GLibRecLocker() > + { > + g_rec_mutex_unlock(mutex_); > + } > + > +private: > + GRecMutex *mutex_; > +}; > + > + A single blank line is enough. With these small issues fixed, Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > #endif /* __GST_LIBCAMERA_UTILS_H_ */
diff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h index 33160b8..737ca63 100644 --- a/src/gstreamer/gstlibcamera-utils.h +++ b/src/gstreamer/gstlibcamera-utils.h @@ -15,4 +15,55 @@ GstCaps *gst_libcamera_stream_formats_to_caps(const libcamera::StreamFormats &formats); +/** + * \class GLibLocker + * \brief A simple scoped mutex locker for GMutex + */ +class GLibLocker +{ +public: + GLibLocker(GMutex *mutex) + : mutex_(mutex) + { + g_mutex_lock(mutex_); + } + + GLibLocker(GstObject *object) + : mutex_(GST_OBJECT_GET_LOCK(object)) + { + g_mutex_lock(mutex_); + } + + ~GLibLocker() + { + g_mutex_unlock(mutex_); + } + +private: + GMutex *mutex_; +}; + +/** + * \class GLibRecLocker + * \brief A simple scoped mutex locker for GRecMutex + */ +class GLibRecLocker +{ +public: + GLibRecLocker(GRecMutex *mutex) + : mutex_(mutex) + { + g_rec_mutex_lock(mutex_); + } + + ~GLibRecLocker() + { + g_rec_mutex_unlock(mutex_); + } + +private: + GRecMutex *mutex_; +}; + + #endif /* __GST_LIBCAMERA_UTILS_H_ */
While GLib has locker implementation already using g_autoptr(), recursive mutext locker was onmly introduced in recent GLib. Implement a simple locker for GMutex and GRectMutex in order to allow making locking simplier and safer. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> --- src/gstreamer/gstlibcamera-utils.h | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)