Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ScheduleChanges.cs
- XsdCachingReader.cs
- _ListenerResponseStream.cs
- EventProperty.cs
- EventManager.cs
- GcSettings.cs
- AdapterUtil.cs
- TypefaceMetricsCache.cs
- printdlgexmarshaler.cs
- ClientTargetCollection.cs
- DaylightTime.cs
- HtmlImage.cs
- GAC.cs
- securestring.cs
- OrderPreservingSpoolingTask.cs
- ToolstripProfessionalRenderer.cs
- LocatorPartList.cs
- MenuItemCollection.cs
- PathData.cs
- DbUpdateCommandTree.cs
- BindingElementExtensionElement.cs
- HelpEvent.cs
- UIElementAutomationPeer.cs
- PerformanceCounterPermissionEntryCollection.cs
- WindowsEditBox.cs
- TypeBuilderInstantiation.cs
- SynchronizedDispatch.cs
- AttachmentService.cs
- StackOverflowException.cs
- HttpListenerContext.cs
- Win32.cs
- UniqueConstraint.cs
- CodeSubDirectoriesCollection.cs
- ToolboxDataAttribute.cs
- BigInt.cs
- MemoryStream.cs
- DbProviderFactories.cs
- WindowsListViewSubItem.cs
- MainMenu.cs
- HtmlInputSubmit.cs
- XmlNamespaceMapping.cs
- TransformProviderWrapper.cs
- ImageFormat.cs
- ExpressionLink.cs
- XmlDigitalSignatureProcessor.cs
- FocusChangedEventArgs.cs
- BrowsableAttribute.cs
- HttpRequestTraceRecord.cs
- PresentationSource.cs
- HasRunnableWorkflowEvent.cs
- SqlDesignerDataSourceView.cs
- StrongNameUtility.cs
- ImageCodecInfo.cs
- Formatter.cs
- JapaneseCalendar.cs
- EventsTab.cs
- CheckoutException.cs
- AnchoredBlock.cs
- RecipientInfo.cs
- MulticastOption.cs
- Helpers.cs
- Context.cs
- ErrorWrapper.cs
- ExpressionVisitor.cs
- CommonXSendMessage.cs
- CaseInsensitiveHashCodeProvider.cs
- updatecommandorderer.cs
- ProvideValueServiceProvider.cs
- ProviderConnectionPointCollection.cs
- EncodingTable.cs
- ResXResourceReader.cs
- NetNamedPipeSecurity.cs
- Polygon.cs
- CultureInfoConverter.cs
- OrCondition.cs
- ItemAutomationPeer.cs
- Policy.cs
- BitmapEffectOutputConnector.cs
- safelink.cs
- HelloMessage11.cs
- KnownBoxes.cs
- InstanceLockLostException.cs
- WebPartMenu.cs
- WindowsContainer.cs
- Int16KeyFrameCollection.cs
- RelationHandler.cs
- ModuleBuilder.cs
- MatcherBuilder.cs
- OAVariantLib.cs
- Int32Storage.cs
- WebResponse.cs
- ClientSession.cs
- SymmetricAlgorithm.cs
- SortDescription.cs
- DatatypeImplementation.cs
- XmlEntityReference.cs
- UnsafeNativeMethods.cs
- TextPointer.cs
- Slider.cs
- HandlerBase.cs