2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-10-25 10:54:52 +00:00
|
|
|
|
|
|
|
use glib::translate::mut_override;
|
|
|
|
|
2020-02-28 14:29:48 +00:00
|
|
|
#[must_use = "if unused the Mutex will immediately unlock"]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GMutex")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
2017-10-25 10:54:52 +00:00
|
|
|
|
|
|
|
impl<'a> MutexGuard<'a> {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "g_mutex_lock")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-10-25 10:54:52 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::g_mutex_lock(mut_override(mutex));
|
2017-10-25 10:54:52 +00:00
|
|
|
}
|
|
|
|
MutexGuard(mutex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Drop for MutexGuard<'a> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
2017-10-25 10:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-27 17:27:16 +00:00
|
|
|
|
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Trait that allows accessing `Display` implementation on types external to this crate.
|
|
|
|
pub trait Displayable {
|
|
|
|
type DisplayImpl: std::fmt::Display;
|
|
|
|
|
|
|
|
fn display(self) -> Self::DisplayImpl;
|
|
|
|
}
|