diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2020-01-16 10:24:19 -0500 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-07 01:57:45 +0200 |
commit | 7e82d3c2a1ecca4f2041a1a095a0725fe9d172c0 (patch) | |
tree | 8370655a4507db8a155d27c45bffabea6e84c093 | |
parent | 0e0cc2149ec10f6bad74a646ce3eaeba7f6c5b54 (diff) |
gst: utils: Add simple scoped lockers for GMutex and GRectMutex
While GLib has locker implementation already using g_autoptr(), recursive mutex
locker was only introduced in recent GLib. Implement a simple locker for GMutex
and GRectMutex in order to allow making locking simpler and safer.
Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | src/gstreamer/gstlibcamera-utils.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h index 2e4e3042..562ffe97 100644 --- a/src/gstreamer/gstlibcamera-utils.h +++ b/src/gstreamer/gstlibcamera-utils.h @@ -16,4 +16,54 @@ 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__ */ |