summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Threading/Mutex.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Threading/Mutex.cs')
-rw-r--r--src/mscorlib/src/System/Threading/Mutex.cs92
1 files changed, 48 insertions, 44 deletions
diff --git a/src/mscorlib/src/System/Threading/Mutex.cs b/src/mscorlib/src/System/Threading/Mutex.cs
index dcb821307a..454a323f9a 100644
--- a/src/mscorlib/src/System/Threading/Mutex.cs
+++ b/src/mscorlib/src/System/Threading/Mutex.cs
@@ -11,8 +11,9 @@
**
**
=============================================================================*/
-namespace System.Threading
-{
+
+namespace System.Threading
+{
using System;
using System.Threading;
using System.Runtime.CompilerServices;
@@ -28,7 +29,7 @@ namespace System.Threading
public sealed class Mutex : WaitHandle
{
- static bool dummyBool;
+ private static bool dummyBool;
internal class MutexSecurity
{
@@ -46,12 +47,12 @@ namespace System.Threading
// 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 PLATFORM_WINDOWS
if (name != null && System.IO.Path.MaxPath < name.Length)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name));
+ throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, Path.MaxPath), nameof(name));
}
-#endif
+#endif // PLATFORM_WINDOWS
Contract.EndContractBlock();
Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
@@ -67,20 +68,20 @@ namespace System.Threading
RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
tryCode,
cleanupCode,
- cleanupInfo);
+ cleanupInfo);
createdNew = tryCodeHelper.m_newMutex;
}
- internal class MutexTryCodeHelper
+ internal class MutexTryCodeHelper
{
- bool m_initiallyOwned;
- MutexCleanupInfo m_cleanupInfo;
+ private bool m_initiallyOwned;
+ private MutexCleanupInfo m_cleanupInfo;
internal bool m_newMutex;
- String m_name;
- Win32Native.SECURITY_ATTRIBUTES m_secAttrs;
- Mutex m_mutex;
+ private String m_name;
+ private Win32Native.SECURITY_ATTRIBUTES m_secAttrs;
+ private Mutex m_mutex;
- internal MutexTryCodeHelper(bool initiallyOwned,MutexCleanupInfo cleanupInfo, String name, Win32Native.SECURITY_ATTRIBUTES secAttrs, Mutex mutex)
+ internal MutexTryCodeHelper(bool initiallyOwned, MutexCleanupInfo cleanupInfo, String name, Win32Native.SECURITY_ATTRIBUTES secAttrs, Mutex mutex)
{
Debug.Assert(name == null || name.Length != 0);
@@ -92,16 +93,16 @@ namespace System.Threading
}
internal void MutexTryCode(object userData)
- {
+ {
SafeWaitHandle mutexHandle = null;
// try block
RuntimeHelpers.PrepareConstrainedRegions();
- try
+ try
{
}
- finally
+ finally
{
- if (m_initiallyOwned)
+ if (m_initiallyOwned)
{
m_cleanupInfo.inCriticalRegion = true;
}
@@ -109,15 +110,15 @@ namespace System.Threading
int errorCode = 0;
RuntimeHelpers.PrepareConstrainedRegions();
- try
+ try
{
}
- finally
+ finally
{
errorCode = CreateMutexHandle(m_initiallyOwned, m_name, m_secAttrs, out mutexHandle);
- }
+ }
- if (mutexHandle.IsInvalid)
+ if (mutexHandle.IsInvalid)
{
mutexHandle.SetHandleAsInvalid();
if (m_name != null)
@@ -127,11 +128,11 @@ 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", Interop.Sys.MaxName), "name");
+ throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, Interop.Sys.MaxName), "name");
#endif
case Win32Native.ERROR_INVALID_HANDLE:
- throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", m_name));
+ throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, m_name));
}
}
__Error.WinIOError(errorCode, m_name);
@@ -140,19 +141,21 @@ namespace System.Threading
m_mutex.SetHandleInternal(mutexHandle);
m_mutex.hasThreadAffinity = true;
-
}
}
private void MutexCleanupCode(Object userData, bool exceptionThrown)
{
- MutexCleanupInfo cleanupInfo = (MutexCleanupInfo) userData;
-
+ MutexCleanupInfo cleanupInfo = (MutexCleanupInfo)userData;
+
// If hasThreadAffinity isn't true, we've thrown an exception in the above try, and we must free the mutex
// on this OS thread before ending our thread affninity.
- if(!hasThreadAffinity) {
- if (cleanupInfo.mutexHandle != null && !cleanupInfo.mutexHandle.IsInvalid) {
- if( cleanupInfo.inCriticalRegion) {
+ if (!hasThreadAffinity)
+ {
+ if (cleanupInfo.mutexHandle != null && !cleanupInfo.mutexHandle.IsInvalid)
+ {
+ if (cleanupInfo.inCriticalRegion)
+ {
Win32Native.ReleaseMutex(cleanupInfo.mutexHandle);
}
cleanupInfo.mutexHandle.Dispose();
@@ -171,7 +174,8 @@ namespace System.Threading
}
}
- public Mutex(bool initiallyOwned, String name) : this(initiallyOwned, name, out dummyBool) {
+ public Mutex(bool initiallyOwned, String name) : this(initiallyOwned, name, out dummyBool)
+ {
}
public Mutex(bool initiallyOwned) : this(initiallyOwned, null, out dummyBool)
@@ -181,7 +185,7 @@ namespace System.Threading
public Mutex() : this(false, null, out dummyBool)
{
}
-
+
private Mutex(SafeWaitHandle handle)
{
SetHandleInternal(handle);
@@ -190,7 +194,7 @@ namespace System.Threading
public static Mutex OpenExisting(string name)
{
- return OpenExisting(name, (MutexRights) 0);
+ return OpenExisting(name, (MutexRights)0);
}
internal enum MutexRights
@@ -206,7 +210,7 @@ namespace System.Threading
throw new WaitHandleCannotBeOpenedException();
case OpenExistingResult.NameInvalid:
- throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name));
+ throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
case OpenExistingResult.PathNotFound:
__Error.WinIOError(Win32Native.ERROR_PATH_NOT_FOUND, name);
@@ -226,17 +230,17 @@ namespace System.Threading
{
if (name == null)
{
- throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_WithParamName"));
+ throw new ArgumentNullException(nameof(name), SR.ArgumentNull_WithParamName);
}
- if(name.Length == 0)
+ if (name.Length == 0)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name));
+ throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
}
#if !PLATFORM_UNIX
- if(System.IO.Path.MaxPath < name.Length)
+ if (System.IO.Path.MaxPath < name.Length)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name));
+ throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, Path.MaxPath), nameof(name));
}
#endif
Contract.EndContractBlock();
@@ -258,11 +262,11 @@ 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", Interop.Sys.MaxName), nameof(name));
+ throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, Interop.Sys.MaxName), nameof(name));
}
#endif
- if(Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
+ if (Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
return OpenExistingResult.NameNotFound;
if (Win32Native.ERROR_PATH_NOT_FOUND == errorCode)
return OpenExistingResult.PathNotFound;
@@ -270,7 +274,7 @@ namespace System.Threading
return OpenExistingResult.NameInvalid;
// this is for passed through Win32Native Errors
- __Error.WinIOError(errorCode,name);
+ __Error.WinIOError(errorCode, name);
}
result = new Mutex(myHandle);
@@ -287,11 +291,11 @@ namespace System.Threading
}
else
{
- throw new ApplicationException(Environment.GetResourceString("Arg_SynchronizationLockException"));
+ throw new ApplicationException(SR.Arg_SynchronizationLockException);
}
}
- static int CreateMutexHandle(bool initiallyOwned, String name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle)
+ private static int CreateMutexHandle(bool initiallyOwned, String name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle)
{
int errorCode;