Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- Array.cs
- MaterializeFromAtom.cs
- ResourceType.cs
- DataGridViewRowPrePaintEventArgs.cs
- RemotingException.cs
- PixelFormats.cs
- SpeechUI.cs
- PolicyDesigner.cs
- ConditionalAttribute.cs
- ManagementQuery.cs
- KeySpline.cs
- DesignerActionPanel.cs
- TransformationRules.cs
- EqualityComparer.cs
- ExtensionFile.cs
- CellPartitioner.cs
- ChannelManager.cs
- DataListCommandEventArgs.cs
- DrawListViewItemEventArgs.cs
- ProfileModule.cs
- HttpWebResponse.cs
- XmlUtil.cs
- HGlobalSafeHandle.cs
- COSERVERINFO.cs
- SpecularMaterial.cs
- TraceContextEventArgs.cs
- ExpressionBinding.cs
- UserNameSecurityTokenProvider.cs
- SqlDataSourceCache.cs
- FormConverter.cs
- DmlSqlGenerator.cs
- Atom10FormatterFactory.cs
- TryCatchDesigner.xaml.cs
- coordinatorfactory.cs
- PropertyInfoSet.cs
- EasingKeyFrames.cs
- AdPostCacheSubstitution.cs
- SelectionUIService.cs
- CodeDefaultValueExpression.cs
- XappLauncher.cs
- ObjectViewQueryResultData.cs
- Opcode.cs
- KeyValueSerializer.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- HttpCapabilitiesEvaluator.cs
- DialogResultConverter.cs
- DataServiceHostFactory.cs
- TemplateLookupAction.cs
- KeyMatchBuilder.cs
- PriorityItem.cs
- SeekableReadStream.cs
- MarkupExtensionParser.cs
- MemberProjectionIndex.cs
- ObjectConverter.cs
- SqlDataSourceSelectingEventArgs.cs
- ArrangedElementCollection.cs
- SuppressIldasmAttribute.cs
- ViewManager.cs
- XmlSchemaExporter.cs
- XmlSerializationWriter.cs
- EndpointConfigContainer.cs
- SQLMoneyStorage.cs
- Endpoint.cs
- ToolStripDropDownClosingEventArgs.cs
- BoundColumn.cs
- WebPartCollection.cs
- TypeBuilderInstantiation.cs
- Module.cs
- httpstaticobjectscollection.cs
- UriExt.cs
- XmlUtil.cs
- MenuBindingsEditorForm.cs
- CountAggregationOperator.cs
- EventListener.cs
- SizeF.cs
- XPathDocument.cs
- MouseOverProperty.cs
- FilteredDataSetHelper.cs
- ListBindingConverter.cs
- Process.cs
- BamlRecords.cs
- RPIdentityRequirement.cs
- FrameworkContentElementAutomationPeer.cs
- GroupItem.cs
- brushes.cs
- SqlInternalConnectionSmi.cs
- Module.cs
- SmuggledIUnknown.cs
- DataBinder.cs
- InheritanceRules.cs
- _SslState.cs
- CqlParser.cs
- Mouse.cs
- _AutoWebProxyScriptEngine.cs
- LoginView.cs
- DispatchWrapper.cs
- AssemblyBuilderData.cs
- PasswordDeriveBytes.cs
- OLEDB_Enum.cs
- SettingsBindableAttribute.cs