Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / Util / ReadWriteObjectLock.cs / 1 / ReadWriteObjectLock.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * ReadWriteObjectLock * * Copyright (c) 1998-1999, Microsoft Corporation * */ namespace System.Web.Util { using System.Runtime.Serialization.Formatters; using System.Threading; class ReadWriteObjectLock { // Assumption: // -1 = a writer has the lock // 0 = no one has the lock // >0 = number of readers using the lock private int _lock; internal ReadWriteObjectLock() { } internal virtual void AcquireRead() { lock(this) { while (_lock == -1) { try { Monitor.Wait(this); } catch (ThreadInterruptedException) { // Just keep looping } } _lock++; } } internal virtual void ReleaseRead() { lock(this) { Debug.Assert(_lock > 0); _lock--; if (_lock == 0) { Monitor.PulseAll(this); } } } internal virtual void AcquireWrite() { lock(this) { while (_lock != 0) { try { Monitor.Wait(this); } catch (ThreadInterruptedException) { // Just keep looping } } _lock = -1; } } internal virtual void ReleaseWrite() { lock(this) { Debug.Assert(_lock == -1); _lock = 0; Monitor.PulseAll(this); } } /* internal virtual void AssertReadLock() { #if DBG Debug.Assert(_lock > 0); #endif } internal virtual void AssertWriteLock() { #if DBG Debug.Assert(_lock == -1); #endif } */ } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * ReadWriteObjectLock * * Copyright (c) 1998-1999, Microsoft Corporation * */ namespace System.Web.Util { using System.Runtime.Serialization.Formatters; using System.Threading; class ReadWriteObjectLock { // Assumption: // -1 = a writer has the lock // 0 = no one has the lock // >0 = number of readers using the lock private int _lock; internal ReadWriteObjectLock() { } internal virtual void AcquireRead() { lock(this) { while (_lock == -1) { try { Monitor.Wait(this); } catch (ThreadInterruptedException) { // Just keep looping } } _lock++; } } internal virtual void ReleaseRead() { lock(this) { Debug.Assert(_lock > 0); _lock--; if (_lock == 0) { Monitor.PulseAll(this); } } } internal virtual void AcquireWrite() { lock(this) { while (_lock != 0) { try { Monitor.Wait(this); } catch (ThreadInterruptedException) { // Just keep looping } } _lock = -1; } } internal virtual void ReleaseWrite() { lock(this) { Debug.Assert(_lock == -1); _lock = 0; Monitor.PulseAll(this); } } /* internal virtual void AssertReadLock() { #if DBG Debug.Assert(_lock > 0); #endif } internal virtual void AssertWriteLock() { #if DBG Debug.Assert(_lock == -1); #endif } */ } } // 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
- ClientSettingsSection.cs
- DoubleLinkList.cs
- GrammarBuilder.cs
- ListItemConverter.cs
- Select.cs
- XmlIterators.cs
- TabPageDesigner.cs
- AtomicFile.cs
- SiteMapDataSource.cs
- FilterException.cs
- HostedAspNetEnvironment.cs
- XmlNodeChangedEventManager.cs
- NumberFormatInfo.cs
- XmlSerializerFactory.cs
- HttpModuleAction.cs
- XmlSerializerFactory.cs
- UserMapPath.cs
- TextTreeInsertElementUndoUnit.cs
- ExpandCollapseProviderWrapper.cs
- SelectedDatesCollection.cs
- QueryStringHandler.cs
- ConsumerConnectionPoint.cs
- PrimitiveXmlSerializers.cs
- Geometry3D.cs
- ControlPaint.cs
- BlurEffect.cs
- RsaSecurityTokenAuthenticator.cs
- CodeDomSerializer.cs
- ProfilePropertyMetadata.cs
- TdsParserStateObject.cs
- DecoderFallback.cs
- ControlParameter.cs
- MetadataItemCollectionFactory.cs
- MultipleViewPatternIdentifiers.cs
- xmlglyphRunInfo.cs
- NameValueCollection.cs
- HostingPreferredMapPath.cs
- ContentControl.cs
- ReadOnlyMetadataCollection.cs
- WebEventTraceProvider.cs
- InfocardChannelParameter.cs
- HttpProfileBase.cs
- BinaryCommonClasses.cs
- CookieProtection.cs
- ClassImporter.cs
- OptimisticConcurrencyException.cs
- ReservationCollection.cs
- TransportOutputChannel.cs
- SQLInt16.cs
- BitStream.cs
- MemberDomainMap.cs
- _LazyAsyncResult.cs
- LZCodec.cs
- SimpleHandlerFactory.cs
- PlanCompiler.cs
- altserialization.cs
- EndEvent.cs
- SiteMap.cs
- GiveFeedbackEvent.cs
- CopyAction.cs
- EncoderReplacementFallback.cs
- SerializationTrace.cs
- NotifyParentPropertyAttribute.cs
- WebPartDescriptionCollection.cs
- StaticResourceExtension.cs
- PageRequestManager.cs
- EdmItemError.cs
- ProtocolElement.cs
- FirstMatchCodeGroup.cs
- TypeDescriptionProvider.cs
- ServerType.cs
- SqlErrorCollection.cs
- WebPartDeleteVerb.cs
- FixedSOMTextRun.cs
- TemplateControlBuildProvider.cs
- RelationshipEnd.cs
- SHA384.cs
- SmiSettersStream.cs
- CompatibleIComparer.cs
- ExceptionWrapper.cs
- ControlIdConverter.cs
- QueryOpcode.cs
- ScriptComponentDescriptor.cs
- CapabilitiesAssignment.cs
- DesignerPainter.cs
- EpmCustomContentDeSerializer.cs
- DbInsertCommandTree.cs
- Source.cs
- Transform3DGroup.cs
- CodeTypeReferenceExpression.cs
- ProxyGenerationError.cs
- PhoneCall.cs
- Delegate.cs
- CheckBoxAutomationPeer.cs
- HeaderedItemsControl.cs
- BaseAddressPrefixFilterElementCollection.cs
- DesignUtil.cs
- WorkflowQueue.cs
- GridViewDeletedEventArgs.cs
- ProfileGroupSettingsCollection.cs