예제 #1
0
 /// <summary>
 /// This is called by the long jobs instance of the ComparisonCase class when it is done running its
 /// comparison and it is ready to remove itself from the running list to allow new jobs to continue
 /// </summary>
 /// <param name="cc">ComparisonCase instance of the job that just finished</param>
 internal static void removeLongRunningCase(ComparisonCase cc)
 {
     lock (FSTService.Instance.runningCasesLock)
     {
         FSTService.Instance.longRunningCases.Remove(cc);
     }
 }
예제 #2
0
        private void dequeueJobs()
        {
            int maxJobs     = Environment.ProcessorCount;
            int maxLongJobs = (Environment.ProcessorCount > 4) ? 2 : 1;         // give ourselves an extra long job thread if we have over four cores. ideally, this would be the default configuration

            if (maxJobs > 1)
            {
                maxJobs -= maxLongJobs;              // leave a processor for the big jobs, but don't block small jobs if we're on a single core box (please don't run this on a single core box)
            }
            while (!stopThreads)
            {
                lock (runningCasesLock)
                {
                    DataRow dr = null;

                    // if we're not maxxed out on normal threads, try to dequeue and start a job
                    if (runningCases.Count < maxJobs)
                    {
                        lock (jobQueueLock)
                        {
                            if (jobQueue.Count > 0)
                            {
                                dr = jobQueue.Dequeue();
                            }
                        }

                        if (dr != null)
                        {
                            // this is where we start jobs (new thread is created in constructor)
                            ComparisonCase cc = new ComparisonCase(dr);
                            runningCases.Add(cc);
                        }
                    }

                    DataRow drLong = null;

                    // if we're not maxxed out on long job threads, try to dequeue and start a job
                    if (longRunningCases.Count < maxLongJobs)
                    {
                        lock (jobQueueLock)
                        {
                            if (longJobQueue.Count > 0)
                            {
                                drLong = longJobQueue.Dequeue();
                            }
                        }

                        if (drLong != null)
                        {
                            // this is where we start jobs (new thread is created in constructor)
                            ComparisonCase cc = new ComparisonCase(drLong);
                            longRunningCases.Add(cc);
                        }
                    }
                }
                Thread.Sleep(1000);
            }
        }