File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ public void BeginDeferred()
1818 if ( IsMerging )
1919 return ;
2020
21- _worldState . Locks += 1 ;
22- EcsAssert . Assert ( _worldState . Locks > 0 , "" ) ;
21+ var locks = _worldState . Begin ( ) ;
22+ EcsAssert . Assert ( locks > 0 , "" ) ;
2323 }
2424
2525
@@ -28,14 +28,14 @@ public void EndDeferred()
2828 if ( IsMerging )
2929 return ;
3030
31- _worldState . Locks -= 1 ;
32- EcsAssert . Assert ( _worldState . Locks >= 0 , "" ) ;
31+ var locks = _worldState . End ( ) ;
32+ EcsAssert . Assert ( locks >= 0 , "" ) ;
3333
34- if ( _worldState . Locks == 0 && _operations . Count > 0 )
34+ if ( locks == 0 && _operations . Count > 0 )
3535 {
36- _worldState . Locks = - 1 ;
36+ _worldState . Lock ( ) ;
3737 Merge ( ) ;
38- _worldState . Locks = 0 ;
38+ _worldState . Unlock ( ) ;
3939 }
4040 }
4141
@@ -163,6 +163,11 @@ private void Merge()
163163 struct WorldState
164164 {
165165 public int Locks ;
166+
167+ public int Lock ( ) => Locks = - 1 ;
168+ public int Unlock ( ) => Locks = 0 ;
169+ public int Begin ( ) => Interlocked . Increment ( ref Locks ) ;
170+ public int End ( ) => Interlocked . Decrement ( ref Locks ) ;
166171 }
167172
168173 struct DeferredOp
You can’t perform that action at this time.
0 commit comments