mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-10-31 22:59:14 +00:00
Add a borrow() function to SendCell
To allow doing the thread check only once for performance reasons.
This commit is contained in:
parent
3395203a53
commit
5676aeb3ef
1 changed files with 24 additions and 2 deletions
|
@ -85,7 +85,7 @@ fn create_ui(app: >k::Application) {
|
|||
|
||||
let app_clone = SendCell::new(app.clone());
|
||||
bus.add_watch(move |_, msg| {
|
||||
let app = &app_clone;
|
||||
let app = app_clone.borrow();
|
||||
match msg.view() {
|
||||
MessageView::Eos(..) => gtk::main_quit(),
|
||||
MessageView::Error(err) => {
|
||||
|
@ -95,7 +95,7 @@ fn create_ui(app: >k::Application) {
|
|||
err.get_error(),
|
||||
err.get_debug()
|
||||
);
|
||||
app.get().quit();
|
||||
app.quit();
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
@ -127,6 +127,7 @@ fn main() {
|
|||
// but us having to use them in a closure that requires Send
|
||||
use std::thread;
|
||||
use std::cmp;
|
||||
use std::ops;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SendCell<T> {
|
||||
|
@ -154,6 +155,27 @@ impl<T> SendCell<T> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow(&self) -> Ref<T> {
|
||||
Ref { data: self.get() }
|
||||
}
|
||||
|
||||
pub fn try_borrow(&self) -> Option<Ref<T>> {
|
||||
self.try_get().map(|data| Ref { data: data })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Ref<'a, T: 'a> {
|
||||
data: &'a T,
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> ops::Deref for Ref<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
self.data
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<T> for SendCell<T> {
|
||||
|
|
Loading…
Reference in a new issue