@@ -7,7 +7,7 @@ use crate::{
7
7
} ,
8
8
system:: { ExclusiveSystem , System } ,
9
9
} ;
10
- use std:: { borrow:: Cow , ptr :: NonNull } ;
10
+ use std:: { borrow:: Cow , cell :: UnsafeCell } ;
11
11
12
12
/// System metadata like its name, labels, order requirements and component access.
13
13
pub trait SystemContainer : GraphNode < Label = BoxedSystemLabel > {
@@ -106,7 +106,7 @@ impl SystemContainer for ExclusiveSystemContainer {
106
106
}
107
107
108
108
pub struct ParallelSystemContainer {
109
- system : NonNull < dyn System < In = ( ) , Out = ( ) > > ,
109
+ system : Box < UnsafeCell < dyn System < In = ( ) , Out = ( ) > > > ,
110
110
pub ( crate ) run_criteria_index : Option < usize > ,
111
111
pub ( crate ) run_criteria_label : Option < BoxedRunCriteriaLabel > ,
112
112
pub ( crate ) should_run : bool ,
@@ -123,7 +123,8 @@ unsafe impl Sync for ParallelSystemContainer {}
123
123
impl ParallelSystemContainer {
124
124
pub ( crate ) fn from_descriptor ( descriptor : ParallelSystemDescriptor ) -> Self {
125
125
ParallelSystemContainer {
126
- system : unsafe { NonNull :: new_unchecked ( Box :: into_raw ( descriptor. system ) ) } ,
126
+ // SAFE: it is fine to wrap inner value with UnsafeCell, as it is repr(transparent)
127
+ system : unsafe { Box :: from_raw ( Box :: into_raw ( descriptor. system ) as * mut _ ) } ,
127
128
should_run : false ,
128
129
run_criteria_index : None ,
129
130
run_criteria_label : None ,
@@ -140,20 +141,19 @@ impl ParallelSystemContainer {
140
141
}
141
142
142
143
pub fn system ( & self ) -> & dyn System < In = ( ) , Out = ( ) > {
143
- // SAFE: statically enforced shared access.
144
- unsafe { self . system . as_ref ( ) }
144
+ // SAFE: statically enforced shared access
145
+ unsafe { self . system . get ( ) . as_ref ( ) . unwrap ( ) }
145
146
}
146
147
147
148
pub fn system_mut ( & mut self ) -> & mut dyn System < In = ( ) , Out = ( ) > {
148
- // SAFE: statically enforced exclusive access.
149
- unsafe { self . system . as_mut ( ) }
149
+ self . system . get_mut ( )
150
150
}
151
151
152
152
/// # Safety
153
153
/// Ensure no other borrows exist along with this one.
154
154
#[ allow( clippy:: mut_from_ref) ]
155
155
pub unsafe fn system_mut_unsafe ( & self ) -> & mut dyn System < In = ( ) , Out = ( ) > {
156
- & mut * self . system . as_ptr ( )
156
+ self . system . get ( ) . as_mut ( ) . unwrap ( )
157
157
}
158
158
159
159
pub fn should_run ( & self ) -> bool {
0 commit comments