Exemplo n.º 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;
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
        }