Example #1
0
        public static void sol_cmd_enq_deferred()
        {
            CLRList l;
            CLRList r;

            /* Reverse the list to preserve original command order. */

            for (r = null, l = deferred_cmds;
                 l != null;
                 r = CLRList.list_cons(l.data, r), l = CLRList.list_rest(l))
            {
                ;
            }

            /* Enqueue commands. */

            for (; r != null; r = CLRList.list_rest(r))
            {
                if (enq_fn.cmd_enq_fn != null)
                {
                    enq_fn.cmd_enq_fn.func((Command)r.data);
                }

                r.data = null;
            }

            deferred_cmds = null;
        }
Example #2
0
        public static void queue_enq(CLRQueue q, object data)
        {
            q.tail.data = data;
            q.tail.next = CLRList.list_cons((object)null, null);

            q.tail = q.tail.next;
        }
Example #3
0
        /*
         * Free the list cell FIRST and return the "next" member. The "data"
         * member is not freed.
         */
        public static CLRList list_rest(CLRList first)
        {
            CLRList rest = first.next;

            first = null;

            return(rest);
        }
Example #4
0
        public static void sol_cmd_enq(Command lnew)
        {
            if (defer_cmds != 0)
            {
                Command copy;
                CLRList l;
                CLRList p;

                for (p = null, l = deferred_cmds; l != null; p = l, l = l.next)
                {
                    Command cur = (Command)l.data;

                    /* Remove element made obsolete by the lnew command. */

                    if (lnew.type == cur.type &&
                        ((lnew.type == cmd_type.CMD_BODY_TIME &&
                          lnew.bodytime.bi == cur.bodytime.bi) ||
                         (lnew.type == cmd_type.CMD_BODY_PATH &&
                          lnew.bodypath.bi == cur.bodypath.bi)))
                    {
                        //free(cur);
                        cur = null;

                        if (p != null)
                        {
                            p.next = CLRList.list_rest(l);
                        }
                        else
                        {
                            deferred_cmds = CLRList.list_rest(l);
                        }

                        /*
                         * The operation above made the list pointer useless
                         * for the variable update part of the loop, and it
                         * seems a bit involved to recover from that in a
                         * proper fashion.  Fortunately, this very block
                         * ensures that there's only one element to remove, so
                         * no more iterations are needed.
                         */

                        l = null;
                        break;
                    }
                }

                copy = new Command();
                {
                    copy.CopyFrom(lnew);
                    deferred_cmds = CLRList.list_cons(copy, deferred_cmds);
                }
            }
            else if (enq_fn.cmd_enq_fn != null)
            {
                enq_fn.cmd_enq_fn.func(lnew);
            }
        }
Example #5
0
        public static CLRQueue CLR_queue_new()
        {
            CLRQueue lnew;

            lnew      = new CLRQueue();
            lnew.head = lnew.tail = CLRList.list_cons((object)null, null);

            return(lnew);
        }
Example #6
0
        /*
         * Allocate and return a list cell initialised with FIRST and REST as
         * "data" and "next" members, respectively.
         */
        public static CLRList list_cons(object first, CLRList rest)
        {
            CLRList lnew;

            lnew = new CLRList();
            {
                lnew.data = first;
                lnew.next = rest;
            }

            return(lnew);
        }
Example #7
0
        public static object queue_deq(CLRQueue q)
        {
            object data = null;

            if (queue_empty(q) == 0)
            {
                data   = q.head.data;
                q.head = CLRList.list_rest(q.head);
            }

            return(data);
        }
Example #8
0
 public CLRList()
 {
     data = null;
     next = null;
 }
Example #9
0
 public CLRQueue()
 {
     head = null;
     tail = null;
 }