File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -119,9 +119,11 @@ create_opaque_type!(dispatch_io_s, dispatch_io_t);
119
119
pub const DISPATCH_QUEUE_SERIAL : dispatch_queue_attr_t = core:: ptr:: null_mut ( ) ;
120
120
121
121
/// 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 > = {
123
123
// 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
+ } )
125
127
} ;
126
128
127
129
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 {
251
253
// SAFETY: Always safe to get pointer from static, only needed for MSRV.
252
254
unsafe { addr_of ! ( _dispatch_main_q) as dispatch_queue_main_t }
253
255
}
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 > { }
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ impl From<QueueAttribute> for dispatch_queue_attr_t {
22
22
fn from ( value : QueueAttribute ) -> Self {
23
23
match value {
24
24
QueueAttribute :: Serial => DISPATCH_QUEUE_SERIAL ,
25
- QueueAttribute :: Concurrent => DISPATCH_QUEUE_CONCURRENT as * const _ as * mut _ ,
25
+ QueueAttribute :: Concurrent => DISPATCH_QUEUE_CONCURRENT . 0 as * const _ as * mut _ ,
26
26
_ => panic ! ( "Unknown QueueAttribute value: {:?}" , value) ,
27
27
}
28
28
}
You can’t perform that action at this time.
0 commit comments