From 8d001d8b169152022a3fe7079970a6d970a2464d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 9 Apr 2022 11:36:39 +0300 Subject: [PATCH] Stop using glib::SendUnique It is being removed because it does not add a lot of value. --- examples/src/bin/overlay-composition.rs | 17 ++++++----------- examples/src/bin/pango-cairo.rs | 17 ++++++----------- gstreamer-base/Gir.toml | 2 +- gstreamer-base/src/auto/adapter.rs | 7 ------- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/examples/src/bin/overlay-composition.rs b/examples/src/bin/overlay-composition.rs index 770578435..e8edcadd5 100644 --- a/examples/src/bin/overlay-composition.rs +++ b/examples/src/bin/overlay-composition.rs @@ -35,7 +35,7 @@ struct ErrorMessage { } struct DrawingContext { - layout: glib::SendUniqueCell, + layout: LayoutWrapper, info: Option, } @@ -46,15 +46,13 @@ impl ops::Deref for LayoutWrapper { type Target = pango::Layout; fn deref(&self) -> &pango::Layout { + assert_eq!(self.0.ref_count(), 1); &self.0 } } -unsafe impl glib::SendUnique for LayoutWrapper { - fn is_unique(&self) -> bool { - self.0.ref_count() == 1 - } -} +// SAFETY: We ensure that there are never multiple references to the layout. +unsafe impl Send for LayoutWrapper {} fn create_pipeline() -> Result { gst::init()?; @@ -111,10 +109,7 @@ fn create_pipeline() -> Result { // interior mutability (see Rust docs). Via this we can get a mutable reference to the contained // data which is checked at runtime for uniqueness (blocking in case of mutex, panic in case // of refcell) instead of compile-time (like with normal references). - let drawer = Arc::new(Mutex::new(DrawingContext { - layout: glib::SendUniqueCell::new(layout).unwrap(), - info: None, - })); + let drawer = Arc::new(Mutex::new(DrawingContext { layout, info: None })); // Connect to the overlaycomposition element's "draw" signal, which is emitted for // each videoframe piped through the element. The signal handler needs to @@ -140,7 +135,7 @@ fn create_pipeline() -> Result { let timestamp = buffer.pts().unwrap(); let info = drawer.info.as_ref().unwrap(); - let layout = drawer.layout.borrow(); + let layout = &drawer.layout; let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64 / (10.0 * gst::ClockTime::SECOND.nseconds() as f64); diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index 28c9fed6f..7c2f6abec 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -38,7 +38,7 @@ struct ErrorMessage { } struct DrawingContext { - layout: glib::SendUniqueCell, + layout: LayoutWrapper, info: Option, } @@ -49,15 +49,13 @@ impl ops::Deref for LayoutWrapper { type Target = pango::Layout; fn deref(&self) -> &pango::Layout { + assert_eq!(self.0.ref_count(), 1); &self.0 } } -unsafe impl glib::SendUnique for LayoutWrapper { - fn is_unique(&self) -> bool { - self.0.ref_count() == 1 - } -} +// SAFETY: We ensure that there are never multiple references to the layout. +unsafe impl Send for LayoutWrapper {} fn create_pipeline() -> Result { gst::init()?; @@ -112,10 +110,7 @@ fn create_pipeline() -> Result { // interior mutability (see Rust docs). Via this we can get a mutable reference to the contained // data which is checked at runtime for uniqueness (blocking in case of mutex, panic in case // of refcell) instead of compile-time (like with normal references). - let drawer = Arc::new(Mutex::new(DrawingContext { - layout: glib::SendUniqueCell::new(layout).unwrap(), - info: None, - })); + let drawer = Arc::new(Mutex::new(DrawingContext { layout, info: None })); let drawer_clone = drawer.clone(); // Connect to the cairooverlay element's "draw" signal, which is emitted for @@ -140,7 +135,7 @@ fn create_pipeline() -> Result { let _duration = args[3].get::().unwrap(); let info = drawer.info.as_ref().unwrap(); - let layout = drawer.layout.borrow(); + let layout = &drawer.layout; let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64 / (10.0 * gst::ClockTime::SECOND.nseconds() as f64); diff --git a/gstreamer-base/Gir.toml b/gstreamer-base/Gir.toml index 400bab899..a044bd761 100644 --- a/gstreamer-base/Gir.toml +++ b/gstreamer-base/Gir.toml @@ -138,7 +138,7 @@ status = "generate" name = "GstBase.Adapter" status = "generate" final_type = true -concurrency = "send-unique" +concurrency = "none" [[object.function]] name = "map" # Unsafe, implemented on `UniqueAdapter` diff --git a/gstreamer-base/src/auto/adapter.rs b/gstreamer-base/src/auto/adapter.rs index bf09d230c..139157b8b 100644 --- a/gstreamer-base/src/auto/adapter.rs +++ b/gstreamer-base/src/auto/adapter.rs @@ -4,7 +4,6 @@ // DO NOT EDIT use glib::translate::*; -use glib::ObjectExt; use std::mem; glib::wrapper! { @@ -130,9 +129,3 @@ impl Default for Adapter { Self::new() } } - -unsafe impl glib::SendUnique for Adapter { - fn is_unique(&self) -> bool { - self.ref_count() == 1 - } -}