use std::fmt;
#[allow(non_camel_case_types)]
pub(crate) type dispatch_queue_attr_t = *mut dispatch_queue_attr_s;
#[repr(C)]
#[allow(non_camel_case_types)]
pub(crate) struct dispatch_queue_attr_s {
_priv: [u8; 0],
}
#[repr(transparent)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct DispatchQueueAttributes(
u64,
);
impl fmt::Debug for DispatchQueueAttributes {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("DispatchQueueAttributes")
.field("is_concurrent", &self.is_concurrent())
.field("is_initially_inactive", &self.is_initially_inactive())
.finish()
}
}
const SHIFT_CONCURRENT: u64 = 1;
const SHIFT_INACTIVE: u64 = 2;
const FLAG_CONCURRENT: u64 = 1 << SHIFT_CONCURRENT;
const FLAG_INACTIVE: u64 = 1 << SHIFT_INACTIVE;
impl DispatchQueueAttributes {
pub const SERIAL: Self = Self(0);
pub const SERIAL_INACTIVE: Self = Self::SERIAL.with_initially_inactive(true);
pub const CONCURRENT: Self = Self(FLAG_CONCURRENT);
pub const CONCURRENT_INACTIVE: Self = Self::CONCURRENT.with_initially_inactive(true);
#[inline]
pub const fn is_concurrent(&self) -> bool {
self.0 & FLAG_CONCURRENT != 0
}
#[inline]
pub const fn with_concurrent(self, yes: bool) -> Self {
Self((self.0 & !FLAG_CONCURRENT) | ((yes as u64) << SHIFT_CONCURRENT))
}
#[inline]
pub const fn is_initially_inactive(&self) -> bool {
self.0 & FLAG_INACTIVE != 0
}
#[inline]
pub const fn with_initially_inactive(self, yes: bool) -> Self {
Self((self.0 & !FLAG_INACTIVE) | ((yes as u64) << SHIFT_INACTIVE))
}
#[inline]
pub(crate) fn _to_raw(&self) -> dispatch_queue_attr_t {
const DISPATCH_QUEUE_SERIAL: dispatch_queue_attr_t = 0 as _;
extern "C" {
static mut _dispatch_queue_attr_concurrent: dispatch_queue_attr_s;
fn dispatch_queue_attr_make_initially_inactive(
attr: dispatch_queue_attr_t,
) -> dispatch_queue_attr_t;
}
let mut attr = DISPATCH_QUEUE_SERIAL;
if self.is_concurrent() {
attr = unsafe { &mut _dispatch_queue_attr_concurrent };
}
if self.is_initially_inactive() {
attr = unsafe { dispatch_queue_attr_make_initially_inactive(attr) };
}
attr
}
}