Implement Sync/Send for more types and don't implement Send for TypeFind

They can actually be shared with multiple threads at the same time
safely as all functions requiring an immutable reference are
thread-safe.

OTOH TypeFind can't be shared safely between different threads as not
all implementations of the TypeFind struct are thread-safe.
This commit is contained in:
Sebastian Dröge 2019-12-18 17:04:42 +02:00
parent da8187b016
commit 2ba5105b80
28 changed files with 95 additions and 8 deletions

View file

@ -87,6 +87,9 @@ impl Drop for AudioRingBufferSpec {
} }
} }
unsafe impl Send for AudioRingBufferSpec {}
unsafe impl Sync for AudioRingBufferSpec {}
impl fmt::Debug for AudioRingBufferSpec { impl fmt::Debug for AudioRingBufferSpec {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.debug_struct("AudioRingBufferSpec") f.debug_struct("AudioRingBufferSpec")

View file

@ -23,6 +23,9 @@ pub struct BaseParseFrame<'a>(
PhantomData<&'a BaseParse>, PhantomData<&'a BaseParse>,
); );
unsafe impl<'a> Send for BaseParseFrame<'a> {}
unsafe impl<'a> Sync for BaseParseFrame<'a> {}
#[derive(Debug)] #[derive(Debug)]
pub enum Overhead { pub enum Overhead {
None, None,

View file

@ -36,6 +36,7 @@ impl Drop for Harness {
} }
unsafe impl Send for Harness {} unsafe impl Send for Harness {}
unsafe impl Sync for Harness {}
impl Harness { impl Harness {
pub fn add_element_full<P: IsA<gst::Element>>( pub fn add_element_full<P: IsA<gst::Element>>(
@ -792,7 +793,7 @@ impl Harness {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Ref<'a>(Option<Harness>, PhantomData<&'a gst_check_sys::GstHarness>); pub struct Ref<'a>(Option<Harness>, PhantomData<&'a Harness>);
impl<'a> ops::Deref for Ref<'a> { impl<'a> ops::Deref for Ref<'a> {
type Target = Harness; type Target = Harness;
@ -810,10 +811,7 @@ impl<'a> Drop for Ref<'a> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RefMut<'a>( pub struct RefMut<'a>(Option<Harness>, PhantomData<&'a mut Harness>);
Option<Harness>,
PhantomData<&'a mut gst_check_sys::GstHarness>,
);
impl<'a> ops::Deref for RefMut<'a> { impl<'a> ops::Deref for RefMut<'a> {
type Target = Harness; type Target = Harness;

View file

@ -11,6 +11,9 @@ use GLContext;
#[repr(C)] #[repr(C)]
pub struct GLSyncMeta(gst_gl_sys::GstGLSyncMeta); pub struct GLSyncMeta(gst_gl_sys::GstGLSyncMeta);
unsafe impl Send for GLSyncMeta {}
unsafe impl Sync for GLSyncMeta {}
impl GLSyncMeta { impl GLSyncMeta {
pub fn add<'a, C: IsA<GLContext>>( pub fn add<'a, C: IsA<GLContext>>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,

View file

@ -10,6 +10,9 @@ use gst_net_sys;
#[repr(C)] #[repr(C)]
pub struct NetAddressMeta(gst_net_sys::GstNetAddressMeta); pub struct NetAddressMeta(gst_net_sys::GstNetAddressMeta);
unsafe impl Send for NetAddressMeta {}
unsafe impl Sync for NetAddressMeta {}
impl NetAddressMeta { impl NetAddressMeta {
pub fn add<'a, A: IsA<gio::SocketAddress>>( pub fn add<'a, A: IsA<gio::SocketAddress>>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,

View file

@ -11,6 +11,9 @@ pub enum Writable {}
#[repr(C)] #[repr(C)]
pub struct RTPBuffer<'a, T>(gst_rtp_sys::GstRTPBuffer, &'a gst::Buffer, PhantomData<T>); pub struct RTPBuffer<'a, T>(gst_rtp_sys::GstRTPBuffer, &'a gst::Buffer, PhantomData<T>);
unsafe impl<'a, T> Send for RTPBuffer<'a, T> {}
unsafe impl<'a, T> Sync for RTPBuffer<'a, T> {}
impl<'a> RTPBuffer<'a, Readable> { impl<'a> RTPBuffer<'a, Readable> {
pub fn from_buffer_readable( pub fn from_buffer_readable(
buffer: &gst::Buffer, buffer: &gst::Buffer,

View file

@ -16,6 +16,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPAttribute(pub(crate) gst_sdp_sys::GstSDPAttribute); pub struct SDPAttribute(pub(crate) gst_sdp_sys::GstSDPAttribute);
unsafe impl Send for SDPAttribute {}
unsafe impl Sync for SDPAttribute {}
impl SDPAttribute { impl SDPAttribute {
pub fn new(key: &str, value: Option<&str>) -> Self { pub fn new(key: &str, value: Option<&str>) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();

View file

@ -16,6 +16,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPBandwidth(pub(crate) gst_sdp_sys::GstSDPBandwidth); pub struct SDPBandwidth(pub(crate) gst_sdp_sys::GstSDPBandwidth);
unsafe impl Send for SDPBandwidth {}
unsafe impl Sync for SDPBandwidth {}
impl SDPBandwidth { impl SDPBandwidth {
pub fn new(bwtype: &str, bandwidth: u32) -> Self { pub fn new(bwtype: &str, bandwidth: u32) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();

View file

@ -16,6 +16,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPConnection(pub(crate) gst_sdp_sys::GstSDPConnection); pub struct SDPConnection(pub(crate) gst_sdp_sys::GstSDPConnection);
unsafe impl Send for SDPConnection {}
unsafe impl Sync for SDPConnection {}
impl SDPConnection { impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self { pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();

View file

@ -14,6 +14,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPKey(gst_sdp_sys::GstSDPKey); pub struct SDPKey(gst_sdp_sys::GstSDPKey);
unsafe impl Send for SDPKey {}
unsafe impl Sync for SDPKey {}
impl SDPKey { impl SDPKey {
pub fn type_(&self) -> Option<&str> { pub fn type_(&self) -> Option<&str> {
unsafe { unsafe {

View file

@ -14,6 +14,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPOrigin(pub(crate) gst_sdp_sys::GstSDPOrigin); pub struct SDPOrigin(pub(crate) gst_sdp_sys::GstSDPOrigin);
unsafe impl Send for SDPOrigin {}
unsafe impl Sync for SDPOrigin {}
impl SDPOrigin { impl SDPOrigin {
pub fn username(&self) -> Option<&str> { pub fn username(&self) -> Option<&str> {
unsafe { unsafe {

View file

@ -18,6 +18,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPTime(pub(crate) gst_sdp_sys::GstSDPTime); pub struct SDPTime(pub(crate) gst_sdp_sys::GstSDPTime);
unsafe impl Send for SDPTime {}
unsafe impl Sync for SDPTime {}
impl SDPTime { impl SDPTime {
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Self { pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();

View file

@ -16,6 +16,9 @@ use gst_sdp_sys;
#[repr(C)] #[repr(C)]
pub struct SDPZone(pub(crate) gst_sdp_sys::GstSDPZone); pub struct SDPZone(pub(crate) gst_sdp_sys::GstSDPZone);
unsafe impl Send for SDPZone {}
unsafe impl Sync for SDPZone {}
impl SDPZone { impl SDPZone {
pub fn new(time: &str, typed_time: &str) -> Self { pub fn new(time: &str, typed_time: &str) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();

View file

@ -663,6 +663,9 @@ impl<'a> ops::Deref for VideoFrameRef<&'a mut gst::BufferRef> {
} }
} }
unsafe impl<T> Send for VideoFrameRef<T> {}
unsafe impl<T> Sync for VideoFrameRef<T> {}
impl<T> Drop for VideoFrameRef<T> { impl<T> Drop for VideoFrameRef<T> {
fn drop(&mut self) { fn drop(&mut self) {
if !self.3 { if !self.3 {

View file

@ -18,6 +18,9 @@ use gst_video_sys;
#[repr(C)] #[repr(C)]
pub struct VideoMeta(gst_video_sys::GstVideoMeta); pub struct VideoMeta(gst_video_sys::GstVideoMeta);
unsafe impl Send for VideoMeta {}
unsafe impl Sync for VideoMeta {}
impl VideoMeta { impl VideoMeta {
pub fn add( pub fn add(
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
@ -134,6 +137,9 @@ impl fmt::Debug for VideoMeta {
#[repr(C)] #[repr(C)]
pub struct VideoOverlayCompositionMeta(gst_video_sys::GstVideoOverlayCompositionMeta); pub struct VideoOverlayCompositionMeta(gst_video_sys::GstVideoOverlayCompositionMeta);
unsafe impl Send for VideoOverlayCompositionMeta {}
unsafe impl Sync for VideoOverlayCompositionMeta {}
impl VideoOverlayCompositionMeta { impl VideoOverlayCompositionMeta {
pub fn add<'a>( pub fn add<'a>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
@ -186,6 +192,11 @@ impl fmt::Debug for VideoOverlayCompositionMeta {
#[repr(C)] #[repr(C)]
pub struct VideoCaptionMeta(gst_video_sys::GstVideoCaptionMeta); pub struct VideoCaptionMeta(gst_video_sys::GstVideoCaptionMeta);
#[cfg(any(feature = "v1_16", feature = "dox"))]
unsafe impl Send for VideoCaptionMeta {}
#[cfg(any(feature = "v1_16", feature = "dox"))]
unsafe impl Sync for VideoCaptionMeta {}
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
impl VideoCaptionMeta { impl VideoCaptionMeta {
pub fn add<'a>( pub fn add<'a>(

View file

@ -525,6 +525,9 @@ impl From<ValidVideoTimeCode> for VideoTimeCode {
#[repr(C)] #[repr(C)]
pub struct VideoTimeCodeMeta(gst_video_sys::GstVideoTimeCodeMeta); pub struct VideoTimeCodeMeta(gst_video_sys::GstVideoTimeCodeMeta);
unsafe impl Send for VideoTimeCodeMeta {}
unsafe impl Sync for VideoTimeCodeMeta {}
impl VideoTimeCodeMeta { impl VideoTimeCodeMeta {
pub fn add<'a>( pub fn add<'a>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,

View file

@ -15,6 +15,9 @@ use MemoryFlags;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AllocationParams(gst_sys::GstAllocationParams); pub struct AllocationParams(gst_sys::GstAllocationParams);
unsafe impl Send for AllocationParams {}
unsafe impl Sync for AllocationParams {}
impl AllocationParams { impl AllocationParams {
pub fn get_flags(&self) -> MemoryFlags { pub fn get_flags(&self) -> MemoryFlags {
from_glib(self.0.flags) from_glib(self.0.flags)

View file

@ -604,6 +604,9 @@ macro_rules! define_iter(
items: PhantomData<$mtyp>, items: PhantomData<$mtyp>,
} }
unsafe impl<'a, T: MetaAPI> Send for $name<'a, T> { }
unsafe impl<'a, T: MetaAPI> Sync for $name<'a, T> { }
impl<'a, T: MetaAPI> $name<'a, T> { impl<'a, T: MetaAPI> $name<'a, T> {
fn new(buffer: $typ) -> $name<'a, T> { fn new(buffer: $typ) -> $name<'a, T> {
skip_assert_initialized!(); skip_assert_initialized!();
@ -778,6 +781,9 @@ impl<'a, T> Drop for BufferMap<'a, T> {
} }
} }
unsafe impl<'a, T> Send for BufferMap<'a, T> {}
unsafe impl<'a, T> Sync for BufferMap<'a, T> {}
impl<T> MappedBuffer<T> { impl<T> MappedBuffer<T> {
pub fn as_slice(&self) -> &[u8] { pub fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) } unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) }
@ -860,6 +866,7 @@ impl<T> PartialEq for MappedBuffer<T> {
impl<T> Eq for MappedBuffer<T> {} impl<T> Eq for MappedBuffer<T> {}
unsafe impl<T> Send for MappedBuffer<T> {} unsafe impl<T> Send for MappedBuffer<T> {}
unsafe impl<T> Sync for MappedBuffer<T> {}
lazy_static! { lazy_static! {
pub static ref BUFFER_COPY_METADATA: ::BufferCopyFlags = pub static ref BUFFER_COPY_METADATA: ::BufferCopyFlags =

View file

@ -187,6 +187,9 @@ impl BufferPoolConfig {
#[derive(Debug)] #[derive(Debug)]
pub struct BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams); pub struct BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams);
unsafe impl Send for BufferPoolAcquireParams {}
unsafe impl Sync for BufferPoolAcquireParams {}
impl BufferPoolAcquireParams { impl BufferPoolAcquireParams {
pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self { pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self {
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams { BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams {

View file

@ -326,6 +326,7 @@ where
} }
unsafe impl<T> Send for Iterator<T> {} unsafe impl<T> Send for Iterator<T> {}
unsafe impl<T> Sync for Iterator<T> {}
unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpointer) -> i32 unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpointer) -> i32
where where

View file

@ -380,6 +380,9 @@ impl<'a, T> Drop for MemoryMap<'a, T> {
} }
} }
unsafe impl<'a, T> Send for MemoryMap<'a, T> {}
unsafe impl<'a, T> Sync for MemoryMap<'a, T> {}
impl<T> MappedMemory<T> { impl<T> MappedMemory<T> {
pub fn as_slice(&self) -> &[u8] { pub fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) } unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) }
@ -462,3 +465,4 @@ impl<T> PartialEq for MappedMemory<T> {
impl<T> Eq for MappedMemory<T> {} impl<T> Eq for MappedMemory<T> {}
unsafe impl<T> Send for MappedMemory<T> {} unsafe impl<T> Send for MappedMemory<T> {}
unsafe impl<T> Sync for MappedMemory<T> {}

View file

@ -27,7 +27,7 @@ use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr};
use glib_sys; use glib_sys;
use gst_sys; use gst_sys;
pub unsafe trait MetaAPI: Sized { pub unsafe trait MetaAPI: Sync + Send + Sized {
type GstType; type GstType;
fn get_meta_api() -> glib::Type; fn get_meta_api() -> glib::Type;
@ -210,6 +210,9 @@ impl<'a, U> MetaRefMut<'a, Meta, U> {
#[repr(C)] #[repr(C)]
pub struct Meta(gst_sys::GstMeta); pub struct Meta(gst_sys::GstMeta);
unsafe impl Send for Meta {}
unsafe impl Sync for Meta {}
impl Meta { impl Meta {
fn get_api(&self) -> glib::Type { fn get_api(&self) -> glib::Type {
unsafe { glib::Type::from_glib((*self.0.info).api) } unsafe { glib::Type::from_glib((*self.0.info).api) }
@ -235,6 +238,9 @@ impl fmt::Debug for Meta {
#[repr(C)] #[repr(C)]
pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta); pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta);
unsafe impl Send for ParentBufferMeta {}
unsafe impl Sync for ParentBufferMeta {}
impl ParentBufferMeta { impl ParentBufferMeta {
pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> { pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> {
unsafe { unsafe {
@ -276,6 +282,11 @@ impl fmt::Debug for ParentBufferMeta {
#[repr(C)] #[repr(C)]
pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta); pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta);
#[cfg(any(feature = "v1_14", feature = "dox"))]
unsafe impl Send for ReferenceTimestampMeta {}
#[cfg(any(feature = "v1_14", feature = "dox"))]
unsafe impl Sync for ReferenceTimestampMeta {}
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
impl ReferenceTimestampMeta { impl ReferenceTimestampMeta {
pub fn add<'a>( pub fn add<'a>(

View file

@ -99,6 +99,9 @@ pub enum PadProbeData<'a> {
__Unknown(*mut gst_sys::GstMiniObject), __Unknown(*mut gst_sys::GstMiniObject),
} }
unsafe impl<'a> Send for PadProbeData<'a> {}
unsafe impl<'a> Sync for PadProbeData<'a> {}
#[derive(Debug)] #[derive(Debug)]
pub struct StreamLock(Pad); pub struct StreamLock(Pad);
impl Drop for StreamLock { impl Drop for StreamLock {

View file

@ -25,6 +25,9 @@ glib_wrapper! {
} }
} }
unsafe impl Send for ParseContext {}
unsafe impl Sync for ParseContext {}
impl ParseContext { impl ParseContext {
pub fn new() -> Self { pub fn new() -> Self {
unsafe { from_glib_full(gst_sys::gst_parse_context_new()) } unsafe { from_glib_full(gst_sys::gst_parse_context_new()) }

View file

@ -508,6 +508,7 @@ impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
impl<T: FormattedValue> Eq for FormattedSegment<T> {} impl<T: FormattedValue> Eq for FormattedSegment<T> {}
unsafe impl<T: FormattedValue> Send for FormattedSegment<T> {} unsafe impl<T: FormattedValue> Send for FormattedSegment<T> {}
unsafe impl<T: FormattedValue> Sync for FormattedSegment<T> {}
impl<T: FormattedValue> Clone for FormattedSegment<T> { impl<T: FormattedValue> Clone for FormattedSegment<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {

View file

@ -25,6 +25,7 @@ macro_rules! gst_plugin_define(
#[repr(C)] #[repr(C)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc); pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
unsafe impl Send for GstPluginDesc {}
unsafe impl Sync for GstPluginDesc {} unsafe impl Sync for GstPluginDesc {}
#[no_mangle] #[no_mangle]

View file

@ -23,6 +23,7 @@ macro_rules! gst_plugin_define(
#[repr(C)] #[repr(C)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc); pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
unsafe impl Send for GstPluginDesc {}
unsafe impl Sync for GstPluginDesc {} unsafe impl Sync for GstPluginDesc {}
static GST_PLUGIN_DESC: GstPluginDesc = GstPluginDesc($crate::gst_sys::GstPluginDesc { static GST_PLUGIN_DESC: GstPluginDesc = GstPluginDesc($crate::gst_sys::GstPluginDesc {

View file

@ -96,8 +96,6 @@ impl<'a> TypeFind<'a> {
} }
} }
unsafe impl<'a> Send for TypeFind<'a> {}
impl TypeFindFactory { impl TypeFindFactory {
pub fn call_function(&self, find: &mut dyn TypeFindImpl) { pub fn call_function(&self, find: &mut dyn TypeFindImpl) {
unsafe { unsafe {