| 171 | } |
| 172 | |
| 173 | void FMjShmRegion::Close(bool bDeleteFile) |
| 174 | { |
| 175 | if (MappedAddr == nullptr) |
| 176 | return; |
| 177 | |
| 178 | #if PLATFORM_WINDOWS |
| 179 | ::UnmapViewOfFile(MappedAddr); |
| 180 | if (PlatformMappingHandle) |
| 181 | ::CloseHandle(static_cast<HANDLE>(PlatformMappingHandle)); |
| 182 | if (PlatformFileHandle) |
| 183 | ::CloseHandle(static_cast<HANDLE>(PlatformFileHandle)); |
| 184 | #else |
| 185 | ::munmap(MappedAddr, static_cast<size_t>(MappedSize)); |
| 186 | if (PlatformFileHandle) |
| 187 | { |
| 188 | const int fd = static_cast<int>(reinterpret_cast<intptr_t>(PlatformFileHandle)); |
| 189 | ::close(fd); |
| 190 | } |
| 191 | #endif |
| 192 | |
| 193 | if (bDeleteFile && !FilePath.IsEmpty()) |
| 194 | { |
| 195 | IFileManager::Get().Delete(*FilePath, /*RequireExists=*/false, /*EvenReadOnly=*/false, /*Quiet=*/true); |
| 196 | } |
| 197 | |
| 198 | MappedAddr = nullptr; |
| 199 | PlatformFileHandle = nullptr; |
| 200 | PlatformMappingHandle = nullptr; |
| 201 | MappedSize = 0; |
| 202 | BufferStride = 0; |
| 203 | NumBuffers = 0; |
| 204 | FilePath.Reset(); |
| 205 | } |
no test coverage detected