Ejemplo n.º 1
0
        /// <summary>
        /// 多线程并行建图
        /// </summary>
        /// <param name="threadCount">并行线程数量</param>
        private unsafe void buildGraph(int threadCount)
        {
            node bootNode = NodePool[boot];

            Monitor.Enter(nodeLock);
            try
            {
                list <int> reader = getBuildGraphReader(ref bootNode);
                if (reader.Count != 0)
                {
                    int            taskCount = threadCount - 1;
                    graphBuilder[] builders  = new graphBuilder[threadCount];
                    for (int builderIndex = 0; builderIndex != builders.Length; builders[builderIndex++].Set(ref bootNode))
                    {
                        ;
                    }
                    using (fastCSharp.threading.task task = new fastCSharp.threading.task(taskCount))
                    {
                        do
                        {
                            int[] readerArray = reader.UnsafeArray;
                            int   count = reader.Count / threadCount, index = 0;
                            for (int builderIndex = 0; builderIndex != taskCount; ++builderIndex)
                            {
                                builders[builderIndex].Set(readerArray, index, index += count);
                                task.Add(builders[builderIndex].Build);
                            }
                            builders[taskCount].Set(readerArray, index, reader.Count);
                            builders[taskCount].Build();
                            task.WaitFree();
                            reader.Empty();
                            for (int builderIndex = 0; builderIndex != builders.Length; ++builderIndex)
                            {
                                list <int> writer = builders[builderIndex].Writer;
                                if (writer.Count != 0)
                                {
                                    reader.Add(writer.UnsafeArray, 0, writer.Count);
                                }
                            }
                        }while (reader.Count != 0);
                    }
                }
            }
            finally { Monitor.Exit(nodeLock); }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 定时任务信息
 /// </summary>
 /// <param name="task">任务处理</param>
 public timerTask(task task)
 {
     this.task      = task ?? task.Default;
     timer.Elapsed += onTimer;
 }