diff options
Diffstat (limited to 'src/mscorlib/src/System/Threading/Mutex.cs')
-rw-r--r-- | src/mscorlib/src/System/Threading/Mutex.cs | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/src/mscorlib/src/System/Threading/Mutex.cs b/src/mscorlib/src/System/Threading/Mutex.cs index 506abb7a07..dcb821307a 100644 --- a/src/mscorlib/src/System/Threading/Mutex.cs +++ b/src/mscorlib/src/System/Threading/Mutex.cs @@ -16,7 +16,6 @@ namespace System.Threading using System; using System.Threading; using System.Runtime.CompilerServices; - using System.Security.Permissions; using System.IO; using Microsoft.Win32; using Microsoft.Win32.SafeHandles; @@ -27,23 +26,20 @@ namespace System.Threading using System.Diagnostics; using System.Diagnostics.Contracts; - [ComVisible(true)] public sealed class Mutex : WaitHandle { static bool dummyBool; - public class MutexSecurity + internal class MutexSecurity { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public Mutex(bool initiallyOwned, String name, out bool createdNew) : this(initiallyOwned, name, out createdNew, (MutexSecurity)null) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - public unsafe Mutex(bool initiallyOwned, String name, out bool createdNew, MutexSecurity mutexSecurity) + internal unsafe Mutex(bool initiallyOwned, String name, out bool createdNew, MutexSecurity mutexSecurity) { if (name == string.Empty) { @@ -62,26 +58,6 @@ namespace System.Threading CreateMutexWithGuaranteedCleanup(initiallyOwned, name, out createdNew, secAttrs); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - internal Mutex(bool initiallyOwned, String name, out bool createdNew, Win32Native.SECURITY_ATTRIBUTES secAttrs) - { - if (name == string.Empty) - { - // Empty name is treated as an unnamed mutex. Set to null, and we will check for null from now on. - name = null; - } -#if !PLATFORM_UNIX - if (name != null && System.IO.Path.MaxPath < name.Length) - { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); - } -#endif - Contract.EndContractBlock(); - - CreateMutexWithGuaranteedCleanup(initiallyOwned, name, out createdNew, secAttrs); - } - - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] internal void CreateMutexWithGuaranteedCleanup(bool initiallyOwned, String name, out bool createdNew, Win32Native.SECURITY_ATTRIBUTES secAttrs) { RuntimeHelpers.CleanupCode cleanupCode = new RuntimeHelpers.CleanupCode(MutexCleanupCode); @@ -104,7 +80,6 @@ namespace System.Threading Win32Native.SECURITY_ATTRIBUTES m_secAttrs; Mutex m_mutex; - [PrePrepareMethod] internal MutexTryCodeHelper(bool initiallyOwned,MutexCleanupInfo cleanupInfo, String name, Win32Native.SECURITY_ATTRIBUTES secAttrs, Mutex mutex) { Debug.Assert(name == null || name.Length != 0); @@ -116,7 +91,6 @@ namespace System.Threading m_mutex = mutex; } - [PrePrepareMethod] internal void MutexTryCode(object userData) { SafeWaitHandle mutexHandle = null; @@ -153,7 +127,7 @@ namespace System.Threading #if PLATFORM_UNIX case Win32Native.ERROR_FILENAME_EXCED_RANGE: // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8 - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", PathInternal.MaxComponentLength), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Interop.Sys.MaxName), "name"); #endif case Win32Native.ERROR_INVALID_HANDLE: @@ -170,7 +144,6 @@ namespace System.Threading } } - [PrePrepareMethod] private void MutexCleanupCode(Object userData, bool exceptionThrown) { MutexCleanupInfo cleanupInfo = (MutexCleanupInfo) userData; @@ -198,21 +171,17 @@ namespace System.Threading } } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public Mutex(bool initiallyOwned, String name) : this(initiallyOwned, name, out dummyBool) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public Mutex(bool initiallyOwned) : this(initiallyOwned, null, out dummyBool) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public Mutex() : this(false, null, out dummyBool) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private Mutex(SafeWaitHandle handle) { SetHandleInternal(handle); @@ -224,11 +193,11 @@ namespace System.Threading return OpenExisting(name, (MutexRights) 0); } - public enum MutexRights + internal enum MutexRights { } - public static Mutex OpenExisting(string name, MutexRights rights) + internal static Mutex OpenExisting(string name, MutexRights rights) { Mutex result; switch (OpenExistingWorker(name, rights, out result)) @@ -253,11 +222,6 @@ namespace System.Threading return OpenExistingWorker(name, (MutexRights)0, out result) == OpenExistingResult.Success; } - public static bool TryOpenExisting(string name, MutexRights rights, out Mutex result) - { - return OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success; - } - private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result) { if (name == null) @@ -294,7 +258,7 @@ namespace System.Threading if (name != null && errorCode == Win32Native.ERROR_FILENAME_EXCED_RANGE) { // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8 - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", PathInternal.MaxComponentLength), nameof(name)); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Interop.Sys.MaxName), nameof(name)); } #endif @@ -316,7 +280,6 @@ namespace System.Threading // Note: To call ReleaseMutex, you must have an ACL granting you // MUTEX_MODIFY_STATE rights (0x0001). The other interesting value // in a Mutex's ACL is MUTEX_ALL_ACCESS (0x1F0001). - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public void ReleaseMutex() { if (Win32Native.ReleaseMutex(safeWaitHandle)) @@ -324,11 +287,10 @@ namespace System.Threading } else { - throw new Exception(Environment.GetResourceString("Arg_SynchronizationLockException")); + throw new ApplicationException(Environment.GetResourceString("Arg_SynchronizationLockException")); } } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] static int CreateMutexHandle(bool initiallyOwned, String name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle) { int errorCode; |