Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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 } */ } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ImageCodecInfo.cs
- MapPathBasedVirtualPathProvider.cs
- DebugView.cs
- StylusButtonEventArgs.cs
- PersonalizationDictionary.cs
- ExceptionTranslationTable.cs
- SoapIncludeAttribute.cs
- SourceElementsCollection.cs
- FixedSOMGroup.cs
- sqlser.cs
- ValueType.cs
- Label.cs
- oledbconnectionstring.cs
- IdentityNotMappedException.cs
- ClientTarget.cs
- KeyBinding.cs
- SymbolDocumentGenerator.cs
- Pipe.cs
- SemanticAnalyzer.cs
- SpeechSeg.cs
- RequestResizeEvent.cs
- FlowDocumentReaderAutomationPeer.cs
- StaticResourceExtension.cs
- ConfigurationPropertyAttribute.cs
- QilDataSource.cs
- UserUseLicenseDictionaryLoader.cs
- MaskedTextBoxDesignerActionList.cs
- SchemaTableColumn.cs
- NetWebProxyFinder.cs
- ExtenderHelpers.cs
- ScrollViewer.cs
- WSUtilitySpecificationVersion.cs
- DataTableReader.cs
- CompiledQueryCacheEntry.cs
- AttributeCallbackBuilder.cs
- XhtmlBasicCalendarAdapter.cs
- GridItemProviderWrapper.cs
- LookupNode.cs
- ValidationErrorCollection.cs
- WebPartConnectionsEventArgs.cs
- BitmapCacheBrush.cs
- ListDictionaryInternal.cs
- EncodingStreamWrapper.cs
- DependencyObjectValidator.cs
- ProcessHostConfigUtils.cs
- TableLayoutPanelCellPosition.cs
- TemporaryBitmapFile.cs
- FileBasedResourceGroveler.cs
- SortedList.cs
- ImageDrawing.cs
- UnSafeCharBuffer.cs
- DbInsertCommandTree.cs
- DispatchChannelSink.cs
- MessageSecurityOverMsmqElement.cs
- MsmqReceiveHelper.cs
- ByteStack.cs
- ForeignConstraint.cs
- IResourceProvider.cs
- DbConnectionInternal.cs
- TextCharacters.cs
- AttachedPropertiesService.cs
- AppSecurityManager.cs
- CatalogPartChrome.cs
- ExpressionHelper.cs
- ConnectionManagementSection.cs
- XmlNodeChangedEventManager.cs
- RefreshPropertiesAttribute.cs
- CounterSetInstance.cs
- VectorCollection.cs
- CellCreator.cs
- SamlSerializer.cs
- TextTreeDeleteContentUndoUnit.cs
- TranslateTransform3D.cs
- RectangleConverter.cs
- PlaceHolder.cs
- PerformanceCounterLib.cs
- Processor.cs
- httpapplicationstate.cs
- TypeUtil.cs
- _AuthenticationState.cs
- TrackingConditionCollection.cs
- SchemaInfo.cs
- TdsParserHelperClasses.cs
- EntityViewGenerator.cs
- RequestResizeEvent.cs
- NamedPipeProcessProtocolHandler.cs
- RowsCopiedEventArgs.cs
- WsdlWriter.cs
- FixedPosition.cs
- TextDecorations.cs
- BitmapEffectRenderDataResource.cs
- WSHttpBindingBaseElement.cs
- WebPartEventArgs.cs
- ObservableDictionary.cs
- OdbcConnection.cs
- DefaultObjectMappingItemCollection.cs
- ArrayWithOffset.cs
- RawAppCommandInputReport.cs
- Update.cs
- DocumentApplication.cs