Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2017-03-23 20:34:57 +0300
committerMarek Safar <marek.safar@gmail.com>2017-03-24 16:35:18 +0300
commitba36f4d6220554113a9a9b0dc3ddaf8b909583d5 (patch)
treee67c7a5a68b0c8092b12d499fe1d0d9355eceec6 /mcs/class/System.Core
parent9e79e8849434837125795445b6b241741ecfb75d (diff)
[bcl] Add a finalizer to MemoryMappedFile.
Diffstat (limited to 'mcs/class/System.Core')
-rw-r--r--mcs/class/System.Core/Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs6
-rw-r--r--mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs30
2 files changed, 18 insertions, 18 deletions
diff --git a/mcs/class/System.Core/Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs b/mcs/class/System.Core/Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs
index a862bf05db1..85b3fd50c14 100644
--- a/mcs/class/System.Core/Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs
+++ b/mcs/class/System.Core/Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs
@@ -31,6 +31,7 @@ using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Permissions;
using System.Security.Principal;
+using System.IO.MemoryMappedFiles;
namespace Microsoft.Win32.SafeHandles
{
@@ -42,10 +43,11 @@ namespace Microsoft.Win32.SafeHandles
handle = preexistingHandle;
}
- [MonoTODO]
protected override bool ReleaseHandle ()
{
- throw new NotImplementedException ();
+ MemoryMapImpl.CloseMapping (handle);
+ handle = IntPtr.Zero;
+ return true;
}
}
}
diff --git a/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs b/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs
index 7a3cce164f6..4adaaf514fe 100644
--- a/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs
+++ b/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs
@@ -33,7 +33,6 @@ using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
-
namespace System.IO.MemoryMappedFiles
{
internal static class MemoryMapImpl {
@@ -113,7 +112,6 @@ namespace System.IO.MemoryMappedFiles
}
}
-
public class MemoryMappedFile : IDisposable {
// MemoryMappedFileAccess fileAccess;
// string name;
@@ -127,7 +125,7 @@ namespace System.IO.MemoryMappedFiles
//
FileStream stream;
bool keepOpen;
- IntPtr handle;
+ SafeMemoryMappedFileHandle handle;
public static MemoryMappedFile CreateFromFile (string path)
{
@@ -147,7 +145,7 @@ namespace System.IO.MemoryMappedFiles
IntPtr handle = MemoryMapImpl.OpenFile (path, mode, null, out capacity, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None);
return new MemoryMappedFile () {
- handle = handle,
+ handle = new SafeMemoryMappedFileHandle (handle, true),
// fileAccess = MemoryMappedFileAccess.ReadWrite,
// fileCapacity = capacity
};
@@ -179,7 +177,7 @@ namespace System.IO.MemoryMappedFiles
IntPtr handle = MemoryMapImpl.OpenFile (path, mode, mapName, out capacity, access, MemoryMappedFileOptions.None);
return new MemoryMappedFile () {
- handle = handle,
+ handle = new SafeMemoryMappedFileHandle (handle, true),
// fileAccess = access,
// name = mapName,
// fileCapacity = capacity
@@ -202,7 +200,7 @@ namespace System.IO.MemoryMappedFiles
MemoryMapImpl.ConfigureHandleInheritability (handle, inheritability);
return new MemoryMappedFile () {
- handle = handle,
+ handle = new SafeMemoryMappedFileHandle (handle, true),
// fileAccess = access,
// name = mapName,
// fileCapacity = capacity,
@@ -229,7 +227,7 @@ namespace System.IO.MemoryMappedFiles
MemoryMapImpl.ConfigureHandleInheritability (handle, inheritability);
return new MemoryMappedFile () {
- handle = handle,
+ handle = new SafeMemoryMappedFileHandle (handle, true),
// fileAccess = access,
// name = mapName,
// fileCapacity = capacity,
@@ -252,7 +250,7 @@ namespace System.IO.MemoryMappedFiles
IntPtr handle = MemoryMapImpl.OpenFile (null, mode, mapName, out capacity, access, options);
return new MemoryMappedFile () {
- handle = handle,
+ handle = new SafeMemoryMappedFileHandle (handle, true),
// fileAccess = access,
// name = mapName,
// fileCapacity = capacity
@@ -339,7 +337,7 @@ namespace System.IO.MemoryMappedFiles
public MemoryMappedViewStream CreateViewStream (long offset, long size, MemoryMappedFileAccess access)
{
- var view = MemoryMappedView.Create (handle, offset, size, access);
+ var view = MemoryMappedView.Create (handle.DangerousGetHandle (), offset, size, access);
return new MemoryMappedViewStream (view);
}
@@ -355,7 +353,7 @@ namespace System.IO.MemoryMappedFiles
public MemoryMappedViewAccessor CreateViewAccessor (long offset, long size, MemoryMappedFileAccess access)
{
- var view = MemoryMappedView.Create (handle, offset, size, access);
+ var view = MemoryMappedView.Create (handle.DangerousGetHandle (), offset, size, access);
return new MemoryMappedViewAccessor (view);
}
@@ -370,16 +368,16 @@ namespace System.IO.MemoryMappedFiles
protected virtual void Dispose (bool disposing)
{
- if (disposing){
- if (stream != null){
+ if (disposing) {
+ if (stream != null) {
if (keepOpen == false)
stream.Close ();
stream = null;
}
- if (handle != IntPtr.Zero) {
- MemoryMapImpl.CloseMapping (handle);
- handle = IntPtr.Zero;
- }
+ }
+ if (handle != null) {
+ handle.Dispose ();
+ handle = null;
}
}