public virtual void Dispose() { if (Disposed) { return; } if (PagerState != null) { PagerState.Release(); PagerState = null; } Task.WaitAll(_tasks.ToArray()); Disposed = true; GC.SuppressFinalize(this); }
public virtual void Dispose() { if (Disposed) { return; } _options.IoMetrics.FileClosed(FileName); if (_pagerState != null) { _pagerState.Release(); _pagerState = null; } Disposed = true; NativeMemory.UnregisterFileMapping(FileName); GC.SuppressFinalize(this); }
public void SetPagerState(PagerState newState) { if (DisposeOnceRunner.Disposed) { ThrowAlreadyDisposedException(); } lock (_pagerStateModificationLocker) { newState.AddRef(); if (ShouldLockMemoryAtPagerLevel()) { // Note: This is handled differently in 32-bits. // Locking/unlocking the memory is done separately for each mapping. try { foreach (var info in newState.AllocationInfos) { if (info.Size == 0 || info.BaseAddress == null) { continue; } Lock(info.BaseAddress, info.Size, state: null); } } catch { // need to restore the state to the way it was, so we'll dispose the pager state newState.Release(); throw; } } _debugInfo = GetSourceName(); var oldState = _pagerState; _pagerState = newState; PagerStateChanged?.Invoke(newState); oldState?.Release(); } }
public PureMemoryPager(byte[] data) { var ptr = Marshal.AllocHGlobal(data.Length); var buffer = new Buffer { Handle = ptr, Base = (byte *)ptr.ToPointer(), Size = data.Length }; _buffers = _buffers.Append(buffer); NumberOfAllocatedPages = data.Length / PageSize; PagerState.Release(); PagerState = new PagerState(this); PagerState.AddRef(); fixed(byte *origin = data) { NativeMethods.memcpy(buffer.Base, origin, data.Length); } }
public PosixTempMemoryMapPager(string file, long?initialFileSize = null) { _file = file; _fd = Syscall.open(_file, OpenFlags.O_RDWR | OpenFlags.O_CREAT | OpenFlags.O_EXCL, FilePermissions.S_IWUSR | FilePermissions.S_IRUSR); if (_fd == -1) { PosixHelper.ThrowLastError(Marshal.GetLastWin32Error()); } DeleteOnClose = true; SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE); _totalAllocationSize = NearestSizeToPageSize(initialFileSize ?? _totalAllocationSize); PosixHelper.AllocateFileSpace(_fd, (ulong)_totalAllocationSize); NumberOfAllocatedPages = _totalAllocationSize / PageSize; PagerState.Release(); PagerState = CreatePagerState(); }
public PosixMemoryMapPager(int pageSize, string file, long?initialFileSize = null) : base(pageSize) { _file = file; _isSyncDirAllowed = PosixHelper.CheckSyncDirectoryAllowed(_file); PosixHelper.EnsurePathExists(_file); _fd = Syscall.open(file, OpenFlags.O_RDWR | OpenFlags.O_CREAT, FilePermissions.S_IWUSR | FilePermissions.S_IRUSR); if (_fd == -1) { var err = Marshal.GetLastWin32Error(); PosixHelper.ThrowLastError(err); } SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE); _totalAllocationSize = GetFileSize(); if (_totalAllocationSize == 0 && initialFileSize.HasValue) { _totalAllocationSize = NearestSizeToPageSize(initialFileSize.Value); } if (_totalAllocationSize == 0 || _totalAllocationSize % SysPageSize != 0 || _totalAllocationSize != GetFileSize()) { _totalAllocationSize = NearestSizeToPageSize(_totalAllocationSize); PosixHelper.AllocateFileSpace(_fd, (ulong)_totalAllocationSize); } if (_isSyncDirAllowed && PosixHelper.SyncDirectory(file) == -1) { var err = Marshal.GetLastWin32Error(); PosixHelper.ThrowLastError(err); } NumberOfAllocatedPages = _totalAllocationSize / _pageSize; PagerState.Release(); PagerState = CreatePagerState(); }
public override void AllocateMorePages(Transaction tx, long newLength) { var oldSize = NumberOfAllocatedPages * PageSize; if (newLength < oldSize) { throw new ArgumentException("Cannot set the legnth to less than the current length"); } if (newLength == oldSize) { return; // nothing to do } var increaseSize = (newLength - oldSize); NumberOfAllocatedPages += increaseSize / PageSize; var newPtr = Marshal.AllocHGlobal(new IntPtr(increaseSize)); var buffer = new Buffer { Handle = newPtr, Base = (byte *)newPtr.ToPointer(), Size = increaseSize }; _buffers = _buffers.Append(buffer); var newPager = new PagerState(this); newPager.AddRef(); // one for the pager if (tx != null) // we only pass null during startup, and we don't need it there { newPager.AddRef(); // one for the current transaction tx.AddPagerState(newPager); } PagerState.Release(); PagerState = newPager; }