internal bool Lock(Table obj) { if (obj.RowNo == 0) { throw new System.InvalidOperationException("MinBase: Attempt to lock an object which hasn't been loaded from file " + File.LoFile.Name + "."); } SyncWrite.WaitOne(); RowLock lk; while (true) { if (!LockList.TryGetValue(obj.RowNo, out lk)) { break; } bool rv = lk.Lock(); SyncWrite.ReleaseMutex(); if (rv) { return(true); } System.Threading.Thread.Sleep(0); SyncWrite.WaitOne(); } lk = new RowLock(); File.Lock(obj); LockList.Add(obj.RowNo, lk); Read(obj, obj.RowNo); SyncWrite.ReleaseMutex(); return(true); }
public Index(string nm, ushort kl, DateTime udTime) { int sz = DataFile.GetSize(Root); if (DataFile.Exists(nm, "Index")) { File = DataFile.Open(nm, "Index", FileMode.Open); File.Read(Root, DataFile.coSignatureSz, sz); if (DateTime.Compare(Root.LastUpdate, udTime) >= 0 && Root.Closed) { Root.Closed = false; File.Lock(Root); File.Write(Root); return; } File.Close(); DataFile.Delete(nm, "Index"); } File = DataFile.Open(nm, "Index", FileMode.CreateNew); DataFile.Blank(Root, sz); Root.KeyLength = kl; Root.Closed = false; Root.PageSize = (ushort)DataFile.GetSize(new IdxPage(0, 0, 0, kl)); File.Append(Root, sz); File.Lock(Root); }