Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / Microsoft / Win32 / SafeHandles / SafeWaitHandle.cs / 1305376 / SafeWaitHandle.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SafeWaitHandle ** ** ** A wrapper for Win32 events (mutexes, auto reset events, and ** manual reset events). Used by WaitHandle. ** ** ===========================================================*/ using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.Versioning; using Microsoft.Win32; using System.Threading; namespace Microsoft.Win32.SafeHandles { [System.Security.SecurityCritical] // auto-generated_required public sealed class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid { // Special case flags for Mutexes enables workaround for known OS bug at // http://support.microsoft.com/default.aspx?scid=kb;en-us;889318 // One machine-wide mutex serializes all OpenMutex and CloseHandle operations. // bIsMutex: if true, we need to grab machine-wide mutex before doing any Close ops. // Initialized to false by the runtime. private bool bIsMutex; // bIsMutex: if true, we need to avoid grabbing the machine-wide mutex before Close ops, // since that mutex is, of course, this very handle. // Initialized to false by the runtime. private bool bIsReservedMutex; // Called by P/Invoke marshaler private SafeWaitHandle() : base(true) { } [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public SafeWaitHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) { SetHandle(existingHandle); } [System.Security.SecurityCritical] [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] override protected bool ReleaseHandle() { #if !FEATURE_CORECLR if (!bIsMutex || Environment.HasShutdownStarted) return Win32Native.CloseHandle(handle); bool bReturn = false; bool bMutexObtained = false; try { if (!bIsReservedMutex) { Mutex.AcquireReservedMutex(ref bMutexObtained); } bReturn = Win32Native.CloseHandle(handle); } finally { if (bMutexObtained) Mutex.ReleaseReservedMutex(); } return bReturn; #else return Win32Native.CloseHandle(handle); #endif } internal void SetAsMutex() { bIsMutex = true; } [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal void SetAsReservedMutex() { bIsReservedMutex = true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsRichEdit.cs
- Size3DValueSerializer.cs
- EncryptedData.cs
- ProfileSection.cs
- _NegotiateClient.cs
- DirectoryObjectSecurity.cs
- UIElementAutomationPeer.cs
- RuleProcessor.cs
- PointLight.cs
- SecurityHeaderElementInferenceEngine.cs
- ProcessProtocolHandler.cs
- OletxTransactionManager.cs
- LogicalExpr.cs
- GroupBoxDesigner.cs
- WorkflowServiceHostFactory.cs
- DynamicDataRoute.cs
- Transform3DCollection.cs
- ReliabilityContractAttribute.cs
- CodeTypeOfExpression.cs
- LicenseManager.cs
- AttachedPropertyMethodSelector.cs
- ValidationRuleCollection.cs
- WebEvents.cs
- ExtendedTransformFactory.cs
- EventWaitHandle.cs
- ToolBarButtonDesigner.cs
- AdRotatorDesigner.cs
- XslTransformFileEditor.cs
- OleDbDataReader.cs
- SBCSCodePageEncoding.cs
- MustUnderstandSoapException.cs
- TimeSpanValidator.cs
- SqlStatistics.cs
- ContainsRowNumberChecker.cs
- FixedSOMFixedBlock.cs
- ConsumerConnectionPoint.cs
- GridViewRowEventArgs.cs
- ImpersonateTokenRef.cs
- AttributeAction.cs
- Transactions.cs
- AmbiguousMatchException.cs
- ListViewAutomationPeer.cs
- MultiAsyncResult.cs
- XNodeNavigator.cs
- mda.cs
- TextBox.cs
- GenerateHelper.cs
- RecognizeCompletedEventArgs.cs
- ControlBindingsCollection.cs
- DesignerDataView.cs
- XmlSchemaSimpleContentExtension.cs
- EntityContainerRelationshipSet.cs
- DesigntimeLicenseContext.cs
- ValidatingPropertiesEventArgs.cs
- UnrecognizedPolicyAssertionElement.cs
- ServiceMetadataPublishingElement.cs
- Transform.cs
- EventLogEntry.cs
- DataMemberAttribute.cs
- updatecommandorderer.cs
- Dictionary.cs
- PageAsyncTaskManager.cs
- OuterGlowBitmapEffect.cs
- BaseDataListComponentEditor.cs
- UriTemplateTable.cs
- HtmlInputControl.cs
- XmlSignatureManifest.cs
- DSASignatureFormatter.cs
- ProcessManager.cs
- IdentityManager.cs
- HideDisabledControlAdapter.cs
- MatcherBuilder.cs
- HtmlElementCollection.cs
- PropertyPath.cs
- InteropAutomationProvider.cs
- ToolStripDropTargetManager.cs
- CodeMemberEvent.cs
- RepeatBehavior.cs
- EntityDataSourceState.cs
- XPathItem.cs
- CultureNotFoundException.cs
- TransformGroup.cs
- DynamicValueConverter.cs
- WebControl.cs
- _NegotiateClient.cs
- HttpModuleCollection.cs
- ForwardPositionQuery.cs
- PipeStream.cs
- SQLInt32Storage.cs
- XmlLanguageConverter.cs
- SplineKeyFrames.cs
- MatrixAnimationBase.cs
- ToolStripItemCollection.cs
- SchemaContext.cs
- XmlSchemaAttribute.cs
- ValidationResult.cs
- CodeParameterDeclarationExpressionCollection.cs
- RelationshipManager.cs
- ResourceDisplayNameAttribute.cs
- UnsafeNativeMethods.cs