Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / SafeBitVector32.cs / 1305376 / SafeBitVector32.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Threading; namespace System.Web.Util { // // This is a multithreadsafe version of System.Collections.Specialized.BitVector32. // [Serializable] internal struct SafeBitVector32 { private volatile int _data; internal SafeBitVector32(int data) { this._data = data; } internal bool this[int bit] { get { int data = _data; return (data & bit) == bit; } set { for (;;) { int oldData = _data; int newData; if (value) { newData = oldData | bit; } else { newData = oldData & ~bit; } #pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); #pragma warning restore 0420 if (result == oldData) { break; } } } } internal bool ChangeValue(int bit, bool value) { for (;;) { int oldData = _data; int newData; if (value) { newData = oldData | bit; } else { newData = oldData & ~bit; } if (oldData == newData) { return false; } #pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); #pragma warning restore 0420 if (result == oldData) { return true; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Threading; namespace System.Web.Util { // // This is a multithreadsafe version of System.Collections.Specialized.BitVector32. // [Serializable] internal struct SafeBitVector32 { private volatile int _data; internal SafeBitVector32(int data) { this._data = data; } internal bool this[int bit] { get { int data = _data; return (data & bit) == bit; } set { for (;;) { int oldData = _data; int newData; if (value) { newData = oldData | bit; } else { newData = oldData & ~bit; } #pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); #pragma warning restore 0420 if (result == oldData) { break; } } } } internal bool ChangeValue(int bit, bool value) { for (;;) { int oldData = _data; int newData; if (value) { newData = oldData | bit; } else { newData = oldData & ~bit; } if (oldData == newData) { return false; } #pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); #pragma warning restore 0420 if (result == oldData) { return true; } } } } } // 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
- DataGridRelationshipRow.cs
- Debug.cs
- SecurityKeyIdentifier.cs
- CompositeFontFamily.cs
- LocationInfo.cs
- AutoGeneratedFieldProperties.cs
- SmtpMail.cs
- SpeechEvent.cs
- AssociativeAggregationOperator.cs
- EventSinkActivityDesigner.cs
- ProfileEventArgs.cs
- IIS7WorkerRequest.cs
- LabelInfo.cs
- Win32SafeHandles.cs
- SoapObjectWriter.cs
- SecureStringHasher.cs
- PrintEvent.cs
- DataTable.cs
- InvariantComparer.cs
- SafeRegistryHandle.cs
- ToolBar.cs
- MenuItemStyle.cs
- WindowPattern.cs
- TextSegment.cs
- XPathBinder.cs
- ViewSimplifier.cs
- TypeListConverter.cs
- ToolStripLabel.cs
- Transform3DGroup.cs
- SAPICategories.cs
- TypeSchema.cs
- Parsers.cs
- VectorCollectionConverter.cs
- TypeFieldSchema.cs
- ADMembershipProvider.cs
- LogRestartAreaEnumerator.cs
- UserControl.cs
- AddInController.cs
- cookie.cs
- ScrollBar.cs
- RangeValuePattern.cs
- XmlSchemaComplexContentExtension.cs
- AppSecurityManager.cs
- ValidationException.cs
- PageTheme.cs
- BlockUIContainer.cs
- IHttpResponseInternal.cs
- ConfigXmlElement.cs
- FixedFindEngine.cs
- ToolStripCollectionEditor.cs
- Documentation.cs
- ColorTransform.cs
- TreeBuilderBamlTranslator.cs
- RegexCode.cs
- LowerCaseStringConverter.cs
- FragmentQuery.cs
- Row.cs
- RuntimeResourceSet.cs
- KeyedByTypeCollection.cs
- DataBinding.cs
- CollectionExtensions.cs
- DynamicEndpointElement.cs
- WriterOutput.cs
- LowerCaseStringConverter.cs
- ImpersonateTokenRef.cs
- ProviderMetadataCachedInformation.cs
- cookiecontainer.cs
- EmissiveMaterial.cs
- UpdateProgress.cs
- ParamArrayAttribute.cs
- HostProtectionException.cs
- CodeNamespaceImport.cs
- BinaryUtilClasses.cs
- MergeLocalizationDirectives.cs
- OdbcConnectionPoolProviderInfo.cs
- ResXFileRef.cs
- DataTemplate.cs
- DrawingServices.cs
- NavigationProperty.cs
- TextDecorationLocationValidation.cs
- Transform.cs
- ImageUrlEditor.cs
- MenuItemStyle.cs
- PropertyBuilder.cs
- TransformedBitmap.cs
- EnterpriseServicesHelper.cs
- OutputScopeManager.cs
- CompressedStack.cs
- PrintPreviewControl.cs
- DataFormats.cs
- GridViewHeaderRowPresenter.cs
- UserControlCodeDomTreeGenerator.cs
- DeclaredTypeElement.cs
- ScrollItemPattern.cs
- HttpListenerRequest.cs
- UTF32Encoding.cs
- HostingEnvironmentSection.cs
- TreeNodeStyle.cs
- Latin1Encoding.cs
- MatrixCamera.cs