Example #1
0
        public PosixPageFileBackedMemoryMapPager(string file, long?initialFileSize = null)
        {
            var instanceId = Interlocked.Increment(ref _counter);

            _file = "/" + Syscall.getpid() + "-" + instanceId + "-" + file;
            _fd   = Rt.shm_open(_file, OpenFlags.O_RDWR | OpenFlags.O_CREAT, (int)FilePermissions.ALLPERMS);
            if (_fd == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }

            SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE);

            if (initialFileSize.HasValue)
            {
                _totalAllocationSize = NearestSizeToPageSize(initialFileSize.Value);
            }

            _totalAllocationSize = NearestSizeToPageSize(_totalAllocationSize);
            var result = Syscall.ftruncate(_fd, _totalAllocationSize);

            if (result != 0)
            {
                PosixHelper.ThrowLastError(result);
            }

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
            PagerState.Release();
            PagerState = CreatePagerState();
        }
Example #2
0
 public override void Dispose()
 {
     base.Dispose();
     if (_fd != -1)
     {
         Syscall.close(_fd);
         Rt.shm_unlink(_file);
         _fd = -1;
     }
 }