Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- ObjectDataSourceFilteringEventArgs.cs
- FieldNameLookup.cs
- QueueProcessor.cs
- TaiwanLunisolarCalendar.cs
- NullableIntSumAggregationOperator.cs
- PrtTicket_Public.cs
- PauseStoryboard.cs
- HttpHandlersSection.cs
- SqlError.cs
- ReachIDocumentPaginatorSerializerAsync.cs
- StatusBarPanel.cs
- SpecularMaterial.cs
- PrintEvent.cs
- GridViewDesigner.cs
- DrawTreeNodeEventArgs.cs
- UTF7Encoding.cs
- InnerItemCollectionView.cs
- HttpRequestCacheValidator.cs
- RequiredAttributeAttribute.cs
- BinaryParser.cs
- SymbolEqualComparer.cs
- AppDomain.cs
- ElementProxy.cs
- StringReader.cs
- XmlCharCheckingReader.cs
- PeerNearMe.cs
- CustomWebEventKey.cs
- VisualTreeUtils.cs
- ExpressionHelper.cs
- SqlException.cs
- NumericUpDownAcceleration.cs
- RayMeshGeometry3DHitTestResult.cs
- WindowsListViewGroup.cs
- TextBoxRenderer.cs
- XPathAncestorQuery.cs
- Size3D.cs
- TextPointer.cs
- ExpanderAutomationPeer.cs
- LicenseContext.cs
- Transform3DCollection.cs
- IgnoreSection.cs
- ExcludePathInfo.cs
- TimeZone.cs
- MediaSystem.cs
- RowType.cs
- TagMapInfo.cs
- UrlPropertyAttribute.cs
- IRCollection.cs
- DataGridCommandEventArgs.cs
- CellConstant.cs
- AccessViolationException.cs
- ServiceTimeoutsBehavior.cs
- Attributes.cs
- ModuleElement.cs
- ApplyImportsAction.cs
- XamlStackWriter.cs
- XmlWhitespace.cs
- LoginView.cs
- WpfPayload.cs
- DesignerActionVerbItem.cs
- JoinSymbol.cs
- ControlPaint.cs
- TextFormatterContext.cs
- PersonalizationStateQuery.cs
- ISO2022Encoding.cs
- CompressedStack.cs
- COM2Enum.cs
- ECDsa.cs
- PropertyEmitterBase.cs
- ProviderUtil.cs
- ListArgumentProvider.cs
- _IPv6Address.cs
- ToolboxCategory.cs
- ToolStripGrip.cs
- ResourceIDHelper.cs
- ObjectStateManager.cs
- InputProcessorProfiles.cs
- HtmlValidationSummaryAdapter.cs
- Enum.cs
- CallTemplateAction.cs
- IndicShape.cs
- CacheOutputQuery.cs
- SinglePageViewer.cs
- DesignTimeTemplateParser.cs
- StylusTip.cs
- MetafileEditor.cs
- MarkupCompiler.cs
- RegexWriter.cs
- EventLogPermission.cs
- ColumnMapTranslator.cs
- ValidationErrorEventArgs.cs
- RegularExpressionValidator.cs
- LiteralControl.cs
- Transform.cs
- Button.cs
- BaseTemplatedMobileComponentEditor.cs
- ValidatorUtils.cs
- ValueQuery.cs
- TextCharacters.cs
- EditingCoordinator.cs