Ejemplo n.º 1
0
        internal bool Read(FlagArray flags, ref int owner, out LockSlot <T> slot)
        {
            if (Read(ref owner, out slot))
            {
                return(true);
            }
            var resultLock = -1;

            foreach (var flag in flags.Flags)
            {
                if (!_slots.TryGet(flag, out var testSlot))
                {
                    continue;
                }

                if (slot?.CompareTo(testSlot) >= 0)
                {
                    continue;
                }

                slot       = testSlot;
                resultLock = flag;
            }
            if (Interlocked.CompareExchange(ref owner, resultLock, -1) != -1)
            {
                return(Read(ref owner, out slot));
            }
            return(slot != null);
        }
Ejemplo n.º 2
0
        internal bool Read(FlagArray flags, ref int owner, out LockSlot <T> slot)
        {
            if (Read(ref owner, out slot))
            {
                return(true);
            }
            var resultLock = -1;

            foreach (var flag in flags.Flags)
            {
                LockSlot <T> testSlot;
                if (!_slots.TryGet(flag, out testSlot))
                {
                    continue;
                }
                if (ReferenceEquals(slot, null) || slot.CompareTo(testSlot) < 0)
                {
                    slot       = testSlot;
                    resultLock = flag;
                }
            }
            if (Interlocked.CompareExchange(ref owner, resultLock, -1) != -1)
            {
                return(Read(ref owner, out slot));
            }
            if (slot == null)
            {
                return(false);
            }
            return(true);
        }