Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / 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. //------------------------------------------------------------------------------ //// 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MediaPlayer.cs
- PathFigure.cs
- BadImageFormatException.cs
- Image.cs
- UInt16.cs
- TextEditorDragDrop.cs
- ParamArrayAttribute.cs
- XPathSingletonIterator.cs
- KeyedPriorityQueue.cs
- CatalogZoneBase.cs
- ReadWriteObjectLock.cs
- LocalClientSecuritySettings.cs
- RelationshipSet.cs
- ValuePattern.cs
- WebResourceAttribute.cs
- _SSPIWrapper.cs
- XamlPathDataSerializer.cs
- SafeHandles.cs
- PermissionSet.cs
- AsmxEndpointPickerExtension.cs
- DesignerTransactionCloseEvent.cs
- WebPartMinimizeVerb.cs
- StdRegProviderWrapper.cs
- DataGridViewRowCollection.cs
- PersistenceContext.cs
- SymbolEqualComparer.cs
- ToggleProviderWrapper.cs
- GenericTypeParameterBuilder.cs
- StatusBar.cs
- InvalidCommandTreeException.cs
- WindowsListViewScroll.cs
- EntityFunctions.cs
- RectIndependentAnimationStorage.cs
- MimeTypePropertyAttribute.cs
- ValueType.cs
- SimpleNameService.cs
- Message.cs
- PerformanceCounterCategory.cs
- AuthenticationSchemesHelper.cs
- BrowsableAttribute.cs
- XhtmlBasicLinkAdapter.cs
- TreeNodeCollection.cs
- UIPermission.cs
- AesManaged.cs
- TimeSpanValidatorAttribute.cs
- SqlConnectionHelper.cs
- HttpHeaderCollection.cs
- HtmlTableCell.cs
- PixelFormats.cs
- Matrix.cs
- MonthCalendarDesigner.cs
- ProcessInfo.cs
- QuadTree.cs
- DefinitionUpdate.cs
- AppSettingsExpressionEditor.cs
- StylusPointPropertyInfo.cs
- OutputCacheProfile.cs
- WebPartConnectionsConnectVerb.cs
- DataControlFieldHeaderCell.cs
- SatelliteContractVersionAttribute.cs
- ValidationError.cs
- SchemaCompiler.cs
- CodeGotoStatement.cs
- DashStyle.cs
- ProcessModuleCollection.cs
- StateManagedCollection.cs
- FormattedText.cs
- ProcessModelSection.cs
- BuildProvider.cs
- ConfigXmlWhitespace.cs
- FontStretch.cs
- HtmlEncodedRawTextWriter.cs
- HTTPNotFoundHandler.cs
- HttpDebugHandler.cs
- XamlHostingSectionGroup.cs
- basecomparevalidator.cs
- AsymmetricKeyExchangeDeformatter.cs
- AuthenticatedStream.cs
- dataSvcMapFileLoader.cs
- UTF8Encoding.cs
- TcpHostedTransportConfiguration.cs
- RolePrincipal.cs
- XmlWrappingReader.cs
- XsdBuilder.cs
- XPathNodePointer.cs
- XmlByteStreamWriter.cs
- CellTreeNodeVisitors.cs
- Size.cs
- SeekableReadStream.cs
- TemplateNameScope.cs
- FrameworkReadOnlyPropertyMetadata.cs
- BevelBitmapEffect.cs
- WindowsRichEdit.cs
- InvalidEnumArgumentException.cs
- HttpRuntimeSection.cs
- SoapIgnoreAttribute.cs
- PathParser.cs
- XmlUtil.cs
- MeasurementDCInfo.cs
- InternalConfirm.cs