| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //
- // System.Threading.WaitHandle.cs
- //
- // Author:
- // Dick Porter ([email protected])
- // Gonzalo Paniagua Javier ([email protected]
- //
- // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
- // Copyright (C) 2004-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;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Runtime.Remoting.Contexts;
- using System.Security.Permissions;
- using System.Runtime.InteropServices;
- using Microsoft.Win32.SafeHandles;
- using System.Runtime.ConstrainedExecution;
- namespace System.Threading
- {
- [StructLayout (LayoutKind.Sequential)]
- public abstract partial class WaitHandle
- : MarshalByRefObject, IDisposable
- {
- protected static readonly IntPtr InvalidHandle = (IntPtr) (-1);
- static int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll)
- {
- #if MONOTOUCH
- if (exitContext)
- throw new NotSupportedException ("exitContext == true is not supported");
- #endif
- try {
- if (exitContext)
- SynchronizationAttribute.ExitContext ();
- if (WaitAll)
- return WaitAll_internal (waitHandles, millisecondsTimeout, exitContext);
- else
- return WaitAny_internal (waitHandles, millisecondsTimeout, exitContext);
- } finally {
- if (exitContext)
- SynchronizationAttribute.EnterContext ();
- }
- }
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int WaitAll_internal(WaitHandle[] handles, int ms, bool exitContext);
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int WaitAny_internal(WaitHandle[] handles, int ms, bool exitContext);
- static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
- {
- #if MONOTOUCH
- if (exitContext)
- throw new NotSupportedException ("exitContext == true is not supported");
- #endif
- bool release = false;
- try {
- if (exitContext)
- SynchronizationAttribute.ExitContext ();
- waitableSafeHandle.DangerousAddRef (ref release);
- return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout, exitContext);
- } finally {
- if (release)
- waitableSafeHandle.DangerousRelease ();
- if (exitContext)
- SynchronizationAttribute.EnterContext ();
- }
- }
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern int WaitOne_internal(IntPtr handle, int ms, bool exitContext);
- static int SignalAndWaitOne (SafeWaitHandle waitHandleToSignal,SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
- {
- bool releaseHandleToSignal = false, releaseHandleToWaitOn = false;
- try {
- waitHandleToSignal.DangerousAddRef (ref releaseHandleToSignal);
- waitHandleToWaitOn.DangerousAddRef (ref releaseHandleToWaitOn);
- return SignalAndWait_Internal (waitHandleToSignal.DangerousGetHandle (), waitHandleToWaitOn.DangerousGetHandle (), millisecondsTimeout, exitContext);
- } finally {
- if (releaseHandleToSignal)
- waitHandleToSignal.DangerousRelease ();
- if (releaseHandleToWaitOn)
- waitHandleToWaitOn.DangerousRelease ();
- }
- }
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern int SignalAndWait_Internal (IntPtr toSignal, IntPtr toWaitOn, int ms, bool exitContext);
- }
- }
|