public void Reallocate(ulong size) { _freeSectors.Clear(); _size = size; _totalSectorCount = MathHelper.Roundup(_size, SectorSize) / SectorSize; _usingSectorCount = 0; _bitmapStorage.SetLength(_totalSectorCount); }
public async ValueTask CheckBlocks(Action <CheckBlocksProgressReport> progress, CancellationToken token) { await Task.Run(() => { // 重複するセクタを確保したブロックを検出しRemoveする。 lock (_lockObject) { using (var bitmapManager = new BitStorage(_bufferPool)) { bitmapManager.SetLength(this.Size / SectorSize); var hashes = new List <OmniHash>(); foreach (var(hash, clusterInfo) in _clusterMetadataMap) { foreach (var sector in clusterInfo.Sectors) { if (!bitmapManager.Get(sector)) { bitmapManager.Set(sector, true); } else { hashes.Add(hash); break; } } } foreach (var hash in hashes) { this.Remove(hash); } } } // 読めないブロックを検出しRemoveする。 { var list = this.ToArray(); uint badCount = 0; uint checkedCount = 0; uint blockCount = (uint)list.Length; token.ThrowIfCancellationRequested(); progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); foreach (var hash in list) { token.ThrowIfCancellationRequested(); lock (_lockObject) { if (this.Contains(hash)) { bool result = this.TryGet(hash, out var memoryOwner); if (!result) { badCount++; } memoryOwner?.Dispose(); } } checkedCount++; if (checkedCount % 32 == 0) { progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); } } progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); } }, token); }