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
- SoundPlayerAction.cs
- BamlResourceSerializer.cs
- PageAdapter.cs
- ServerValidateEventArgs.cs
- Process.cs
- ThrowHelper.cs
- BamlVersionHeader.cs
- ObjectListCommandsPage.cs
- SafeNativeMethods.cs
- tabpagecollectioneditor.cs
- DataTablePropertyDescriptor.cs
- InheritanceContextHelper.cs
- RichTextBox.cs
- XmlHelper.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- PropVariant.cs
- DirtyTextRange.cs
- AnnotationAuthorChangedEventArgs.cs
- NamespaceMapping.cs
- ProviderSettings.cs
- DefaultCommandConverter.cs
- DesignRelationCollection.cs
- xml.cs
- StateBag.cs
- InputLanguageProfileNotifySink.cs
- SocketCache.cs
- RawMouseInputReport.cs
- TextParagraphView.cs
- ADRoleFactoryConfiguration.cs
- BitmapPalettes.cs
- DateTimeValueSerializer.cs
- FixedMaxHeap.cs
- AnnotationResourceChangedEventArgs.cs
- SqlDeflator.cs
- InkCanvasFeedbackAdorner.cs
- ContentPlaceHolderDesigner.cs
- ColumnMapProcessor.cs
- RefreshPropertiesAttribute.cs
- complextypematerializer.cs
- AsyncOperation.cs
- EntityCommand.cs
- Calendar.cs
- FactoryGenerator.cs
- TextStore.cs
- RotateTransform3D.cs
- BitmapEffectDrawingContent.cs
- ConfigXmlAttribute.cs
- OdbcPermission.cs
- ProxyManager.cs
- SystemWebCachingSectionGroup.cs
- InlinedAggregationOperatorEnumerator.cs
- XmlSiteMapProvider.cs
- GenericTypeParameterConverter.cs
- PrivateFontCollection.cs
- OleDbPermission.cs
- ConfigXmlAttribute.cs
- ItemAutomationPeer.cs
- ResourcePool.cs
- EdmSchemaError.cs
- ControlTemplate.cs
- MatrixConverter.cs
- BamlBinaryReader.cs
- MultitargetingHelpers.cs
- DataTableReaderListener.cs
- MetadataSource.cs
- MenuItemBindingCollection.cs
- Triangle.cs
- ConnectionProviderAttribute.cs
- SessionStateUtil.cs
- ClientConfigurationHost.cs
- DataGridViewCellParsingEventArgs.cs
- ScopeCompiler.cs
- DbExpressionRules.cs
- EditingCommands.cs
- ControlTemplate.cs
- Interop.cs
- DataRelation.cs
- EntityKeyElement.cs
- Stylus.cs
- EventWaitHandleSecurity.cs
- CompositeControl.cs
- HMACSHA1.cs
- MessageContractMemberAttribute.cs
- KeyedPriorityQueue.cs
- CompressEmulationStream.cs
- ArrangedElementCollection.cs
- SequenceDesigner.cs
- PbrsForward.cs
- COM2EnumConverter.cs
- _emptywebproxy.cs
- PageTheme.cs
- BridgeDataReader.cs
- XPathSelectionIterator.cs
- XmlSignificantWhitespace.cs
- Tracking.cs
- XmlnsCompatibleWithAttribute.cs
- DetailsViewUpdateEventArgs.cs
- SrgsRulesCollection.cs
- Touch.cs
- Comparer.cs