mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 13:01:05 +00:00
25 lines
671 B
Rust
25 lines
671 B
Rust
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
|
|
use glib::translate::mut_override;
|
|
|
|
#[must_use = "if unused the Mutex will immediately unlock"]
|
|
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
|
|
|
impl<'a> MutexGuard<'a> {
|
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
|
skip_assert_initialized!();
|
|
unsafe {
|
|
glib::ffi::g_mutex_lock(mut_override(mutex));
|
|
}
|
|
MutexGuard(mutex)
|
|
}
|
|
}
|
|
|
|
impl<'a> Drop for MutexGuard<'a> {
|
|
fn drop(&mut self) {
|
|
unsafe {
|
|
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
|
}
|
|
}
|
|
}
|