Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- UInt64Storage.cs
- KeyValueSerializer.cs
- EntitySetDataBindingList.cs
- MaterialGroup.cs
- recordstate.cs
- BaseCodeDomTreeGenerator.cs
- TypeSystem.cs
- NamespaceQuery.cs
- DynamicPropertyHolder.cs
- ExtenderControl.cs
- BrowserDefinition.cs
- MailWebEventProvider.cs
- ShaderRenderModeValidation.cs
- ExecutionTracker.cs
- DataGridViewDataConnection.cs
- StringToken.cs
- ScrollEventArgs.cs
- basemetadatamappingvisitor.cs
- InstalledVoice.cs
- ProxyAttribute.cs
- ConsoleKeyInfo.cs
- UITypeEditor.cs
- HijriCalendar.cs
- LocalValueEnumerator.cs
- SerializationInfo.cs
- InkCanvas.cs
- RowsCopiedEventArgs.cs
- OneToOneMappingSerializer.cs
- ListSourceHelper.cs
- FlowDocumentView.cs
- ToolStripComboBox.cs
- parserscommon.cs
- AutoGeneratedFieldProperties.cs
- VirtualizingStackPanel.cs
- BooleanAnimationUsingKeyFrames.cs
- Debugger.cs
- ResourcesGenerator.cs
- X509CertificateChain.cs
- HyperLinkStyle.cs
- __Error.cs
- XmlNodeList.cs
- WebPartRestoreVerb.cs
- EncoderReplacementFallback.cs
- RunClient.cs
- GridViewColumnCollection.cs
- WorkflowApplicationCompletedEventArgs.cs
- BaseDataListActionList.cs
- CompensateDesigner.cs
- XDRSchema.cs
- GlobalizationAssembly.cs
- Point.cs
- XmlBinaryReader.cs
- SafeArrayRankMismatchException.cs
- SqlInfoMessageEvent.cs
- OleDbEnumerator.cs
- TextBoxRenderer.cs
- ContainerCodeDomSerializer.cs
- ObsoleteAttribute.cs
- ToolStripPanelDesigner.cs
- Panel.cs
- Math.cs
- SecureEnvironment.cs
- EditorPart.cs
- Random.cs
- DataGridViewCheckBoxColumn.cs
- CatalogPartDesigner.cs
- DataComponentMethodGenerator.cs
- CachedFontFamily.cs
- DesignTimeXamlWriter.cs
- VisualBrush.cs
- XamlSerializerUtil.cs
- DataKeyArray.cs
- ExcludeFromCodeCoverageAttribute.cs
- StringArrayConverter.cs
- SettingsSection.cs
- ControlPaint.cs
- RegexWorker.cs
- HMACSHA1.cs
- InfoCardTraceRecord.cs
- XmlProcessingInstruction.cs
- ApplicationServiceHelper.cs
- IOThreadScheduler.cs
- FontSizeConverter.cs
- SystemInformation.cs
- FormViewDesigner.cs
- _DisconnectOverlappedAsyncResult.cs
- HighContrastHelper.cs
- ProvidersHelper.cs
- _CacheStreams.cs
- SessionPageStateSection.cs
- WebPartConnectionsDisconnectVerb.cs
- ConsoleTraceListener.cs
- DrawListViewSubItemEventArgs.cs
- ButtonChrome.cs
- AvTraceFormat.cs
- SyndicationDeserializer.cs
- NullNotAllowedCollection.cs
- ResourcesBuildProvider.cs
- ListControl.cs
- ExpandableObjectConverter.cs