/// <summary> /// Attempts to schedule a write of the specified length into the file. /// </summary> /// <returns> /// A valid block address representing the location where the written /// block will be found, or a 'None' address if the file does not /// currently have enough room for this. /// </returns> /// <remarks> /// The provided writer will be invoked at some point in the future. /// /// Thread-safe. /// </remarks> public BlockAddress TryScheduleWrite( uint realm, Hash hash, int length, WithSpan.ReadWrite writer) { if (length < 0) { throw new ArgumentException($"Negative length: {length}", nameof(length)); } int rank; long offset; lock (_syncRoot) { offset = _offset; _offset = BlockAddress.Ceiling(offset + BlockHeader.Size + length); if (_offset > _file.Length) { // Since this file is about to be flushed and closed, // because it's "full enough", we prevent additional writes. _offset = _file.Length; return(BlockAddress.None); } rank = _flags.Count; _flags.Append(ReadFlag.Triggered(() => PerformWrite(offset, writer))); } // We touched '_offset' and '_flags' in the critical section, the remaining // work on the actual byte span can be done without mutex. var span = _file.AsMemory(offset, BlockHeader.Size).Span; ref var header = ref MemoryMarshal.Cast <byte, BlockHeader>(span)[0];
/// <summary> Construct from a read-only file. </summary> /// <remarks> /// Used when recovering files written by a previous program /// instance from their locations. /// </remarks> public BlockFile(IFileMemory file, uint fileId) { _pinner = new Pinner(); _file = file ?? throw new ArgumentNullException(nameof(file)); FileId = fileId; _flags = new AppendList <ReadFlag>(); var offset = 0L; while (offset < _file.Length) { var block = AtOffset(offset); ref var header = ref block.Header; if (header.Rank != _flags.Count || header.ContentLength < 0 || header.ContentLength + BlockHeader.Size > _file.Length) { // The header of the block appears broken. Do not include // it in the list, and stop scanning (since we don't know // how far to jump ahead). break; } var thisOffset = offset; _flags.Append(ReadFlag.Triggered(() => VerifyAtOffset(thisOffset))); offset += block.RelativeOffsetToNextBlock; }
public void Update(bool[] deleteFlags) { DbTransaction t = readFlags.BeginTransaction(); for (int i = 0; i < Mails.Count; ++i) { if (deleteFlags[i]) { ReadFlag r = new ReadFlag(); r.PaymentId = ((Mail)mails[i]).id; readFlags.Add(r); } } t.Commit(); }
public void SetAsmSim(AsmSimulator asmSimulator, int lineNumber, bool isExpanded) { this._asmSimulator = asmSimulator; this._lineNumber = lineNumber; bool empty = true; if (this._asmSimulator.Enabled & Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip) { this._itemsOnPage = new List <TextBox>(); this.AsmSimGridExpander.IsExpanded = isExpanded; this.AsmSimGridExpanderNumeration.Text = Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration; var(ReadReg, WriteReg, ReadFlag, WriteFlag, MemRead, MemWrite) = this._asmSimulator.Get_Usage(lineNumber); var readReg = new HashSet <Rn>(ReadReg); var writeReg = new HashSet <Rn>(WriteReg); this.GenerateHeader(); int row = 2; foreach (Rn reg in Enum.GetValues(typeof(Rn))) { bool b1 = readReg.Contains(reg); bool b2 = writeReg.Contains(reg); if (b1 || b2) { empty = false; if (b1) { this.Generate(reg, true, row); } if (b2) { this.Generate(reg, false, row); } row++; } } foreach (Flags flag in FlagTools.GetFlags(ReadFlag | WriteFlag)) { if (flag == Flags.NONE) { continue; } bool b1 = ReadFlag.HasFlag(flag); bool b2 = WriteFlag.HasFlag(flag); if (b1 || b2) { empty = false; if (b1) { this.Generate(flag, true, row); } if (b2) { this.Generate(flag, false, row); } row++; } } } this.AsmSimGridExpander.Visibility = (empty) ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridBorder.Visibility = (empty) ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridExpanderNumeration.SelectionChanged += (sender, i) => { string numerationStr = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString(); NumerationEnum numeration = AsmSourceTools.ParseNumeration(numerationStr); if (numeration == NumerationEnum.UNKNOWN) { AsmDudeToolsStatic.Output_WARNING("SetAsmSim:smSimGridExpanderNumeration.SelectionChanged: unknown numerationStr=" + numerationStr); } //AsmDudeToolsStatic.Output_INFO("AsmSimGridExpanderNumeration:SelectionChanged: numeration="+ numeration); foreach (var textBox in this._itemsOnPage) { var info = textBox.Tag as ButtonInfo; string content = (info.reg == Rn.NOREG) ? this._asmSimulator.Get_Flag_Value_If_Already_Computed(info.flag, this._lineNumber, info.before) : this._asmSimulator.Get_Register_Value_If_Already_Computed(info.reg, this._lineNumber, info.before, numeration); if (content != null) { textBox.Text = info.reg.ToString() + " = " + content; } } }; }
public void Update(bool[] deleteFlags) { DbTransaction t = readFlags.BeginTransaction(); for (int i=0; i<Mails.Count; ++i) { if (deleteFlags[i]) { ReadFlag r = new ReadFlag(); r.PaymentId = ((Mail)mails[i]).id; readFlags.Add(r); } } t.Commit(); }