This repository was archived by the owner on Dec 22, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
UpdateLib/UpdateLib/Tasks Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ public static WorkerScheduler Instance
3939 private readonly AtomicInteger m_currentWorkerCount ;
4040 private readonly AsyncTask m_dispatcherTask ;
4141 private readonly ManualResetEvent m_waitForAvailableWorker ;
42+ private readonly object sync = new object ( ) ;
4243
4344 #endregion
4445
@@ -65,19 +66,22 @@ private void Dispatcher()
6566 AsyncTask task = null ;
6667 while ( m_taskQueue . TryDequeue ( out task ) )
6768 {
68- if ( task . IsCompleted || task . IsCancelled || task . HasErrors )
69- continue ;
69+ lock ( sync )
70+ {
71+ if ( task . IsCompleted || task . IsCancelled || task . HasErrors )
72+ continue ;
7073
71- SetupTask ( task ) ;
74+ SetupTask ( task ) ;
7275
73- if ( m_currentWorkerCount . Value >= MAX_WORKERS )
74- m_waitForAvailableWorker . Reset ( ) ;
76+ if ( m_currentWorkerCount . Value >= MAX_WORKERS )
77+ m_waitForAvailableWorker . Reset ( ) ;
7578
76- m_waitForAvailableWorker . WaitOne ( ) ;
79+ m_waitForAvailableWorker . WaitOne ( ) ;
7780
78- Logger . Debug ( GetType ( ) . Name , $ "Current worker count: { m_currentWorkerCount . Increment ( ) } ") ;
81+ Logger . Debug ( GetType ( ) . Name , $ "Current worker count: { m_currentWorkerCount . Increment ( ) } | Current queue count: { m_taskQueue . Count } ") ;
7982
80- task . ConfigureAwait ( false ) . Start ( ) ;
83+ task . ConfigureAwait ( false ) . Start ( ) ;
84+ }
8185 }
8286 }
8387
You can’t perform that action at this time.
0 commit comments