Beispiel #1
0
        public void Run(int threadCount)
        {
            _threads = CreateThreads(threadCount);

            Dictionary <Type, List <WorkTask> > groups = GenerateTaskGroups();

            HashSet <WorkTask> looseTasks;

            DistributeWork(_threads, groups, out looseTasks);

            ProviderRuntimeData runtimeData = new ProviderRuntimeData(looseTasks);

            foreach (WorkerThread workerThread in _threads)
            {
                if (workerThread.Tasks.Count == 0)
                {
                    continue;
                }
                workerThread.Start(runtimeData);
            }

            Dictionary <WorkerThread, HashSet <ulong> >         threadFiles = GetThreadFiles();
            Dictionary <WorkerThread, List <HashSet <ulong> > > taskFiles   = new Dictionary <WorkerThread, List <HashSet <ulong> > >();

            foreach (WorkerThread workerThread in _threads)
            {
                taskFiles[workerThread] = new List <HashSet <ulong> >();
                foreach (WorkTask workerThreadTask in workerThread.Tasks)
                {
                    if (workerThreadTask.RequiredCASCFiles.Count == 0)
                    {
                        continue;
                    }
                    HashSet <ulong> workerTaskFiles = new HashSet <ulong>();
                    foreach (ulong requiredCASCFile in workerThreadTask.RequiredCASCFiles)
                    {
                        workerTaskFiles.Add(requiredCASCFile);
                    }
                    taskFiles[workerThread].Add(workerTaskFiles);
                }
            }

            int taskIndex    = 0;
            int maxTaskIndex = _threads.Select(x => x.Tasks.Count).Max();

            // distribute casc files
            while (true)
            {
                foreach (WorkerThread workerThread in _threads)
                {
                    if (taskFiles[workerThread].Count > taskIndex)
                    {
                        HashSet <ulong> workerTaskFiles = taskFiles[workerThread][taskIndex];
                        foreach (ulong file in workerTaskFiles)
                        {
                            Stream stream = GetStream(file);
                            workerThread.CASCStreams[file] = stream;
                        }
                    }
                }

                taskIndex++;

                if (taskIndex == maxTaskIndex || maxTaskIndex == 0)
                {
                    break;
                }
            }

            foreach (WorkTask looseTask in runtimeData.LooseTasks)
            {
                foreach (ulong requiredCASCFile in looseTask.RequiredCASCFiles)
                {
                    Stream stream = GetStream(requiredCASCFile);
                    looseTask.CASCStreams[requiredCASCFile] = stream;
                }
            }
        }
Beispiel #2
0
 internal void Start(ProviderRuntimeData providerRuntimeData)
 {
     _providerRuntimeData = providerRuntimeData;
     _thread.Start();
 }