Esempio n. 1
0
        public ParallelProcessor(Action <int, float> componentAction)
        {
            ParallelProcessorWorkers.Setup();
            ParallelProcessorWorkers._processorInstanceCount++;

            processActionData = new ProcessActionData[ParallelProcessorWorkers.MaxWorkerCount];
            processActions    = new Action[ParallelProcessorWorkers.MaxWorkerCount];
            for (int i = 0; i < ParallelProcessorWorkers.MaxWorkerCount; ++i)
            {
                processActionData[i] = new ProcessActionData();
                int threadID = i;
                processActions[i] = () => {
                    //Thread.MemoryBarrier();
                    try {
                        ProcessActionData processData = processActionData[threadID];
                        for (int componentIndex = processData.startComponentIndex; componentIndex <= processData.endComponentIndex; ++componentIndex)
                        {
                            componentAction(componentIndex, processData.deltaTime);
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine("Error in ParallelSystemComponentsProcessor: " + e.Message);
                        UnityEngine.Debug.LogException(e);
                    }
                    finally {
                        //Interlocked.Decrement(ref workingCount);
                        lock (ParallelProcessorWorkers._workingCountLocker) {
                            ParallelProcessorWorkers._workingCount--;
                            Monitor.Pulse(ParallelProcessorWorkers._workingCountLocker);
                        }
                    }
                };
            }
        }
Esempio n. 2
0
        public ParallelProcessorList(int initialSize, Thread[] otherThreads = null)
        {
            ParallelProcessorWorkers.Setup();

            if (initialSize > 0)
            {
                threadLists = new List <List <T> >(initialSize);
            }
            else
            {
                threadLists = new List <List <T> >();
            }

            threadListLUT = new Dictionary <int, List <T> >(ParallelProcessorWorkers.MaxWorkerCount);

            //Create worker thread lists
            foreach (Thread t in ParallelProcessorWorkers.Workers)
            {
                List <T> list = new List <T>();
                threadLists.Add(list);
                threadListLUT[t.ManagedThreadId] = list;
            }
            //Also create lists for other threads?
            if (otherThreads != null)
            {
                foreach (Thread t in otherThreads)
                {
                    List <T> list = new List <T>();
                    threadLists.Add(list);
                    threadListLUT[t.ManagedThreadId] = list;
                }
            }
        }