Пример #1
0
        public override ListItemData RunOnLinkedList(
            LinkedListExecutionState state)
        {
            if (state.Current == null || state.Current.Value.IsDummy)
            {
                return(null);
            }
            ListItemData prevalentData = state.Current.Value.Data;

            if (prevalentData.Value != oldValue)
            {
                return(prevalentData);
            }
            state.Current.Value =
                state.Current.Value.NewWithData(
                    prevalentData.NewWithValue(newValue));
            return(prevalentData);
        }
Пример #2
0
        public override ListItemData RunOnLfdll(LfdllExecutionState state)
        {
            if (state.Current == null || state.Current.IsDummyNode)
            {
                return(null);
            }
            ListItemData oldData = state.Current.Value;

            while (true)
            {
                if (oldData.Value != oldValue)
                {
                    return(oldData);
                }
                ListItemData prevalentData = state.Current.CompareExchangeValue(
                    oldData.NewWithValue(newValue), oldData);
                if (ReferenceEquals(prevalentData, oldData))
                {
                    return(prevalentData);
                }
                oldData = prevalentData;
            }
        }