File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
UnityAsync/Assets/UnityAsync/Manager Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,16 @@ public void Process()
5757
5858 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5959 public void Add ( in T cont )
60+ {
61+ if ( InUnityContext )
62+ AddFast ( cont ) ;
63+ else
64+ AddThreadSafe ( cont ) ;
65+ }
66+
67+ // only call in UnitySynchronizationContext - not thread safe
68+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
69+ void AddFast ( in T cont )
6070 {
6171 try
6272 {
@@ -86,6 +96,15 @@ public void Add(in T cont)
8696 }
8797 }
8898
99+ // use when you may be adding an awaiter from outside of UnitySynchronizationContext
100+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
101+ async void AddThreadSafe ( T cont )
102+ {
103+ await UnitySyncContext ;
104+
105+ AddFast ( cont ) ;
106+ }
107+
89108 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
90109 static void AssertQueueSize ( int queueSize )
91110 {
You can’t perform that action at this time.
0 commit comments