Esempio n. 1
0
        ///// <summary>
        ///// I was having a hard day.
        ///// </summary>
        ///// <returns></returns>
        //public string DebugStr()
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<Ref ");
        //    sb.Append(Id);
        //    sb.Append(", ");
        //    if (_tinfo == null)
        //        sb.Append("NO");
        //    else
        //        sb.AppendFormat("{0} {1}", _tinfo.Status.get(), _tinfo.StartPoint);
        //    sb.Append(", ");
        //    if (_tvals == null)
        //        sb.Append("TVals: NO");
        //    else
        //    {
        //        sb.Append("TVals: ");
        //        TVal t = _tvals;
        //        do
        //        {
        //            sb.Append(t.Point);
        //            sb.Append(" ");
        //        } while ((t = t.Prior) != _tvals);
        //    }
        //    sb.Append(">");
        //    return sb.ToString();
        //}

        #endregion

        #region IDeref Members

        /// <summary>
        /// Gets the (immutable) value the reference is holding.
        /// </summary>
        /// <returns>The value</returns>
        public override object deref()
        {
            LockingTransaction t = LockingTransaction.getRunning();

            if (t == null)
            {
                object ret = currentVal();
                //Console.WriteLine("Thr {0}, {1}: No-trans get => {2}", Thread.CurrentThread.ManagedThreadId,DebugStr(), ret);
                return(ret);
            }
            return(t.doGet(this, _tvals));
        }
Esempio n. 2
0
        /// <summary>
        /// Send an action (encapsulated message).
        /// </summary>
        /// <param name="action">The action to execute.</param>
        /// <remarks>
        /// <para>If there is a transaction running on this thread,
        /// defer execution until the transaction ends
        /// (enqueue the action on the transaction).</para>
        /// <para>If there is already an action running, enqueue it (nested).</para>
        /// <para>Otherwise, queue it for execution.</para>
        /// </remarks>
        internal static void DispatchAction(Action action)
        {
            LockingTransaction trans = LockingTransaction.getRunning();

            if (trans != null)
            {
                trans.enqueue(action);
            }
            else if (_nested != null)
            {
                _nested = _nested.cons(action);
            }
            else
            {
                action.Agent.Enqueue(action);
            }
        }