Merge pull request #3099 from marek-safar/rs-Semaphore
authorMarek Safar <marek.safar@gmail.com>
Fri, 3 Jun 2016 06:23:12 +0000 (08:23 +0200)
committerMarek Safar <marek.safar@gmail.com>
Fri, 3 Jun 2016 06:23:12 +0000 (08:23 +0200)
[System] Semaphore from referencesource

14 files changed:
mcs/class/System/ReferenceSources/NativeMethods.cs
mcs/class/System/System.Security.AccessControl/SemaphoreSecurity.cs
mcs/class/System/System.Threading/Semaphore.cs [deleted file]
mcs/class/System/System.dll.sources
mcs/class/System/Test/System.Threading/SemaphoreTest.cs
mcs/class/System/mobile_System.dll.sources
mcs/class/corlib/System/Environment.cs
mcs/class/referencesource/System/net/System/Net/_Semaphore.cs
mcs/class/referencesource/System/sys/system/IO/ports/InternalResources.cs
mcs/class/referencesource/System/sys/system/threading/semaphore.cs
mono/metadata/appdomain.c
mono/metadata/icall-def.h
mono/metadata/threads-types.h
mono/metadata/threads.c

index ca41ea97acc3c02541182d20d68ee18ccea42033..d2386472e08b004c4cc73f5225a0da81af5e7a46 100644 (file)
@@ -38,6 +38,15 @@ namespace Microsoft.Win32
                public const int WAIT_ABANDONED   = 0x00000080;
                public const int WAIT_ABANDONED_0 = WAIT_ABANDONED;
 
+               public const int ERROR_FILE_NOT_FOUND = 2;
+               public const int ERROR_PATH_NOT_FOUND = 3;
+               public const int ERROR_ACCESS_DENIED = 5;
+               public const int ERROR_INVALID_HANDLE = 6;
+               public const int ERROR_SHARING_VIOLATION = 32;
+               public const int ERROR_INVALID_NAME = 0x7B;
+               public const int ERROR_ALREADY_EXISTS = 183;
+               public const int ERROR_FILENAME_EXCED_RANGE = 0xCE;
+
                public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
                        out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
                {
index f0bdac661cb472752a9ae1a88bb026de0a897cfe..ac6db80037dfe506d1b2da49ad07c8196424eb33 100644 (file)
@@ -133,7 +133,7 @@ namespace System.Security.AccessControl
                        SetAuditRule((AuditRule)rule);
                }
                
-               internal new void PersistModifications (SafeHandle handle)
+               internal new void Persist (SafeHandle handle)
                {
                        WriteLock();
                        try {
diff --git a/mcs/class/System/System.Threading/Semaphore.cs b/mcs/class/System/System.Threading/Semaphore.cs
deleted file mode 100644 (file)
index 7ed2499..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-//
-// System.Threading.Semaphore.cs
-//
-// Author:
-//     Sebastien Pouliot  <sebastien@ximian.com>
-//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.InteropServices;
-using System.Security.AccessControl;
-using System.Security.Permissions;
-using System.Runtime.CompilerServices;
-using System.IO;
-
-namespace System.Threading {
-
-       [ComVisible (false)]
-       public sealed class Semaphore : WaitHandle {
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern IntPtr CreateSemaphore_internal (
-                       int initialCount, int maximumCount, string name,
-                       out bool createdNew);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern int ReleaseSemaphore_internal (
-                       IntPtr handle, int releaseCount, out bool fail);
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               private static extern IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out MonoIOError error);
-               
-               private Semaphore (IntPtr handle)
-               {
-                       Handle = handle;
-               }
-               
-               public Semaphore (int initialCount, int maximumCount)
-                       : this (initialCount, maximumCount, null)
-               {
-               }
-
-               public Semaphore (int initialCount, int maximumCount, string name)
-               {
-                       if (initialCount < 0)
-                               throw new ArgumentOutOfRangeException ("initialCount", "< 0");
-                       if (maximumCount < 1)
-                               throw new ArgumentOutOfRangeException ("maximumCount", "< 1");
-                       if (initialCount > maximumCount)
-                               throw new ArgumentException ("initialCount > maximumCount");
-
-                       bool created;
-                       
-                       Handle = CreateSemaphore_internal (initialCount,
-                                                          maximumCount, name,
-                                                          out created);
-               }
-
-               public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew)
-                       : this (initialCount, maximumCount, name, out createdNew, null)
-               {
-               }
-
-               [MonoTODO ("CreateSemaphore_internal does not support access control, semaphoreSecurity is ignored")]
-               public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew, 
-                       SemaphoreSecurity semaphoreSecurity)
-               {
-                       if (initialCount < 0)
-                               throw new ArgumentOutOfRangeException ("initialCount", "< 0");
-                       if (maximumCount < 1)
-                               throw new ArgumentOutOfRangeException ("maximumCount", "< 1");
-                       if (initialCount > maximumCount)
-                               throw new ArgumentException ("initialCount > maximumCount");
-
-                       Handle = CreateSemaphore_internal (initialCount,
-                                                          maximumCount, name,
-                                                          out createdNew);
-               }
-
-               public SemaphoreSecurity GetAccessControl ()
-               {
-                       return new SemaphoreSecurity (SafeWaitHandle,
-                                                     AccessControlSections.Owner |
-                                                     AccessControlSections.Group |
-                                                     AccessControlSections.Access);
-               }
-
-               [PrePrepareMethod]
-               [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
-               public int Release ()
-               {
-                       return (Release (1));
-               }
-
-               [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
-               public int Release (int releaseCount)
-               {
-                       if (releaseCount < 1)
-                               throw new ArgumentOutOfRangeException ("releaseCount");
-
-                       int ret;
-                       bool fail;
-                       
-                       ret = ReleaseSemaphore_internal (Handle, releaseCount,
-                                                        out fail);
-
-                       if (fail) {
-                               throw new SemaphoreFullException ();
-                       }
-
-                       return (ret);
-               }
-
-               public void SetAccessControl (SemaphoreSecurity semaphoreSecurity)
-               {
-                       if (semaphoreSecurity == null)
-                               throw new ArgumentNullException ("semaphoreSecurity");
-                               
-                       semaphoreSecurity.PersistModifications (SafeWaitHandle);
-               }
-
-               // static methods
-
-#if !MOBILE
-               public static Semaphore OpenExisting (string name)
-               {
-                       return OpenExisting (name, SemaphoreRights.Synchronize | SemaphoreRights.Modify);
-               }
-
-               public static Semaphore OpenExisting (string name, SemaphoreRights rights)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if ((name.Length ==0) || (name.Length > 260))
-                               throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
-
-                       MonoIOError error;
-                       IntPtr handle = OpenSemaphore_internal (name, rights,
-                                                               out error);
-                       if (handle == (IntPtr)null) {
-                               if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
-                                       throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Semaphore handle does not exist: ") + name);
-                               } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
-                                       throw new UnauthorizedAccessException ();
-                               } else {
-                                       throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
-                               }
-                       }
-                       
-                       return(new Semaphore (handle));
-               }
-
-               [SecurityPermissionAttribute (SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
-               public static bool TryOpenExisting (string name, out Semaphore result)
-               {
-                       return TryOpenExisting (name, SemaphoreRights.Synchronize | SemaphoreRights.Modify, out result);
-               }
-
-               [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
-               public static bool TryOpenExisting (string name, SemaphoreRights rights, out Semaphore result)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if ((name.Length == 0) || (name.Length > 260))
-                               throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
-                       
-                       MonoIOError error;
-                       IntPtr handle = OpenSemaphore_internal (name, rights, out error);
-
-                       if (handle == (IntPtr)null) {
-                               result = null;
-                               return false;
-                       }
-
-                       result = new Semaphore (handle);
-                       return true;
-               }
-#else
-               public static Semaphore OpenExisting (string name)
-               {
-                       throw new NotSupportedException ();
-               }
-
-               public static Semaphore OpenExisting (string name, SemaphoreRights rights)
-               {
-                       throw new NotSupportedException ();
-               }
-
-               public static bool TryOpenExisting (string name, out Semaphore result)
-               {
-                       throw new NotSupportedException ();
-               }
-
-               public static bool TryOpenExisting (string name, SemaphoreRights rights, out Semaphore result)
-               {
-                       throw new NotSupportedException ();
-               }
-#endif
-       }
-}
-
index b6f12007fa88a2e0d318d4f9dc08cbcab0d093dc..4ff3508c5c29ba9310c481ada3d4f8459b2b1f06 100644 (file)
@@ -489,7 +489,6 @@ System.Security.Permissions/StorePermissionAttribute.cs
 System.Security.Permissions/StorePermission.cs
 System.Security.Permissions/StorePermissionFlags.cs
 System/SRDescriptionAttribute.cs
-System.Threading/Semaphore.cs
 System.Threading/ThreadExceptionEventArgs.cs
 System.Threading/ThreadExceptionEventHandler.cs
 System.Timers/ElapsedEventArgs.cs
@@ -1084,12 +1083,16 @@ ReferenceSources/_SslStream.cs
 ../referencesource/System/net/System/Net/NetworkInformation/nodetype.cs
 ../referencesource/System/net/System/Net/NetworkInformation/pingexception.cs
 
+../referencesource/System/sys/system/IO/ports/InternalResources.cs
+
 ../referencesource/System/sys/system/runtime/interopservices/DefaultParameterValueAttribute.cs
 ../referencesource/System/sys/system/runtime/interopservices/handlecollector.cs
 
 ../referencesource/System/sys/system/runtime/versioning/FrameworkName.cs
 
 ../referencesource/System/sys/system/threading/Barrier.cs
+../referencesource/System/sys/system/threading/semaphore.cs
+
 ../referencesource/System/sys/system/windows/markup/ValueSerializerAttribute.cs
 
 ../referencesource/System/security/system/security/Authentication/ExtendedProtection/TokenBinding.cs
index e30968bf5adad0a3b22dcdf945de6579205a4b17..db3a57adab565ceadca022b8836d78ba7aec4563 100644 (file)
@@ -180,6 +180,15 @@ namespace MonoTests.System.Threading {
                        Assert.IsTrue (created, "Created");
                }
 
+               [Test]
+               public void Constructor_CreatedWithSameName ()
+               {
+                       var s1 = new Semaphore(1, 5, "name");
+                       bool created;
+                       var s2 = new Semaphore(1, 5, "name", out created);
+                       Assert.IsFalse (created);
+               }
+
                [Test]
                [Category ("MobileNotWorking")]
                public void Constructor_IntIntStringBoolSecurity ()
index 435360525a3a29d3e3fd9e3e37c10da92fb89220..af11ebf62f078c1b7728a9792fbe44aa8608210a 100644 (file)
@@ -264,7 +264,6 @@ System.Security.Cryptography.X509Certificates/X509VerificationFlags.cs
 System.Security.Cryptography/AsnEncodedData.cs
 System.Security.Cryptography/AsnEncodedDataCollection.cs
 System.Security.Cryptography/AsnEncodedDataEnumerator.cs
-System.Threading/Semaphore.cs
 System.Threading/ThreadExceptionEventArgs.cs
 System.Threading/ThreadExceptionEventHandler.cs
 System.Timers/ElapsedEventArgs.cs
@@ -799,12 +798,15 @@ ReferenceSources/Win32Exception.cs
 ../referencesource/System/net/System/Net/NetworkInformation/nodetype.cs
 ../referencesource/System/net/System/Net/NetworkInformation/pingexception.cs
 
+../referencesource/System/sys/system/IO/ports/InternalResources.cs
+
 ../referencesource/System/sys/system/runtime/interopservices/DefaultParameterValueAttribute.cs
 ../referencesource/System/sys/system/runtime/interopservices/handlecollector.cs
 
 ../referencesource/System/sys/system/runtime/versioning/FrameworkName.cs
 
 ../referencesource/System/sys/system/threading/Barrier.cs
+../referencesource/System/sys/system/threading/semaphore.cs
 
 ../referencesource/System/security/system/security/Authentication/ExtendedProtection/TokenBinding.cs
 
index 1db3482d019ccc57b6e6278a032da87be42b94f8..fd5e734534ef56ad965b2fc8621ab86df4206507 100644 (file)
@@ -57,7 +57,7 @@ namespace System {
                 * of icalls, do not require an increment.
                 */
 #pragma warning disable 169
-               private const int mono_corlib_version = 148;
+               private const int mono_corlib_version = 149;
 #pragma warning restore 169
 
                [ComVisible (true)]
index 6ad9cbe9f415da661f409592584cf94c08d82230..0365206cf5fb0949bdd7a36532f5726277e84b37 100644 (file)
@@ -21,8 +21,8 @@ namespace System.Net
         internal Semaphore(int initialCount, int maxCount) : base() {
             lock (this) {
 #if MONO
-                bool created;
-                Handle = System.Threading.Semaphore.CreateSemaphore_internal(initialCount, maxCount, null, out created);
+                int errorCode;
+                Handle = System.Threading.Semaphore.CreateSemaphore_internal(initialCount, maxCount, null, out errorCode);
 #else
                 // 
                 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
@@ -42,9 +42,8 @@ namespace System.Net
 
         internal bool ReleaseSemaphore() {
 #if MONO
-            bool fail;
-            var ret = System.Threading.Semaphore.ReleaseSemaphore_internal (Handle, 1, out fail);
-            return !fail;
+            int previousCount;
+            return System.Threading.Semaphore.ReleaseSemaphore_internal (Handle, 1, out previousCount);
 #else
 #if DEBUG
             int previousCount;
index 4d181e8c220ef641b32877061806d212cd3454a4..973773d29467b190eb5bc811cf07ab5f8f843ee4 100644 (file)
@@ -34,6 +34,7 @@ namespace System.IO.Ports
 #endif
         internal static String GetMessage(int errorCode) 
         {
+#if !MONO
             StringBuilder sb = new StringBuilder(512);
             int result = SafeNativeMethods.FormatMessage(NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS |
                 NativeMethods.FORMAT_MESSAGE_FROM_SYSTEM | NativeMethods.FORMAT_MESSAGE_ARGUMENT_ARRAY,
@@ -47,6 +48,7 @@ namespace System.IO.Ports
                 return s;
             }
             else 
+#endif
             {
                 return SR.GetString(SR.IO_UnknownError, errorCode);
             }
index 9a77cc0a64c37fb9de42a1f2f129bfefeb83a55a..360a55fa534abd5beff1d34fff8ac7d2a233e1c9 100644 (file)
@@ -1,3 +1,6 @@
+#if MONO
+#undef FEATURE_PAL
+#endif
 // ==++==
 // 
 //   Copyright (c) Microsoft Corporation.  All rights reserved.
@@ -21,6 +24,7 @@ namespace System.Threading
 #endif
     using System.Runtime.Versioning;
     using System.Runtime.ConstrainedExecution;
+    using System.Runtime.CompilerServices;
 
 
     [HostProtection(Synchronization=true, ExternalThreading=true)]
@@ -66,11 +70,19 @@ namespace System.Threading
             {
                 throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong));
             }
+
+#if MONO
+            int errorCode;
+            var myHandle = new SafeWaitHandle (CreateSemaphore_internal (initialCount, maximumCount, name, out errorCode), true);
+#else
             SafeWaitHandle   myHandle = SafeNativeMethods.CreateSemaphore(null, initialCount, maximumCount, name);
+#endif
             
             if (myHandle.IsInvalid)
             {
+#if !MONO
                 int errorCode = Marshal.GetLastWin32Error(); 
+#endif
 
                 if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
                     throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle,name));
@@ -119,6 +131,11 @@ namespace System.Threading
                 throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong));
             }
             SafeWaitHandle   myHandle;
+
+#if MONO
+            int errorCode;
+            myHandle = new SafeWaitHandle (CreateSemaphore_internal (initialCount, maximumCount, name, out errorCode), true);
+#else
 #if !FEATURE_PAL && !FEATURE_NETCORE
             // For ACL's, get the security descriptor from the SemaphoreSecurity.
             if (semaphoreSecurity != null) {
@@ -137,7 +154,9 @@ namespace System.Threading
 #if !FEATURE_PAL && !FEATURE_NETCORE
             }
 #endif
+
             int errorCode = Marshal.GetLastWin32Error();
+#endif
             if (myHandle.IsInvalid)
             {
                 if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
@@ -259,7 +278,14 @@ namespace System.Threading
             }
 
             result = null;
+#if MOBILE
+            throw new NotSupportedException ();
+#else
 
+#if MONO
+            int errorCode;
+            var myHandle = new SafeWaitHandle (OpenSemaphore_internal (name, rights, out errorCode), true);
+#else
             //Pass false to OpenSemaphore to prevent inheritedHandles
 #if FEATURE_PAL || FEATURE_NETCORE
             const int SYNCHRONIZE            = 0x00100000;
@@ -268,11 +294,14 @@ namespace System.Threading
             SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore(SEMAPHORE_MODIFY_STATE | SYNCHRONIZE, false, name);
 #else
             SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore((int) rights, false, name);
+#endif
 #endif
             
             if (myHandle.IsInvalid)
             {
+#if !MONO
                 int errorCode = Marshal.GetLastWin32Error();
+#endif
 
                 if (NativeMethods.ERROR_FILE_NOT_FOUND == errorCode || NativeMethods.ERROR_INVALID_NAME == errorCode)
                     return OpenExistingResult.NameNotFound;
@@ -285,6 +314,7 @@ namespace System.Threading
             }
             result = new Semaphore(myHandle);
             return OpenExistingResult.Success;
+#endif
         }
 
 
@@ -318,7 +348,11 @@ namespace System.Threading
             //   the semaphore's count to exceed the maximum count set when Semaphore was created
             //Non-Zero return 
 
+#if MONO
+            if (!ReleaseSemaphore_internal(Handle, releaseCount, out previousCount))
+#else
             if (!SafeNativeMethods.ReleaseSemaphore(SafeWaitHandle, releaseCount, out previousCount))
+#endif
             {
                 throw new SemaphoreFullException();
             }
@@ -342,6 +376,19 @@ namespace System.Threading
             semaphoreSecurity.Persist(SafeWaitHandle);
         }
 #endif
+
+#if MONO
+        [MethodImplAttribute(MethodImplOptions.InternalCall)]
+        internal static extern IntPtr CreateSemaphore_internal (
+            int initialCount, int maximumCount, string name, out int errorCode);
+
+        [MethodImplAttribute(MethodImplOptions.InternalCall)]
+        internal static extern bool ReleaseSemaphore_internal (
+            IntPtr handle, int releaseCount, out int previousCount);
+
+        [MethodImplAttribute (MethodImplOptions.InternalCall)]
+        private static extern IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out int errorCode);
+#endif
     }
 }
 
index 26096cb1e6f27187bccbeb3a17b3e07a0eb54d01..32f0c9fd7b2a28bdd7c1d0c4059c7246386e8f04 100644 (file)
@@ -81,7 +81,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 148
+#define MONO_CORLIB_VERSION 149
 
 typedef struct
 {
index e50dae52ae78539cc9d84b980d53eaad8c026f8f..9f413224e0237fb97ec1e9833dd0ce517b31af27 100644 (file)
@@ -886,9 +886,9 @@ ICALL(NATIVEC_4, "ResetEvent_internal",  ves_icall_System_Threading_Events_Reset
 ICALL(NATIVEC_5, "SetEvent_internal",    ves_icall_System_Threading_Events_SetEvent_internal)
 
 ICALL_TYPE(SEMA, "System.Threading.Semaphore", SEMA_1)
-ICALL(SEMA_1, "CreateSemaphore_internal(int,int,string,bool&)", ves_icall_System_Threading_Semaphore_CreateSemaphore_internal)
-ICALL(SEMA_2, "OpenSemaphore_internal(string,System.Security.AccessControl.SemaphoreRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Semaphore_OpenSemaphore_internal)
-ICALL(SEMA_3, "ReleaseSemaphore_internal(intptr,int,bool&)", ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal)
+ICALL(SEMA_1, "CreateSemaphore_internal(int,int,string,int&)", ves_icall_System_Threading_Semaphore_CreateSemaphore_internal)
+ICALL(SEMA_2, "OpenSemaphore_internal(string,System.Security.AccessControl.SemaphoreRights,int&)", ves_icall_System_Threading_Semaphore_OpenSemaphore_internal)
+ICALL(SEMA_3, "ReleaseSemaphore_internal(intptr,int,int&)", ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal)
 
 ICALL_TYPE(THREAD, "System.Threading.Thread", THREAD_1)
 ICALL(THREAD_1, "Abort_internal(System.Threading.InternalThread,object)", ves_icall_System_Threading_Thread_Abort)
index 68f8ec7851c3e1a13fa19f43c8aae37e285c6454..8ecabdb0e0becc4aa7c2748ce5ea3ab85240d6d2 100644 (file)
@@ -87,8 +87,8 @@ void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *th
 HANDLE ves_icall_System_Threading_Mutex_CreateMutex_internal(MonoBoolean owned, MonoString *name, MonoBoolean *created);
 MonoBoolean ves_icall_System_Threading_Mutex_ReleaseMutex_internal (HANDLE handle );
 HANDLE ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name, gint32 rights, gint32 *error);
-HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, MonoBoolean *created);
-gint32 ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, MonoBoolean *fail);
+HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, gint32 *error);
+MonoBoolean ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, gint32 *prevcount);
 HANDLE ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error);
 HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created);
 gboolean ves_icall_System_Threading_Events_SetEvent_internal (HANDLE handle);
index 63bb06d54166fe9d4e07935558ead1b6182cc23c..4aa7c5d6435bc5e36a83a75ebd006f8190352856 100644 (file)
@@ -1799,47 +1799,34 @@ HANDLE ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name,
 }
 
 
-HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, MonoBoolean *created)
+HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, gint32 *error)
 { 
        HANDLE sem;
        
-       *created = TRUE;
-       
        if (name == NULL) {
                sem = CreateSemaphore (NULL, initialCount, maximumCount, NULL);
        } else {
                sem = CreateSemaphore (NULL, initialCount, maximumCount,
                                       mono_string_chars (name));
-               
-               if (GetLastError () == ERROR_ALREADY_EXISTS) {
-                       *created = FALSE;
-               }
        }
 
+       *error = GetLastError ();
        return(sem);
 }                                                                   
 
-gint32 ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, MonoBoolean *fail)
+MonoBoolean ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, gint32 *prevcount)
 { 
-       gint32 prevcount;
-       
-       *fail = !ReleaseSemaphore (handle, releaseCount, &prevcount);
-
-       return (prevcount);
+       return ReleaseSemaphore (handle, releaseCount, prevcount);
 }
 
 HANDLE ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error)
 {
-       HANDLE ret;
-       
-       *error = ERROR_SUCCESS;
-       
-       ret = OpenSemaphore (rights, FALSE, mono_string_chars (name));
-       if (ret == NULL) {
-               *error = GetLastError ();
-       }
-       
-       return(ret);
+       HANDLE sem;
+
+       sem = OpenSemaphore (rights, FALSE, mono_string_chars (name));
+       *error = GetLastError ();
+
+       return(sem);
 }
 
 HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created)