コード例 #1
0
ファイル: Queue.cs プロジェクト: tkggand/UdtSharp
        void insert_(ulong ts, UDT u)
        {
            SNode n = u.m_pSNode;

            // do not insert repeated node
            if (n.m_iHeapLoc >= 0)
            {
                return;
            }

            m_iLastEntry++;
            m_pHeap[m_iLastEntry] = n;
            n.m_llTimeStamp       = ts;

            int q = m_iLastEntry;
            int p = q;

            while (p != 0)
            {
                p = (q - 1) >> 1;
                if (m_pHeap[p].m_llTimeStamp > m_pHeap[q].m_llTimeStamp)
                {
                    SNode t = m_pHeap[p];
                    m_pHeap[p]   = m_pHeap[q];
                    m_pHeap[q]   = t;
                    t.m_iHeapLoc = q;
                    q            = p;
                }
                else
                {
                    break;
                }
            }

            n.m_iHeapLoc = q;

            // an earlier event has been inserted, wake up sending worker
            if (n.m_iHeapLoc == 0)
            {
                m_pTimer.interrupt();
            }

            // first entry, activate the sending queue
            if (0 == m_iLastEntry)
            {
                m_pWindowCond.Set();
            }
        }
コード例 #2
0
ファイル: Queue.cs プロジェクト: tkggand/UdtSharp
        void remove_(UDT u)
        {
            SNode n = u.m_pSNode;

            if (n.m_iHeapLoc >= 0)
            {
                // remove the node from heap
                m_pHeap[n.m_iHeapLoc] = m_pHeap[m_iLastEntry];
                m_iLastEntry--;
                m_pHeap[n.m_iHeapLoc].m_iHeapLoc = n.m_iHeapLoc;

                int q = n.m_iHeapLoc;
                int p = q * 2 + 1;
                while (p <= m_iLastEntry)
                {
                    if ((p + 1 <= m_iLastEntry) && (m_pHeap[p].m_llTimeStamp > m_pHeap[p + 1].m_llTimeStamp))
                    {
                        p++;
                    }

                    if (m_pHeap[q].m_llTimeStamp > m_pHeap[p].m_llTimeStamp)
                    {
                        SNode t = m_pHeap[p];
                        m_pHeap[p]            = m_pHeap[q];
                        m_pHeap[p].m_iHeapLoc = p;
                        m_pHeap[q]            = t;
                        m_pHeap[q].m_iHeapLoc = q;

                        q = p;
                        p = q * 2 + 1;
                    }
                    else
                    {
                        break;
                    }
                }

                n.m_iHeapLoc = -1;
            }

            // the only event has been deleted, wake up immediately
            if (0 == m_iLastEntry)
            {
                m_pTimer.interrupt();
            }
        }