예제 #1
0
        /// <summary>
        /// Append the specified value, commutatively - if you don't / haven't touched the
        /// sequence in this transaction (using other methods/properties), this will not cause
        /// conflicts! Effectively, the value is simply appended to whatever the sequence
        /// is at commit time. Multiple calls to Append made in one transaction will
        /// append the items in that order - they commute with other transactions only.
        /// </summary>
        public void Append(T val)
        {
            var newItem = new ItemKeeper(val, null, _owner);

            Shield.EnlistCommute(() => {
                if (_head.Value == null)
                {
                    _head.Value = newItem;
                    _tail.Value = newItem;
                }
                else
                {
                    _tail.Modify((ref ItemKeeper t) => {
                        t.Next.Value = newItem;
                        t            = newItem;
                    });
                }
            }, _head, _tail); // the commute degenerates if you read from the seq..
        }