From 9d2c9f9d39c1ba9ce3b989f55d42b72dd3df4fc4 Mon Sep 17 00:00:00 2001 From: turbocool3r Date: Fri, 25 Jun 2021 00:02:00 +0300 Subject: [PATCH] Add as_raw() methods for queues, groups and semaphores. --- src/group.rs | 6 ++++++ src/queue.rs | 6 ++++++ src/sem.rs | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/group.rs b/src/group.rs index 6ba6c5b..9eb2c4c 100644 --- a/src/group.rs +++ b/src/group.rs @@ -10,6 +10,7 @@ use crate::queue::Queue; /// allows for aggregate synchronization, so you can track when all the /// closures complete, even if they are running on different queues. #[derive(Debug)] +#[repr(transparent)] pub struct Group { ptr: dispatch_group_t, } @@ -80,6 +81,11 @@ impl Group { }; result == 0 } + + /// Returns the raw underlying `dispatch_group_t` value. + pub fn as_raw(&self) -> dispatch_group_t { + self.ptr + } } unsafe impl Sync for Group { } diff --git a/src/queue.rs b/src/queue.rs index 46ed9cd..26c9ad8 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -72,6 +72,7 @@ impl QueuePriority { /// For more information, see Apple's [Grand Central Dispatch reference]( /// https://developer.apple.com/library/mac/documentation/Performance/Reference/GCD_libdispatch_Ref/index.html). #[derive(Debug)] +#[repr(transparent)] pub struct Queue { pub(crate) ptr: dispatch_queue_t, } @@ -281,6 +282,11 @@ impl Queue { pub fn suspend(&self) -> SuspendGuard { SuspendGuard::new(self) } + + /// Returns the raw underlying `dispatch_queue_t` value. + pub fn as_raw(&self) -> dispatch_queue_t { + self.ptr + } } unsafe impl Sync for Queue { } diff --git a/src/sem.rs b/src/sem.rs index b6faa24..3654f15 100644 --- a/src/sem.rs +++ b/src/sem.rs @@ -6,6 +6,7 @@ use crate::{time_after_delay, WaitTimeout}; /// A counting semaphore. #[derive(Debug)] +#[repr(transparent)] pub struct Semaphore { ptr: dispatch_semaphore_t, } @@ -69,6 +70,11 @@ impl Semaphore { self.wait_timeout(timeout)?; Ok(SemaphoreGuard::new(self.clone())) } + + /// Returns the raw underlying `dispatch_semaphore_t` value. + pub fn as_raw(&self) -> dispatch_semaphore_t { + self.ptr + } } unsafe impl Sync for Semaphore {}