Exemple #1
0
            /// <summary>
            /// 创建内存对象关系图
            /// </summary>
            public graphBuilder()
            {
                HashSet <Type> checkTypes = hashSet.CreateOnly <Type>();

                foreach (Type type in fastCSharp.checkMemory.GetTypes().ToArray())
                {
                    if (checkTypes.Contains(type))
                    {
                        fastCSharp.log.Error.Add("重复类型 " + type.fullName(), new System.Diagnostics.StackFrame(), false);
                    }
                    else
                    {
                        checkTypes.Add(type);
                    }
                }
                int count = checkTypes.Count;

                if (count != 0)
                {
                    StaticTypes = new staticType[count];
                    types       = dictionary.CreateOnly <Type, typeInfo>();
                    values      = dictionary <objectReference> .Create <value>();

                    arrayBuilders = dictionary.CreateOnly <Type, Action>();
                    staticValues  = new list <staticValue>();
                    foreach (Type type in checkTypes)
                    {
                        currentType = type;
                        buildStatic();
                        StaticTypes[checkTypes.Count - count].Set(type, staticValues);
                        if (--count == 0)
                        {
                            break;
                        }
                        staticValues.Empty();
                    }
                    values        = null;
                    arrayBuilders = null;
                    staticValues  = null;
                    checkTypes    = null;
                    typeNames     = dictionary.CreateOnly <string, typeInfo>();
                    foreach (typeInfo type in types.Values)
                    {
                        typeNames[type.Type.FullName] = type;
                    }
                    types           = null;
                    searcher        = new searcher(StaticTypes);
                    searcher.OnType = searchTypeFields;
                    searcher.Start();
                }
            }
Exemple #2
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); }
        }
        /// <summary>
        /// 超时检测
        /// </summary>
        private void refreshTimeout()
        {
            DateTime time = date.NowSecond;
            int      count = 0, isRefresh = 1;

            Monitor.Enter(dictionaryLock);
            try
            {
                if (refreshValues.Count < this.values.Count)
                {
                    refreshValues.Empty();
                    refreshValues.AddLength(this.values.Count);
                }
                keyValue <keyType, valueType>[] refreshValueArray = refreshValues.UnsafeArray;
                foreach (KeyValuePair <keyType, value> values in this.values)
                {
                    if (time >= values.Value.Timeout)
                    {
                        refreshValueArray[count++].Set(values.Key, values.Value.Value);
                    }
                }
                if (count != 0)
                {
                    foreach (keyValue <keyType, valueType> value in refreshValueArray)
                    {
                        remove(value.Key, value.Value);
                        if (--count == 0)
                        {
                            break;
                        }
                    }
                }
                if (this.values.Count == 0)
                {
                    isRefresh = this.isRefresh = 0;
                }
            }
            finally { Monitor.Exit(dictionaryLock); }
            if (isRefresh != 0)
            {
                timerTask.Default.Add(refresh, date.NowSecond.AddTicks(timeoutTicks));
            }
        }
Exemple #4
0
 /// <summary>
 /// 建图
 /// </summary>
 public unsafe void Build()
 {
     Writer.Empty();
     fixed(int *readerFixed = reader)
     {
         while (startIndex != endIndex)
         {
             node fatherNode = pool[readerFixed[startIndex++]];
             if (fatherNode.Link == 0)
             {
                 foreach (KeyValuePair <keyType, int> nextNode in fatherNode.Nodes)
                 {
                     if (pool[nextNode.Value].GetNodeCount(Boot, nextNode.Key) != 0)
                     {
                         Writer.Add(nextNode.Value);
                     }
                 }
             }
             else
             {
                 foreach (KeyValuePair <keyType, int> nextNode in fatherNode.Nodes)
                 {
                     int link = fatherNode.Link, linkNode = 0;
                     while (pool[link].GetLinkWhereNull(nextNode.Key, ref linkNode, ref link) != 0)
                     {
                         ;
                     }
                     if (linkNode == 0)
                     {
                         Boot.TryGetValue(nextNode.Key, out linkNode);
                     }
                     if (pool[nextNode.Value].GetNodeCount(linkNode) != 0)
                     {
                         Writer.Add(nextNode.Value);
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// 日志信息写文件
        /// </summary>
        private void output()
        {
            while (!isStop)
            {
                Monitor.Enter(logLock);
                try
                {
                    if (newDebugs.Count == 0)
                    {
                        Monitor.Wait(logLock);
                    }
                    list <debug> oldDebugs = currentDebugs;
                    currentDebugs = newDebugs;
                    newDebugs     = oldDebugs;
                }
                finally { Monitor.Exit(logLock); }
                output(string.Join(@"
- - - - - - - - - -
", currentDebugs.GetArray(error => error.ToString())));
                currentDebugs.Empty();
            }
            newDebugs = null;
        }