Expose some threading type members
authorKoundinya Veluri <kouvel@microsoft.com>
Mon, 15 Aug 2016 18:17:48 +0000 (11:17 -0700)
committerKoundinya Veluri <kouvel@microsoft.com>
Thu, 18 Aug 2016 20:02:04 +0000 (13:02 -0700)
- Exposed some public members of WaitHandle
- Fixed "path too long" error message to take a length parameter (as in mscorlib.txt) and uses of it to pass in the correct value for the length
- Made SignalAndWait implementation available on Windows, and throw PlatformNotSupportedException on others

Part of dotnet/corefxdotnet/coreclr#10933

Commit migrated from https://github.com/dotnet/coreclr/commit/fdbe4c2fd8aff7c6c115e3228220fc47fc1eb3d6

src/coreclr/src/mscorlib/model.xml
src/coreclr/src/mscorlib/ref/mscorlib.cs
src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt
src/coreclr/src/mscorlib/src/System/Threading/EventWaitHandle.cs
src/coreclr/src/mscorlib/src/System/Threading/Semaphore.cs
src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs
src/coreclr/src/vm/comwaithandle.cpp
src/coreclr/src/vm/comwaithandle.h
src/coreclr/src/vm/ecalllist.h
src/coreclr/src/vm/threads.cpp
src/coreclr/src/vm/threads.h

index e5db284..243af34 100644 (file)
       <Member Name="Close" />
       <Member Name="Dispose" />
       <Member Name="Dispose(System.Boolean)" />
+      <Member Name="get_Handle" />
+      <Member Name="set_Handle(System.IntPtr)" />
       <Member Name="get_SafeWaitHandle" />
       <Member Name="set_SafeWaitHandle(Microsoft.Win32.SafeHandles.SafeWaitHandle)" />
+      <Member Name="SignalAndWait(System.Threading.WaitHandle,System.Threading.WaitHandle)" />
+      <Member Name="SignalAndWait(System.Threading.WaitHandle,System.Threading.WaitHandle,System.Int32,System.Boolean)" />
+      <Member Name="SignalAndWait(System.Threading.WaitHandle,System.Threading.WaitHandle,System.TimeSpan,System.Boolean)" />
       <Member Name="WaitAny(System.Threading.WaitHandle[])" />
       <Member Name="WaitAny(System.Threading.WaitHandle[],System.Int32)" />
+      <Member Name="WaitAny(System.Threading.WaitHandle[],System.Int32,System.Boolean)" />
       <Member Name="WaitAny(System.Threading.WaitHandle[],System.TimeSpan)" />
+      <Member Name="WaitAny(System.Threading.WaitHandle[],System.TimeSpan,System.Boolean)" />
       <Member Name="WaitAll(System.Threading.WaitHandle[])" />
       <Member Name="WaitAll(System.Threading.WaitHandle[],System.Int32)" />
+      <Member Name="WaitAll(System.Threading.WaitHandle[],System.Int32,System.Boolean)" />
       <Member Name="WaitAll(System.Threading.WaitHandle[],System.TimeSpan)" />
+      <Member Name="WaitAll(System.Threading.WaitHandle[],System.TimeSpan,System.Boolean)" />
       <Member Name="WaitOne" />
       <Member Name="WaitOne(System.Int32)" />
+      <Member Name="WaitOne(System.Int32,System.Boolean)" />
       <Member Name="WaitOne(System.TimeSpan)" />
+      <Member Name="WaitOne(System.TimeSpan,System.Boolean)" />
       <Member MemberType="Property" Name="SafeWaitHandle" />
     </Type>
    <Type Name="System.Threading.WaitHandleExtensions">
index aadae50..d456546 100644 (file)
@@ -12582,20 +12582,31 @@ namespace System.Threading
         protected static readonly System.IntPtr InvalidHandle;
         public const int WaitTimeout = 258;
         protected WaitHandle() { }
+        [System.ObsoleteAttribute("Use the SafeWaitHandle property instead.")]
+        public virtual System.IntPtr Handle { [System.Security.SecuritySafeCriticalAttribute]get { return default(System.IntPtr); } [System.Security.SecurityCriticalAttribute]set { } }
         public Microsoft.Win32.SafeHandles.SafeWaitHandle SafeWaitHandle { [System.Security.SecurityCriticalAttribute]get { throw null; } [System.Security.SecurityCriticalAttribute]set { } }
         public virtual void Close() { }
         public void Dispose() { }
         [System.Security.SecuritySafeCriticalAttribute]
         protected virtual void Dispose(bool explicitDisposing) { }
+        public static bool SignalAndWait(System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn) { return default(bool); }
+        public static bool SignalAndWait(System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) { return default(bool); }
+        public static bool SignalAndWait(System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn, System.TimeSpan timeout, bool exitContext) { return default(bool); }
         public static bool WaitAll(System.Threading.WaitHandle[] waitHandles) { throw null; }
         public static bool WaitAll(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout) { throw null; }
+        public static bool WaitAll(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { return default(bool); }
         public static bool WaitAll(System.Threading.WaitHandle[] waitHandles, System.TimeSpan timeout) { throw null; }
+        public static bool WaitAll(System.Threading.WaitHandle[] waitHandles, System.TimeSpan timeout, bool exitContext) { return default(bool); }
         public static int WaitAny(System.Threading.WaitHandle[] waitHandles) { throw null; }
         public static int WaitAny(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout) { throw null; }
+        public static int WaitAny(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { return default(int); }
         public static int WaitAny(System.Threading.WaitHandle[] waitHandles, System.TimeSpan timeout) { throw null; }
+        public static int WaitAny(System.Threading.WaitHandle[] waitHandles, System.TimeSpan timeout, bool exitContext) { return default(int); }
         public virtual bool WaitOne() { throw null; }
         public virtual bool WaitOne(int millisecondsTimeout) { throw null; }
+        public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) { return default(bool); }
         public virtual bool WaitOne(System.TimeSpan timeout) { throw null; }
+        public virtual bool WaitOne(System.TimeSpan timeout, bool exitContext) { return default(bool); }
     }
     [System.Runtime.InteropServices.ComVisibleAttribute(false)]
     public partial class WaitHandleCannotBeOpenedException : System.Exception
index 363be3e..0369344 100644 (file)
@@ -194,7 +194,7 @@ Argument_ResolveFieldHandle = Type handle '{0}' and field handle with declaring
 Argument_ResourceScopeWrongDirection = Resource type in the ResourceScope enum is going from a more restrictive resource type to a more general one.  From: "{0}"  To: "{1}"
 Argument_BadResourceScopeTypeBits = Unknown value for the ResourceScope: {0}  Too many resource type bits may be set.
 Argument_BadResourceScopeVisibilityBits = Unknown value for the ResourceScope: {0}  Too many resource visibility bits may be set.
-Argument_WaitHandleNameTooLong = The name can be no more than 260 characters in length.
+Argument_WaitHandleNameTooLong = The name can be no more than {0} characters in length.
 Argument_EnumTypeDoesNotMatch = The argument type, '{0}', is not the same as the enum type '{1}'.
 InvalidOperation_MethodBuilderBaked = The signature of the MethodBuilder can no longer be modified because an operation on the MethodBuilder caused the methodDef token to be created. For example, a call to SetCustomAttribute requires the methodDef token to emit the CustomAttribute token.
 InvalidOperation_GenericParametersAlreadySet = The generic parameters are already defined on this MethodBuilder.
index 598b0df..f56da1f 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Threading
 #else
                 if (System.IO.Path.MaxPath < name.Length)
                 {
-                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
+                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
                 }
 #endif
             }
@@ -105,7 +105,7 @@ namespace System.Threading
 #else
                 if (System.IO.Path.MaxPath < name.Length)
                 {
-                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
+                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
                 }
 #endif
             }
@@ -226,7 +226,7 @@ namespace System.Threading
 
             if(null != name && System.IO.Path.MaxPath < name.Length)
             {
-                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
+                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
             }
             
             Contract.EndContractBlock();
index 3220066..303593b 100644 (file)
@@ -95,8 +95,8 @@ namespace System.Threading
 #if PLATFORM_UNIX
                 throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives"));
 #else
-                if (name.Length > Path.MAX_PATH)
-                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
+                if (name.Length > Path.MaxPath)
+                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
 #endif
             }
 
@@ -141,9 +141,9 @@ namespace System.Threading
                 throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
             if (name.Length == 0)
                 throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
-            if (name.Length > Path.MAX_PATH)
-                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
-                     
+            if (name.Length > Path.MaxPath)
+                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
+
             const int SYNCHRONIZE = 0x00100000;
             const int SEMAPHORE_MODIFY_STATE = 0x00000002;
 
index 7703a49..9980c82 100644 (file)
@@ -500,7 +500,11 @@ namespace System.Threading
                                         WaitHandle toSignal,
                                         WaitHandle toWaitOn)
         {
+#if PLATFORM_UNIX
+            throw new PlatformNotSupportedException();
+#else
             return SignalAndWait(toSignal,toWaitOn,-1,false);
+#endif
         }
 
         public static bool SignalAndWait(
@@ -509,12 +513,16 @@ namespace System.Threading
                                         TimeSpan timeout,
                                         bool exitContext)
         {
+#if PLATFORM_UNIX
+            throw new PlatformNotSupportedException();
+#else
             long tm = (long)timeout.TotalMilliseconds;
             if (-1 > tm || (long) Int32.MaxValue < tm)
             {
                 throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
             }
             return SignalAndWait(toSignal,toWaitOn,(int)tm,exitContext);
+#endif
         }
 
         [System.Security.SecuritySafeCritical]  // auto-generated
@@ -525,6 +533,9 @@ namespace System.Threading
                                         int millisecondsTimeout,
                                         bool exitContext)
         {
+#if PLATFORM_UNIX
+            throw new PlatformNotSupportedException();
+#else
             if(null == toSignal)
             {
                 throw new ArgumentNullException("toSignal");
@@ -569,6 +580,7 @@ namespace System.Threading
 
             //Timeout
             return false;
+#endif
         }
 
         private static void ThrowAbandonedMutexException()
index ef16669..13886c3 100644 (file)
@@ -382,7 +382,7 @@ FCIMPL4(INT32, WaitHandleNative::CorWaitMultipleNative, Object* waitObjectsUNSAF
 }
 FCIMPLEND
 
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
 FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWaitHandleSignalUNSAFE,SafeHandle* safeWaitHandleWaitUNSAFE, INT32 timeout, CLR_BOOL hasThreadAffinity, CLR_BOOL exitContext)
 {
     FCALL_CONTRACT;
@@ -415,9 +415,11 @@ FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWait
     Context* defaultContext = pThread->GetDomain()->GetDefaultContext();
     _ASSERTE(defaultContext);
 
+#ifndef FEATURE_CORECLR
     // DoSignalAndWait calls LeaveRuntime/EnterRuntime which may cause the current
     // fiber to be re-scheduled.
     ThreadAffinityAndCriticalRegionHolder affinityAndCriticalRegionHolder(hasThreadAffinity);
+#endif // !FEATURE_CORECLR
 
     SafeHandleHolder shhSignal(&shSignal);
     SafeHandleHolder shhWait(&shWait);
@@ -442,6 +444,7 @@ FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWait
         res = pThread->DoSignalAndWait(handles,timeout,TRUE /*alertable*/);
     }
 
+#ifndef FEATURE_CORECLR
     if (res == WAIT_OBJECT_0 && hasThreadAffinity) {
         affinityAndCriticalRegionHolder.SuppressRelease();
     }
@@ -449,6 +452,7 @@ FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWait
         _ASSERTE(hasThreadAffinity);
         affinityAndCriticalRegionHolder.SuppressRelease();    
     }
+#endif // !FEATURE_CORECLR
 
     retVal = res;
 
@@ -456,4 +460,4 @@ FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWait
     return retVal;
 }
 FCIMPLEND
-#endif // !FEATURE_CORECLR
+#endif // !FEATURE_PAL
index d835220..f593b7e 100644 (file)
@@ -21,7 +21,7 @@ class WaitHandleNative
 public:
     static FCDECL4(INT32, CorWaitOneNative, SafeHandle* safeWaitHandleUNSAFE, INT32 timeout, CLR_BOOL hasThreadAffinity, CLR_BOOL exitContext);
     static FCDECL4(INT32, CorWaitMultipleNative, Object* waitObjectsUNSAFE, INT32 timeout, CLR_BOOL exitContext, CLR_BOOL waitForAll);
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
     static FCDECL5(INT32, CorSignalAndWaitOneNative, SafeHandle* safeWaitHandleSignalUNSAFE, SafeHandle* safeWaitHandleWaitUNSAFE, INT32 timeout, CLR_BOOL hasThreadAffinity, CLR_BOOL exitContext);
 #endif
 };
index c71c5c1..7e9a118 100644 (file)
@@ -1368,9 +1368,9 @@ FCFuncEnd()
 FCFuncStart(gWaitHandleFuncs)
     FCFuncElement("WaitOneNative", WaitHandleNative::CorWaitOneNative)
     FCFuncElement("WaitMultiple", WaitHandleNative::CorWaitMultipleNative)
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
     FCFuncElement("SignalAndWaitOne", WaitHandleNative::CorSignalAndWaitOneNative)
-#endif // !FEATURE_CORECLR
+#endif // !FEATURE_PAL
 FCFuncEnd()
 
 FCFuncStart(gNumberFuncs)
index 072c943..cc2e4eb 100644 (file)
@@ -4704,7 +4704,7 @@ WaitCompleted:
     return ret;
 }
 
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
 //--------------------------------------------------------------------
 // Only one style of wait for DoSignalAndWait since we don't support this on STA Threads
 //--------------------------------------------------------------------
@@ -4851,7 +4851,7 @@ WaitCompleted:
 
     return ret;
 }
-#endif // FEATURE_CORECLR
+#endif // !FEATURE_PAL
 
 #ifdef FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
 DWORD Thread::DoSyncContextWait(OBJECTREF *pSyncCtxObj, int countHandles, HANDLE *handles, BOOL waitAll, DWORD millis)
index bd81c63..ec047f2 100644 (file)
@@ -3504,19 +3504,19 @@ public:
 
     DWORD          DoAppropriateWait(AppropriateWaitFunc func, void *args, DWORD millis,
                                      WaitMode mode, PendingSync *syncInfo = 0);
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
     DWORD          DoSignalAndWait(HANDLE *handles, DWORD millis, BOOL alertable,
                                      PendingSync *syncState = 0);
-#endif
+#endif // !FEATURE_PAL
 private:
     void           DoAppropriateWaitWorkerAlertableHelper(WaitMode mode);
     DWORD          DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL waitAll,
                                            DWORD millis, WaitMode mode);
     DWORD          DoAppropriateWaitWorker(AppropriateWaitFunc func, void *args,
                                            DWORD millis, WaitMode mode);
-#ifndef FEATURE_CORECLR
+#ifndef FEATURE_PAL
     DWORD          DoSignalAndWaitWorker(HANDLE* pHandles, DWORD millis,BOOL alertable);
-#endif
+#endif // !FEATURE_PAL
     DWORD          DoAppropriateAptStateWait(int numWaiters, HANDLE* pHandles, BOOL bWaitAll, DWORD timeout, WaitMode mode);
 #ifdef FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
     DWORD          DoSyncContextWait(OBJECTREF *pSyncCtxObj, int countHandles, HANDLE *handles, BOOL waitAll, DWORD millis);