VirtualBox

Changeset 29976 in vbox for trunk/src


Ignore:
Timestamp:
Jun 2, 2010 11:25:57 AM (15 years ago)
Author:
vboxsync
Message:

HGCM: workaround for a hang (xTracker 4985).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/hgcm/HGCMThread.cpp

    r28800 r29976  
    9090        /* A caller thread waits for completion of a SENT message on this event. */
    9191        RTSEMEVENTMULTI m_eventSend;
     92        int32_t volatile m_i32MessagesProcessed;
    9293
    9394        /* Critical section for accessing the thread data, mostly for message queues. */
     
    213214    m_eventThread (0),
    214215    m_eventSend (0),
     216    m_i32MessagesProcessed (0),
    215217    m_fu32ThreadFlags (0),
    216218    m_pMsgInputQueueHead (NULL),
     
    433435        if (fWait)
    434436        {
     437            /* Immediately check if the message has been processed. */
    435438            while ((pMsg->m_fu32Flags & HGCM_MSG_F_PROCESSED) == 0)
    436439            {
    437                 RTSemEventMultiWait (m_eventSend, RT_INDEFINITE_WAIT);
     440                /* Poll infrequently to make sure no completed message has been missed. */
     441                RTSemEventMultiWait (m_eventSend, 1000);
     442
     443                LogFlow(("HGCMThread::MsgPost: wait completed flags = %08X\n", pMsg->m_fu32Flags));
     444
     445                if ((pMsg->m_fu32Flags & HGCM_MSG_F_PROCESSED) == 0)
     446                {
     447                    RTThreadYield();
     448                }
     449            }
     450
     451            /* 'Our' message has been processed, so should reset the semaphore.
     452             * There is still possible that another message has been processed
     453             * and the semaphore has been signalled again.
     454             * Reset only if there are no other messages completed.
     455             */
     456            int32_t c = ASMAtomicDecS32(&m_i32MessagesProcessed);
     457            Assert(c >= 0);
     458            if (c == 0)
     459            {
    438460                RTSemEventMultiReset (m_eventSend);
    439 
    440                 LogFlow(("HGCMThread::MsgPost: wait completed flags = %08X\n", pMsg->m_fu32Flags));
    441461            }
    442462
     
    581601        bool fWaited = ((pMsg->m_fu32Flags & HGCM_MSG_F_WAIT) != 0);
    582602
     603        if (fWaited)
     604        {
     605            ASMAtomicIncS32(&m_i32MessagesProcessed);
     606
     607            /* This should be done before setting the HGCM_MSG_F_PROCESSED flag. */
     608            pMsg->m_rcSend = result;
     609        }
     610
    583611        /* The message is now completed. */
    584612        pMsg->m_fu32Flags &= ~HGCM_MSG_F_IN_PROCESS;
     
    592620        if (fWaited)
    593621        {
    594             /* If message is being waited, then it is referenced by the waiter and the pointer
    595              * if valid even after hgcmObjDeleteHandle.
    596              */
    597             pMsg->m_rcSend = result;
    598 
    599622            /* Wake up all waiters. so they can decide if their message has been processed. */
    600623            RTSemEventMultiSignal (m_eventSend);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette