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
- TemplateGroupCollection.cs
- CompilerErrorCollection.cs
- HotSpot.cs
- EncoderReplacementFallback.cs
- Window.cs
- ProfilePropertyNameValidator.cs
- CultureTable.cs
- ConnectionPoolManager.cs
- WindowsTooltip.cs
- MetadataSerializer.cs
- XPathChildIterator.cs
- ConfigXmlComment.cs
- SingleTagSectionHandler.cs
- Double.cs
- EDesignUtil.cs
- safelink.cs
- ThemeableAttribute.cs
- HMACMD5.cs
- OverlappedAsyncResult.cs
- Schema.cs
- CacheDependency.cs
- RegisteredDisposeScript.cs
- Util.cs
- basecomparevalidator.cs
- URL.cs
- DataKey.cs
- EmbeddedMailObject.cs
- ExpressionPrinter.cs
- Scheduler.cs
- DbDataRecord.cs
- Inflater.cs
- Preprocessor.cs
- safesecurityhelperavalon.cs
- InputMethodStateTypeInfo.cs
- PropertyMetadata.cs
- ListViewCancelEventArgs.cs
- ToolStripDropDownClosedEventArgs.cs
- SoapEnumAttribute.cs
- TailCallAnalyzer.cs
- BaseInfoTable.cs
- DynamicPropertyReader.cs
- HtmlHistory.cs
- DataGridParentRows.cs
- TimeSpanMinutesConverter.cs
- InvalidateEvent.cs
- EntityDesignerDataSourceView.cs
- PlainXmlSerializer.cs
- BindingGraph.cs
- DbDataSourceEnumerator.cs
- HtmlImage.cs
- DesignerCategoryAttribute.cs
- PolygonHotSpot.cs
- FontFaceLayoutInfo.cs
- TakeQueryOptionExpression.cs
- QilValidationVisitor.cs
- _LocalDataStoreMgr.cs
- ReadOnlyAttribute.cs
- SqlDataReaderSmi.cs
- panel.cs
- HitTestDrawingContextWalker.cs
- TransformPatternIdentifiers.cs
- CmsInterop.cs
- CaseStatement.cs
- RangeValidator.cs
- DependencyPropertyHelper.cs
- OciHandle.cs
- HashStream.cs
- TextEditorDragDrop.cs
- RawUIStateInputReport.cs
- XmlSequenceWriter.cs
- BitmapEffectGeneralTransform.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- VerticalAlignConverter.cs
- FormDesigner.cs
- SpellCheck.cs
- ImageCollectionEditor.cs
- UniqueEventHelper.cs
- SslStream.cs
- PkcsMisc.cs
- EdmTypeAttribute.cs
- CodeSubDirectoriesCollection.cs
- CodeLabeledStatement.cs
- NumberAction.cs
- TextEditorLists.cs
- WorkItem.cs
- CommandHelper.cs
- EventLogWatcher.cs
- HostingPreferredMapPath.cs
- DllNotFoundException.cs
- TcpClientSocketManager.cs
- FixedSOMPage.cs
- DirectoryNotFoundException.cs
- SafeEventLogReadHandle.cs
- ObjectSet.cs
- LinearGradientBrush.cs
- PackagingUtilities.cs
- ToolboxItemImageConverter.cs
- ChannelSinkStacks.cs
- HttpWrapper.cs
- HelloMessageApril2005.cs