示例#1
0
        private static void SetPageBitMapEntry32(uint start2, uint count, bool set)
        {
            uint at = start2;

            while (count > 0)
            {
                uint index = at >> 17;
                uint slot  = index * 4;

                var bitmap = BitMapIndexTable.GetBitMapEntry(slot);

                byte start = (byte)(at & 0b11111);
                uint diff  = start + count - 1;
                byte end   = (byte)(diff <= 31 ? diff : 31);
                byte size  = (byte)(end - start + 1);

                uint mask = BitSet32(start, size);

                uint offset32 = (at >> 10) & 0b11111;

                var value = bitmap.Load32(offset32);

                uint newvalue = set ? (value | mask) : (value & ~mask);

                bitmap.Store32(offset32, newvalue);

                count -= size;
                at    += size;
            }
        }
示例#2
0
        private static void SetPageBitMapEntry(uint start, uint count, bool set)
        {
            var indexShift   = (IntPtr.Size == 4) ? 10 : 9;
            var maskOffIndex = (uint)((1 << (indexShift + 1)) - 1);

            var at = start;

            // TODO: Acquire lock

            while (count > 0)
            {
                var index = (int)(at >> indexShift);

                var bitmap = BitMapIndexTable.GetBitMapEntry((uint)index);

                if (at % 64 == 0 && count >= 64)
                {
                    // 64 bit update
                    var offset = (uint)((index & maskOffIndex) >> 6);

                    bitmap.Store64(offset, set ? ulong.MaxValue : 0);

                    at    += 64;
                    count -= 64;
                }
                else if (at % 32 == 0 && count >= 32)
                {
                    // 32 bit update
                    var offset = (uint)((index & maskOffIndex) >> 5);

                    bitmap.Store32(offset, set ? uint.MaxValue : 0);

                    at    += 32;
                    count -= 32;
                }
                else if (at % 8 == 0 && count >= 8)
                {
                    // 8 bit update
                    var offset = (uint)((index & maskOffIndex) >> 5);

                    bitmap.Store8(offset, set ? byte.MaxValue : (byte)0);

                    at    += 8;
                    count -= 8;
                }
                else
                {
                    // one bit update
                    var offset = (uint)((index & maskOffIndex) >> 3);
                    var value  = bitmap.Load8(offset);

                    var bit = (byte)(1 << index & 0b111);
                    value = (byte)(set ? value | bit : value & bit);

                    bitmap.Store8(offset, value);

                    at    += 1;
                    count -= 1;
                }
            }
        }