Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #372 from sdroege/concurrency
Browse files Browse the repository at this point in the history
Add various Send/Sync impls where appropriate
  • Loading branch information
GuillaumeGomez committed Aug 29, 2018
2 parents ed73ac0 + c635541 commit 79110c8
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ status = "generate"
[[object]]
name = "GLib.Checksum"
status = "generate"
concurrency = "send+sync"
[[object.function]]
name = "get_digest"
#wrong array definition
Expand Down Expand Up @@ -439,6 +440,7 @@ concurrency = "send+sync"
[[object]]
name = "GLib.TimeZone"
status = "generate"
concurrency = "send+sync"
[[object.function]]
name = "adjust_time"
# in-out parameter
Expand Down
1 change: 1 addition & 0 deletions Gir_GObject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ manual = [
name = "GObject.Binding"
status = "generate"
trait = false
concurrency = "send+sync"

[[object]]
name = "GObject.*"
Expand Down
2 changes: 1 addition & 1 deletion gir
3 changes: 3 additions & 0 deletions src/auto/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ impl Checksum {
}
}
}

unsafe impl Send for Checksum {}
unsafe impl Sync for Checksum {}
3 changes: 3 additions & 0 deletions src/auto/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ impl TimeZone {
}
}
}

unsafe impl Send for TimeZone {}
unsafe impl Sync for TimeZone {}
2 changes: 1 addition & 1 deletion src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 04c26a8)
Generated by gir (https://github.com/gtk-rs/gir @ 7191938)
from gir-files (https://github.com/gtk-rs/gir-files @ b8f5ef1)
3 changes: 3 additions & 0 deletions src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ impl Closure {
}
}

unsafe impl Send for Closure {}
unsafe impl Sync for Closure {}

#[cfg(test)]
mod tests {
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ glib_wrapper! {
}

unsafe impl Send for Date { }
unsafe impl Sync for Date { }

impl Date {
pub fn new() -> Date {
Expand Down
33 changes: 18 additions & 15 deletions src/gobject/auto/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,68 +61,71 @@ impl Binding {
}
}

pub fn connect_property_flags_notify<F: Fn(&Binding) + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_property_flags_notify<F: Fn(&Binding) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Binding) + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&Binding) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::flags",
transmute(notify_flags_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}

pub fn connect_property_source_notify<F: Fn(&Binding) + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_property_source_notify<F: Fn(&Binding) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Binding) + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&Binding) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::source",
transmute(notify_source_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}

pub fn connect_property_source_property_notify<F: Fn(&Binding) + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_property_source_property_notify<F: Fn(&Binding) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Binding) + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&Binding) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::source-property",
transmute(notify_source_property_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}

pub fn connect_property_target_notify<F: Fn(&Binding) + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_property_target_notify<F: Fn(&Binding) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Binding) + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&Binding) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::target",
transmute(notify_target_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}

pub fn connect_property_target_property_notify<F: Fn(&Binding) + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_property_target_property_notify<F: Fn(&Binding) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Binding) + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&Binding) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::target-property",
transmute(notify_target_property_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}
}

unsafe impl Send for Binding {}
unsafe impl Sync for Binding {}

unsafe extern "C" fn notify_flags_trampoline(this: *mut gobject_ffi::GBinding, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&Binding) + 'static) = transmute(f);
let f: &&(Fn(&Binding) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}

unsafe extern "C" fn notify_source_trampoline(this: *mut gobject_ffi::GBinding, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&Binding) + 'static) = transmute(f);
let f: &&(Fn(&Binding) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}

unsafe extern "C" fn notify_source_property_trampoline(this: *mut gobject_ffi::GBinding, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&Binding) + 'static) = transmute(f);
let f: &&(Fn(&Binding) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}

unsafe extern "C" fn notify_target_trampoline(this: *mut gobject_ffi::GBinding, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&Binding) + 'static) = transmute(f);
let f: &&(Fn(&Binding) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}

unsafe extern "C" fn notify_target_property_trampoline(this: *mut gobject_ffi::GBinding, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&Binding) + 'static) = transmute(f);
let f: &&(Fn(&Binding) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}
3 changes: 3 additions & 0 deletions src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ glib_wrapper! {
}
}

unsafe impl Send for ParamSpec {}
unsafe impl Sync for ParamSpec {}

impl ParamSpec {
pub fn get_value_type(&self) -> ::Type {
unsafe {
Expand Down
3 changes: 3 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ glib_wrapper! {
}
}

unsafe impl Send for String {}
unsafe impl Sync for String {}

impl String {
pub fn new<T: AsRef<[u8]>>(data: T) -> String {
let bytes = data.as_ref();
Expand Down

0 comments on commit 79110c8

Please sign in to comment.