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

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs')
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs b/src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs
index 46a996348..004e95287 100644
--- a/src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/Mutex.Unix.cs
@@ -2,24 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.IO;
+using System.Runtime.InteropServices;
namespace System.Threading
{
public sealed partial class Mutex
{
- private static void VerifyNameForCreate(string name)
+ private void CreateMutexCore(bool initiallyOwned, string name, out bool createdNew)
{
if (name != null)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
}
- }
-
- private void CreateMutexCore(bool initiallyOwned, string name, out bool createdNew)
- {
- Debug.Assert(name == null);
SafeWaitHandle = WaitSubsystem.NewMutex(initiallyOwned);
createdNew = true;
@@ -30,9 +27,25 @@ namespace System.Threading
throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
}
- private static void ReleaseMutexCore(IntPtr handle)
+ public void ReleaseMutex()
{
- WaitSubsystem.ReleaseMutex(handle);
+ // The field value is modifiable via the public <see cref="WaitHandle.SafeWaitHandle"/> property, save it locally
+ // to ensure that one instance is used in all places in this method
+ SafeWaitHandle waitHandle = _waitHandle;
+ if (waitHandle == null)
+ {
+ ThrowInvalidHandleException();
+ }
+
+ waitHandle.DangerousAddRef();
+ try
+ {
+ WaitSubsystem.ReleaseMutex(waitHandle.DangerousGetHandle());
+ }
+ finally
+ {
+ waitHandle.DangerousRelease();
+ }
}
}
}