Skip to content

Commit 60f2b3c

Browse files
committed
MSRV workaround DISPATCH_QUEUE_CONCURRENT
1 parent 403639a commit 60f2b3c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

crates/dispatch2/src/ffi.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ create_opaque_type!(dispatch_io_s, dispatch_io_t);
119119
pub const DISPATCH_QUEUE_SERIAL: dispatch_queue_attr_t = core::ptr::null_mut();
120120

121121
/// A dispatch queue that executes blocks concurrently.
122-
pub const DISPATCH_QUEUE_CONCURRENT: dispatch_queue_attr_t = {
122+
pub static DISPATCH_QUEUE_CONCURRENT: ImmutableStatic<dispatch_queue_attr_t> = {
123123
// Safety: immutable external definition
124-
unsafe { &_dispatch_queue_attr_concurrent as *const _ as dispatch_queue_attr_t }
124+
ImmutableStatic(unsafe {
125+
&_dispatch_queue_attr_concurrent as *const _ as dispatch_queue_attr_t
126+
})
125127
};
126128

127129
pub const DISPATCH_APPLY_AUTO: dispatch_queue_t = core::ptr::null_mut();
@@ -251,3 +253,13 @@ pub extern "C" fn dispatch_get_main_queue() -> dispatch_queue_main_t {
251253
// SAFETY: Always safe to get pointer from static, only needed for MSRV.
252254
unsafe { addr_of!(_dispatch_main_q) as dispatch_queue_main_t }
253255
}
256+
257+
/// Wrapper type for immutable static variables exported from C,
258+
/// that are documented to be safe for sharing and passing between threads.
259+
#[repr(transparent)]
260+
#[derive(Debug)]
261+
pub struct ImmutableStatic<T>(pub T);
262+
// Safety: safety is guaranteed by the external type.
263+
unsafe impl<T> Sync for ImmutableStatic<T> {}
264+
// Safety: safety is guaranteed by the external type.
265+
unsafe impl<T> Send for ImmutableStatic<T> {}

crates/dispatch2/src/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl From<QueueAttribute> for dispatch_queue_attr_t {
2121
fn from(value: QueueAttribute) -> Self {
2222
match value {
2323
QueueAttribute::Serial => DISPATCH_QUEUE_SERIAL,
24-
QueueAttribute::Concurrent => DISPATCH_QUEUE_CONCURRENT as *const _ as *mut _,
24+
QueueAttribute::Concurrent => DISPATCH_QUEUE_CONCURRENT.0 as *const _ as *mut _,
2525
_ => panic!("Unknown QueueAttribute value: {:?}", value),
2626
}
2727
}

0 commit comments

Comments
 (0)