1 //------------------------------------------------------------------------------
2 // <copyright file="SimpleBitVector32.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 using System.Threading;
10 namespace System.Web.Util {
12 // This is a multithreadsafe version of System.Collections.Specialized.BitVector32.
15 internal struct SafeBitVector32 {
16 private volatile int _data;
18 internal SafeBitVector32(int data) {
22 internal bool this[int bit] {
25 return (data & bit) == bit;
32 newData = oldData | bit;
35 newData = oldData & ~bit;
38 #pragma warning disable 0420
39 int result = Interlocked.CompareExchange(ref _data, newData, oldData);
40 #pragma warning restore 0420
42 if (result == oldData) {
50 internal bool ChangeValue(int bit, bool value) {
55 newData = oldData | bit;
58 newData = oldData & ~bit;
61 if (oldData == newData) {
65 #pragma warning disable 0420
66 int result = Interlocked.CompareExchange(ref _data, newData, oldData);
67 #pragma warning restore 0420
69 if (result == oldData) {