/// <summary> /// 超时检测 /// </summary> public void Refresh() { int index = Pool.PoolIndex; while (index != 0) { if (Pool.Enter()) { DateTime now = date.nowTime.Now; if (index > Pool.PoolIndex) { index = Pool.PoolIndex; } try { for (int endIndex = Math.Max(index - 1024, 0); index != endIndex;) { if (Pool.Pool[--index].CheckTimeout(now)) { Pool.FreeContinue(index); } } } finally { Pool.Exit(); } } else { return; } } }
/// <summary> /// 打开数据库 /// </summary> /// <param name="fileName">数据文件名</param> /// <returns>数据库物理层初始化信息</returns> internal physicalServer.physicalIdentity Open(string fileName) { physicalServer.physicalIdentity physicalInfo = new physicalServer.physicalIdentity { Identity = new physicalServer.timeIdentity { TimeTick = 0, Index = -1 } }; if (isDisposed == 0) { hashString key = fileName; if (physicalPool.Enter()) { if (fileNameIndexs.ContainsKey(key)) { physicalPool.Exit(); } else { try { fileNameIndexs.Add(key, physicalInfo.Identity.Index = physicalPool.GetIndexContinue()); } finally { physicalPool.Exit(); } } if (physicalInfo.Identity.Index != -1) { try { physical physical = new physical(fileName, false); if (!physical.IsDisposed) { if (physicalPool.Enter()) { physicalPool.Pool[physicalInfo.Identity.Index].Set(fileName, physical); physicalPool.Exit(); } physicalInfo.Identity.Identity = physicalPool.Pool[physicalInfo.Identity.Index].Identity; physicalInfo.Identity.TimeTick = fastCSharp.pub.StartTime.Ticks; physicalInfo.IsLoader = physical.IsLoader; } } finally { if (physicalInfo.Identity.TimeTick == 0 && physicalPool.Enter()) { fileNameIndexs.Remove(key); physicalPool.Exit(); } } } } } return(physicalInfo); }
/// <summary> /// TCP服务端注册 /// </summary> /// <returns>TCP服务端标识</returns> internal clientId Register() { clientInfo clientInfo = new clientInfo(); indexIdentity identity; if (clientPool.Enter()) { try { identity.Index = clientPool.GetIndexContinue();//不能写成一行,可能造成Pool先入栈然后被修改,导致索引溢出 identity.Identity = clientPool.Pool[identity.Index].Set(clientInfo); } finally { clientPool.Exit(); } return(new clientId { Tick = logStream.Ticks, Identity = identity }); } clientPool.Exit(); return(default(clientId)); }