using System.Collections.Concurrent;
using System.Diagnostics;
using Server.Core;
using Debug = MrWu.Debug.Debug;

namespace Server.Net
{
    public class ServiceThreadManager : SingleInstance<ServiceThreadManager>
    {
        /// <summary>
        /// 线程管理
        /// </summary>
        public ConcurrentDictionary<AService, int> Threads = new ConcurrentDictionary<AService, int>();

        public void CheckThread(AService service,int threadId)
        {
            if (Threads.TryGetValue(service,out int _threadId))
            {
                if (_threadId != threadId)
                {
                    StackTrace stackTrace = new StackTrace();
                    Debug.Error($"线程ID不一致:{_threadId} {threadId} {stackTrace.ToString()}");
                }
            }
            else if (!Threads.TryAdd(service, threadId))
            {
                Debug.Error("未正常添加到线程管理!");
            }
        }
    }
}