Code:
                         / FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / Util / SafeBitVector32.cs / 1 / 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; 
        }
#if UNUSED_CODE
 
        internal int IntegerValue {
            get { return _data; } 
            set { 
#pragma warning disable 0420
                Interlocked.Exchange(ref _data, value); 
#pragma warning restore 0420
            }
        } 
#endif 
 
        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;
                }
            } 
        }
    } 
} 
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSchemaAttributeGroupRef.cs
- XmlElementCollection.cs
- DoubleAnimationBase.cs
- StyleBamlTreeBuilder.cs
- safelinkcollection.cs
- MessagingDescriptionAttribute.cs
- FixedHyperLink.cs
- X509SecurityTokenAuthenticator.cs
- ToolStripButton.cs
- DateTimeValueSerializerContext.cs
- Vector3DValueSerializer.cs
- HexParser.cs
- MdiWindowListItemConverter.cs
- TrackingDataItem.cs
- ProgressBar.cs
- SafeCertificateStore.cs
- DataGridTextBoxColumn.cs
- ScriptHandlerFactory.cs
- DesignerForm.cs
- DateTimeSerializationSection.cs
- IndexedEnumerable.cs
- ActivitySurrogateSelector.cs
- regiisutil.cs
- NumberFormatInfo.cs
- Errors.cs
- SettingsBase.cs
- ArrayList.cs
- DispatcherOperation.cs
- Image.cs
- TextEditorParagraphs.cs
- PrivateFontCollection.cs
- Int64KeyFrameCollection.cs
- AmbientValueAttribute.cs
- Point3DKeyFrameCollection.cs
- TemplatePropertyEntry.cs
- OdbcException.cs
- SpotLight.cs
- XmlUnspecifiedAttribute.cs
- OSFeature.cs
- ControlPager.cs
- HtmlDocument.cs
- ChtmlTextWriter.cs
- DbMetaDataCollectionNames.cs
- FixedStringLookup.cs
- AudioFormatConverter.cs
- Cell.cs
- FileDialogPermission.cs
- CroppedBitmap.cs
- HashMembershipCondition.cs
- DataFormat.cs
- ConnectionInterfaceCollection.cs
- HwndTarget.cs
- SqlDataSourceSelectingEventArgs.cs
- AttachmentService.cs
- DataPager.cs
- ConnectionProviderAttribute.cs
- InternalControlCollection.cs
- EntityType.cs
- ClusterRegistryConfigurationProvider.cs
- DelegateCompletionCallbackWrapper.cs
- XDeferredAxisSource.cs
- QueuedDeliveryRequirementsMode.cs
- RunWorkerCompletedEventArgs.cs
- GeometryDrawing.cs
- LocationUpdates.cs
- CopyOnWriteList.cs
- InvalidComObjectException.cs
- OleDbError.cs
- TextBox.cs
- LineServices.cs
- GridViewRowEventArgs.cs
- RegexMatchCollection.cs
- WorkflowInvoker.cs
- NodeLabelEditEvent.cs
- GroupBox.cs
- ModuleBuilder.cs
- XmlHierarchicalEnumerable.cs
- SecurityTokenResolver.cs
- Rules.cs
- ComboBox.cs
- PropertyEntry.cs
- InstancePersistenceEvent.cs
- WindowsGrip.cs
- Header.cs
- ToolStripOverflow.cs
- CompilerParameters.cs
- RenderTargetBitmap.cs
- FunctionQuery.cs
- UpdateTracker.cs
- CheckBoxFlatAdapter.cs
- codemethodreferenceexpression.cs
- HttpCachePolicyWrapper.cs
- TableRow.cs
- BaseAsyncResult.cs
- Configuration.cs
- FixUpCollection.cs
- ContentWrapperAttribute.cs
- TerminateDesigner.cs
- ResourceIDHelper.cs
- SinglePhaseEnlistment.cs