VirtualBox

Changeset 25110 in vbox


Ignore:
Timestamp:
Nov 30, 2009 2:02:43 PM (15 years ago)
Author:
vboxsync
Message:

NAT: critical sections introduced. preventing signaling non-waiting semaphores.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r24636 r25110  
    170170    /** event to wakeup the guest receive thread */
    171171    RTSEMEVENT              EventRecv;
     172    RTCRITSECT              csEventRecv;
    172173    /** event to wakeup the guest urgent receive thread */
    173174    RTSEMEVENT              EventUrgRecv;
     175    RTCRITSECT              csEventUrgRecv;
    174176    /** Receive Req queue (deliver packets to the guest) */
    175177    PRTREQQUEUE             pRecvReqQueue;
     
    231233{
    232234    PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
     235    int rc;
    233236
    234237    if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
     
    237240    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    238241    {
     242        rc = RTCritSectEnter(&pThis->csEventRecv);
     243        AssertReleaseRC(rc);
    239244        RTReqProcess(pThis->pRecvReqQueue, 0);
     245        rc = RTCritSectLeave(&pThis->csEventRecv);
     246        AssertReleaseRC(rc);
    240247        if (ASMAtomicReadU32(&pThis->cPkt) == 0)
     248        {
    241249            RTSemEventWait(pThis->EventRecv, RT_INDEFINITE_WAIT);
     250        }
    242251    }
    243252    return VINF_SUCCESS;
     
    248257{
    249258    PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
    250     int rc = RTSemEventSignal(pThis->EventRecv);
     259    int rc;
     260    if (ASMAtomicReadU32(&pThis->cPkt) > 0)
     261    {
     262        rc = RTCritSectEnter(&pThis->csEventRecv);
     263        AssertReleaseRC(rc);
     264        rc = RTSemEventSignal(pThis->EventRecv);
     265        AssertReleaseRC(rc);
     266        rc = RTCritSectLeave(&pThis->csEventRecv);
     267    }
    251268
    252269    STAM_COUNTER_INC(&pThis->StatNATRecvWakeups);
    253     AssertReleaseRC(rc);
    254270    return VINF_SUCCESS;
    255271}
     
    264280    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    265281    {
     282        int rc;
     283        rc = RTCritSectEnter(&pThis->csEventUrgRecv);
     284        AssertReleaseRC(rc);
    266285        RTReqProcess(pThis->pUrgRecvReqQueue, 0);
     286        rc = RTCritSectLeave(&pThis->csEventUrgRecv);
     287        AssertReleaseRC(rc);
    267288        if (ASMAtomicReadU32(&pThis->cUrgPkt) == 0)
    268             RTSemEventWait(pThis->EventUrgRecv, RT_INDEFINITE_WAIT);
     289        {
     290            rc = RTSemEventWait(pThis->EventUrgRecv, RT_INDEFINITE_WAIT);
     291            AssertReleaseRC(rc);
     292        }
    269293    }
    270294    return VINF_SUCCESS;
     
    273297{
    274298    PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
    275     int rc = RTSemEventSignal(pThis->EventUrgRecv);
    276 
    277     AssertReleaseRC(rc);
     299    if (ASMAtomicReadU32(&pThis->cUrgPkt) > 0)
     300    {
     301        int rc;
     302        rc = RTCritSectEnter(&pThis->csEventUrgRecv);
     303        AssertReleaseRC(rc);
     304        rc = RTSemEventSignal(pThis->EventUrgRecv);
     305        AssertReleaseRC(rc);
     306        rc = RTCritSectLeave(&pThis->csEventUrgRecv);
     307        AssertReleaseRC(rc);
     308    }
     309
    278310    return VINF_SUCCESS;
    279311}
     
    317349    while(ASMAtomicReadU32(&pThis->cUrgPkt) != 0)
    318350    {
     351        rc = RTCritSectLeave(&pThis->csEventRecv);
     352        AssertReleaseRC(rc);
    319353        rc = RTSemEventWait(pThis->EventRecv, RT_INDEFINITE_WAIT);
    320354        if (   RT_FAILURE(rc)
     
    322356                 || rc == VERR_INTERRUPTED))
    323357            goto done_unlocked;
     358        rc = RTCritSectEnter(&pThis->csEventRecv);
     359        AssertReleaseRC(rc);
    324360    }
    325361
     
    11351171            rc = RTSemEventCreate(&pThis->EventRecv);
    11361172            rc = RTSemEventCreate(&pThis->EventUrgRecv);
     1173            rc = RTCritSectInit(&pThis->csEventRecv);
     1174            rc = RTCritSectInit(&pThis->csEventUrgRecv);
    11371175            rc = RTCritSectInit(&pThis->csDevAccess);
    11381176            rc = PDMDrvHlpTMTimerCreate(pThis->pDrvIns, TMCLOCK_REAL/*enmClock*/, drvNATSlowTimer,
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