- Timestamp:
- Apr 23, 2018 4:54:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Serial/DrvChar.cpp
r69500 r71987 32 32 #include <iprt/poll.h> 33 33 #include <iprt/stream.h> 34 #include <iprt/critsect.h> 34 35 #include <iprt/semaphore.h> 35 36 #include <iprt/uuid.h> … … 73 74 /** Event semaphore for the read relay thread. */ 74 75 RTSEMEVENT hEvtSemRead; 76 /** Critical section protection the send part. */ 77 RTCRITSECT CritSectSend; 75 78 76 79 /** Internal send FIFO queue */ … … 120 123 PDRVCHAR pThis = RT_FROM_MEMBER(pInterface, DRVCHAR, ICharConnector); 121 124 const char *pbBuffer = (const char *)pvBuf; 125 int rc = VINF_SUCCESS; 122 126 123 127 LogFlow(("%s: pvBuf=%#p cbWrite=%d\n", __FUNCTION__, pvBuf, cbWrite)); 124 128 125 for (uint32_t i = 0; i < cbWrite; i++) 129 RTCritSectEnter(&pThis->CritSectSend); 130 131 for (uint32_t i = 0; i < cbWrite && RT_SUCCESS(rc); i++) 126 132 { 127 if (ASMAtomicXchgBool(&pThis->fSending, true)) 128 return VERR_BUFFER_OVERFLOW; 129 130 pThis->u8SendByte = pbBuffer[i]; 131 pThis->pDrvStream->pfnPollInterrupt(pThis->pDrvStream); 132 STAM_COUNTER_INC(&pThis->StatBytesWritten); 133 if (!ASMAtomicXchgBool(&pThis->fSending, true)) 134 { 135 pThis->u8SendByte = pbBuffer[i]; 136 pThis->pDrvStream->pfnPollInterrupt(pThis->pDrvStream); 137 STAM_COUNTER_INC(&pThis->StatBytesWritten); 138 } 139 else 140 rc = VERR_BUFFER_OVERFLOW; 133 141 } 134 return VINF_SUCCESS; 142 143 RTCritSectLeave(&pThis->CritSectSend); 144 return rc; 135 145 } 136 146 … … 182 192 if (fEvtsRecv & RTPOLL_EVT_WRITE) 183 193 { 194 RTCritSectEnter(&pThis->CritSectSend); 184 195 Assert(pThis->fSending); 185 196 … … 206 217 break; 207 218 } 219 RTCritSectLeave(&pThis->CritSectSend); 208 220 } 209 221 … … 358 370 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 359 371 372 if (RTCritSectIsInitialized(&pThis->CritSectSend)) 373 RTCritSectDelete(&pThis->CritSectSend); 374 360 375 if (pThis->hEvtSemRead != NIL_RTSEMEVENT) 361 376 { … … 393 408 pThis->ICharConnector.pfnSetBreak = drvCharSetBreak; 394 409 410 int rc = RTCritSectInit(&pThis->CritSectSend); 411 if (RT_FAILURE(rc)) 412 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 413 N_("Char#%d: Failed to create critical section"), pDrvIns->iInstance); 414 395 415 /* 396 416 * Get the ICharPort interface of the above driver/device. … … 404 424 */ 405 425 PPDMIBASE pBase; 406 intrc = PDMDrvHlpAttach(pDrvIns, fFlags, &pBase);426 rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pBase); 407 427 if (RT_FAILURE(rc)) 408 428 return rc; /* Don't call PDMDrvHlpVMSetError here as we assume that the driver already set an appropriate error */
Note:
See TracChangeset
for help on using the changeset viewer.