VirtualBox

Changeset 21151 in vbox for trunk/src/VBox/VMM/PDMQueue.cpp


Ignore:
Timestamp:
Jul 2, 2009 11:47:24 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49434
Message:

PDMQueue: Fixed leaking the last pending item when the consume returned false. Also, be more paranoid whe returning unconsumed items to the pending list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMQueue.cpp

    r21148 r21151  
    674674        &&  !pItemsRC
    675675        &&  !pItemsR0)
    676         /* Somebody was racing us. */
     676        /* Somebody may be racing us ... never mind. */
    677677        return true;
    678678
     
    723723            while (pItems)
    724724            {
     725                if (!pQueue->u.Dev.pfnCallback(pQueue->u.Dev.pDevIns, pItems))
     726                    break;
    725727                pCur = pItems;
    726728                pItems = pItems->pNextR3;
    727                 if (!pQueue->u.Dev.pfnCallback(pQueue->u.Dev.pDevIns, pCur))
    728                     break;
    729729                pdmR3QueueFree(pQueue, pCur);
    730730            }
     
    734734            while (pItems)
    735735            {
     736                if (!pQueue->u.Drv.pfnCallback(pQueue->u.Drv.pDrvIns, pItems))
     737                    break;
    736738                pCur = pItems;
    737739                pItems = pItems->pNextR3;
    738                 if (!pQueue->u.Drv.pfnCallback(pQueue->u.Drv.pDrvIns, pCur))
    739                     break;
    740740                pdmR3QueueFree(pQueue, pCur);
    741741            }
     
    745745            while (pItems)
    746746            {
     747                if (!pQueue->u.Int.pfnCallback(pQueue->pVMR3, pItems))
     748                    break;
    747749                pCur = pItems;
    748750                pItems = pItems->pNextR3;
    749                 if (!pQueue->u.Int.pfnCallback(pQueue->pVMR3, pCur))
    750                     break;
    751751                pdmR3QueueFree(pQueue, pCur);
    752752            }
     
    756756            while (pItems)
    757757            {
     758                if (!pQueue->u.Ext.pfnCallback(pQueue->u.Ext.pvUser, pItems))
     759                    break;
    758760                pCur = pItems;
    759761                pItems = pItems->pNextR3;
    760                 if (!pQueue->u.Ext.pfnCallback(pQueue->u.Ext.pvUser, pCur))
    761                     break;
    762762                pdmR3QueueFree(pQueue, pCur);
    763763            }
     
    775775    {
    776776        /*
    777          * Shit, no!
    778          *      1. Insert pCur.
    779          *      2. Reverse the list.
    780          *      3. Insert the LIFO at the tail of the pending list.
     777         * Reverse the list.
    781778         */
    782         pCur->pNextR3 = pItems;
    783         pItems = pCur;
    784 
    785         //pCur = pItems;
     779        pCur = pItems;
    786780        pItems = NULL;
    787781        while (pCur)
    788782        {
    789783            PPDMQUEUEITEMCORE pInsert = pCur;
    790             pCur = pCur->pNextR3;
     784            pCur = pInsert->pNextR3;
    791785            pInsert->pNextR3 = pItems;
    792786            pItems = pInsert;
    793787        }
    794788
    795         if (!ASMAtomicCmpXchgPtr((void * volatile *)&pQueue->pPendingR3, pItems, NULL))
    796         {
    797             pCur = pQueue->pPendingR3;
    798             while (pCur->pNextR3)
    799                 pCur = pCur->pNextR3;
    800             pCur->pNextR3 = pItems;
     789        /*
     790         * Insert the list at the tail of the pending list.
     791         */
     792        for (;;)
     793        {
     794            if (ASMAtomicCmpXchgPtr((void * volatile *)&pQueue->pPendingR3, pItems, NULL))
     795                break;
     796            PPDMQUEUEITEMCORE pPending = (PPDMQUEUEITEMCORE)ASMAtomicXchgPtr((void * volatile *)&pQueue->pPendingR3, NULL);
     797            if (pPending)
     798            {
     799                pCur = pPending;
     800                while (pCur->pNextR3)
     801                    pCur = pCur->pNextR3;
     802                pCur->pNextR3 = pItems;
     803                pItem = pPending;
     804            }
    801805        }
    802806        return false;
Note: See TracChangeset for help on using the changeset viewer.

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