/// <summary>
 ///     文件读取器
 /// </summary>
 /// <param name="fileName">文件名称</param>
 public TmphFileReader(TmphPhysical physical)
 {
     this.physical = physical;
     fileStream = new FileStream(physical.path + physical.fileName, FileMode.Open, FileAccess.Read,
         FileShare.ReadWrite, TmphAppSetting.StreamBufferSize, FileOptions.SequentialScan);
     size = fileStream.Length;
     waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
     clientHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
     if ((size & 3) == 0 && size >= sizeof(int) * 3) TmphThreadPool.TinyPool.FastStart(read, null, null);
     else
     {
         Dispose();
         physical.dataError();
     }
 }
 /// <summary>
 ///     设置数据库物理层
 /// </summary>
 /// <param name="fileName">数据文件名</param>
 /// <param name="physical">数据库物理层</param>
 public void Set(string fileName, TmphPhysical physical)
 {
     FileName = fileName;
     Physical = physical;
 }
 /// <summary>
 ///     清除数据库物理层
 /// </summary>
 /// <param name="identity">索引编号</param>
 public void Clear()
 {
     Physical = null;
     FileName.Null();
     ++Identity;
 }
 /// <summary>
 ///     打开数据库
 /// </summary>
 /// <param name="fileName">数据文件名</param>
 /// <returns>数据库物理层初始化信息</returns>
 internal TmphPhysicalServer.TmphPhysicalIdentity Open(string fileName)
 {
     var physicalInfo = new TmphPhysicalServer.TmphPhysicalIdentity
     {
         Identity = new TmphPhysicalServer.TmphTimeIdentity { TimeTick = 0, Index = -1 }
     };
     if (isDisposed == 0)
     {
         TmphHashString key = fileName;
         TmphInterlocked.NoCheckCompareSetSleep0(ref physicalLock);
         try
         {
             if (!fileNameIndexs.ContainsKey(key))
                 fileNameIndexs.Add(key, physicalInfo.Identity.Index = newIndex());
         }
         finally
         {
             physicalLock = 0;
         }
         if (physicalInfo.Identity.Index != -1)
         {
             try
             {
                 var physical = new TmphPhysical(fileName, false);
                 if (!physical.IsDisposed)
                 {
                     TmphInterlocked.NoCheckCompareSetSleep0(ref physicalLock);
                     physicals[physicalInfo.Identity.Index].Set(fileName, physical);
                     physicalLock = 0;
                     physicalInfo.Identity.Identity = physicals[physicalInfo.Identity.Index].Identity;
                     physicalInfo.Identity.TimeTick = TmphPub.StartTime.Ticks;
                     physicalInfo.IsLoader = physical.IsLoader;
                 }
             }
             finally
             {
                 if (physicalInfo.Identity.TimeTick == 0)
                 {
                     TmphInterlocked.NoCheckCompareSetSleep0(ref physicalLock);
                     try
                     {
                         fileNameIndexs.Remove(key);
                     }
                     finally
                     {
                         physicalLock = 0;
                     }
                 }
             }
         }
     }
     return physicalInfo;
 }