Changeset 45756 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Apr 26, 2013 4:09:56 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp
r45626 r45756 37 37 #include <iprt/assert.h> 38 38 #include <iprt/critsect.h> 39 #include <iprt/list.h> 39 40 #include <iprt/mem.h> 40 41 #include <iprt/once.h> … … 165 166 uint64_t u64NextFrameNo; 166 167 } USBPROXYPIPEOSX, *PUSBPROXYPIPEOSX, **PPUSBPROXYPIPEOSX; 168 169 typedef struct RUNLOOPREFLIST 170 { 171 RTLISTNODE List; 172 CFRunLoopRef RunLoopRef; 173 } RUNLOOPREFLIST, *PRUNLOOPREFLIST; 174 typedef RUNLOOPREFLIST **PPRUNLOOPREFLIST; 167 175 168 176 /** … … 192 200 /** List of isochronous buffer collections. 193 201 * These are allocated on demand by the URB queuing routine and then recycled until the interface is destroyed. */ 202 RTLISTANCHOR HeadOfRunLoopLst; 194 203 PUSBPROXYISOCBUFCOL pIsocBufCols; 195 204 } USBPROXYIFOSX, *PUSBPROXYIFOSX, **PPUSBPROXYIFOSX; … … 209 218 * (i.e. the default control pipe stuff). */ 210 219 CFRunLoopSourceRef RunLoopSrcRef; 211 /** The run loop this device and its interfaces send their events to. */212 CFRunLoopRef RunLoopRef;213 220 /** we want to add and remove RunLoopSourceRefs to run loop's of 221 * every EMT thread participated in USB processing. */ 222 RTLISTANCHOR HeadOfRunLoopLst; 214 223 /** Pointer to the proxy device instance. */ 215 224 PUSBPROXYDEV pProxyDev; … … 270 279 rc = RTErrConvertFromDarwin(krc); 271 280 return rc; 281 } 282 283 /** 284 * Adds Source ref to current run loop and adds it the list of runloops. 285 */ 286 static int usbProxyDarwinAddRunLoopRef(PRTLISTANCHOR pListHead, 287 CFRunLoopSourceRef SourceRef) 288 { 289 AssertPtrReturn(pListHead, VERR_INVALID_PARAMETER); 290 AssertReturn(CFRunLoopSourceIsValid(SourceRef), VERR_INVALID_PARAMETER); 291 292 if (CFRunLoopContainsSource(CFRunLoopGetCurrent(), SourceRef, g_pRunLoopMode)) 293 return VINF_SUCCESS; 294 295 /* Add to the list */ 296 PRUNLOOPREFLIST pListNode = (PRUNLOOPREFLIST)RTMemAllocZ(sizeof(RUNLOOPREFLIST)); 297 if (!pListNode) 298 return VERR_NO_MEMORY; 299 300 pListNode->RunLoopRef = CFRunLoopGetCurrent(); 301 302 CFRetain(pListNode->RunLoopRef); 303 CFRetain(SourceRef); /* We want to be aware of releasing */ 304 305 CFRunLoopAddSource(pListNode->RunLoopRef, SourceRef, g_pRunLoopMode); 306 307 RTListInit(&pListNode->List); 308 309 RTListAppend((PRTLISTNODE)pListHead, &pListNode->List); 310 311 return VINF_SUCCESS; 312 } 313 314 315 /* 316 * Removes all source reference from mode of run loop's we've registered them. 317 * 318 */ 319 static int usbProxyDarwinRemoveSourceRefFromAllRunLoops(PRTLISTANCHOR pHead, 320 CFRunLoopSourceRef SourceRef) 321 { 322 AssertPtrReturn(pHead, VERR_INVALID_PARAMETER); 323 324 while (RTListIsEmpty(pHead)) 325 { 326 PRUNLOOPREFLIST pNode = RTListGetFirst(pHead, RUNLOOPREFLIST, List); 327 /* XXX: Should Release Reference? */ 328 Assert(CFGetRetainCount(pNode->RunLoopRef)); 329 330 CFRunLoopRemoveSource(pNode->RunLoopRef, SourceRef, g_pRunLoopMode); 331 CFRelease(SourceRef); 332 CFRelease(pNode->RunLoopRef); 333 334 RTListNodeRemove(&pNode->List); 335 336 RTMemFree(pNode); 337 } 338 339 return VINF_SUCCESS; 272 340 } 273 341 … … 570 638 } 571 639 572 Assert(pDevOsX->pInFlightHead == pUrbOsX);573 640 /* 574 641 * Remove from the active list. … … 579 646 pUrbOsX->pPrev->pNext = pUrbOsX->pNext; 580 647 else 648 { 649 Assert(pDevOsX->pInFlightHead == pUrbOsX); 581 650 pDevOsX->pInFlightHead = pUrbOsX->pNext; 651 } 582 652 583 653 /* … … 615 685 if (pIf->RunLoopSrcRef) 616 686 { 617 CFRunLoopRemoveSource(pDevOsX->RunLoopRef, pIf->RunLoopSrcRef, g_pRunLoopMode); 687 int rc = usbProxyDarwinRemoveSourceRefFromAllRunLoops((PRTLISTANCHOR)&pIf->HeadOfRunLoopLst, pIf->RunLoopSrcRef); 688 AssertRC(rc); 689 618 690 CFRelease(pIf->RunLoopSrcRef); 619 691 pIf->RunLoopSrcRef = NULL; 692 RTListInit((PRTLISTNODE)&pIf->HeadOfRunLoopLst); 620 693 } 621 694 … … 822 895 if (irc == kIOReturnSuccess) 823 896 { 824 CFRunLoopAddSource(pDevOsX->RunLoopRef, pIf->RunLoopSrcRef, g_pRunLoopMode); 897 RTListInit((PRTLISTNODE)&pIf->HeadOfRunLoopLst); 898 usbProxyDarwinAddRunLoopRef(&pIf->HeadOfRunLoopLst, 899 pIf->RunLoopSrcRef); 825 900 826 901 /* … … 1150 1225 if (pDevOsX) 1151 1226 { 1227 RTListInit((PRTLISTNODE)&pDevOsX->HeadOfRunLoopLst); 1152 1228 vrc = RTCritSectInit(&pDevOsX->CritSect); 1153 1229 if (RT_SUCCESS(vrc)) … … 1156 1232 pDevOsX->ppDevI = ppDevI; 1157 1233 pDevOsX->pProxyDev = pProxyDev; 1158 pDevOsX->RunLoopRef = CFRunLoopGetCurrent();1159 CFRetain(pDevOsX->RunLoopRef); /* paranoia */1160 1234 1161 1235 /* … … 1174 1248 if (irc == kIOReturnSuccess) 1175 1249 { 1176 CFRunLoopAddSource(pDevOsX->RunLoopRef, pDevOsX->RunLoopSrcRef, g_pRunLoopMode);1177 1178 1250 /* 1179 1251 * Determine the active configuration. … … 1190 1262 1191 1263 pProxyDev->Backend.pv = pDevOsX; 1264 usbProxyDarwinAddRunLoopRef(&pDevOsX->HeadOfRunLoopLst, pDevOsX->RunLoopSrcRef); 1192 1265 return VINF_SUCCESS; /* return */ 1193 1266 } 1194 1267 vrc = VERR_VUSB_DEVICE_NOT_ATTACHED; 1195 1196 CFRunLoopRemoveSource(pDevOsX->RunLoopRef, pDevOsX->RunLoopSrcRef, g_pRunLoopMode);1197 1268 } 1198 1269 else … … 1267 1338 if (pDevOsX->RunLoopSrcRef) 1268 1339 { 1269 CFRunLoopRemoveSource(pDevOsX->RunLoopRef, pDevOsX->RunLoopSrcRef, g_pRunLoopMode); 1340 int rc = usbProxyDarwinRemoveSourceRefFromAllRunLoops(&pDevOsX->HeadOfRunLoopLst, pDevOsX->RunLoopSrcRef); 1341 AssertRC(rc); 1342 1343 RTListInit((PRTLISTNODE)&pDevOsX->HeadOfRunLoopLst); 1344 1270 1345 CFRelease(pDevOsX->RunLoopSrcRef); 1271 1346 pDevOsX->RunLoopSrcRef = NULL; … … 1295 1370 */ 1296 1371 RTCritSectDelete(&pDevOsX->CritSect); 1297 1298 if (pDevOsX->RunLoopRef)1299 {1300 CFRelease(pDevOsX->RunLoopRef);1301 pDevOsX->RunLoopRef = NULL;1302 }1303 1372 1304 1373 PUSBPROXYURBOSX pUrbOsX; … … 1530 1599 1531 1600 if (!CFRunLoopContainsSource(CFRunLoopGetCurrent(), pIf->RunLoopSrcRef, g_pRunLoopMode)) 1532 CFRunLoopAddSource(CFRunLoopGetCurrent(), pIf->RunLoopSrcRef, g_pRunLoopMode);1601 usbProxyDarwinAddRunLoopRef(&pIf->HeadOfRunLoopLst, pIf->RunLoopSrcRef); 1533 1602 1534 1603 } … … 1536 1605 1537 1606 if (!CFRunLoopContainsSource(CFRunLoopGetCurrent(), pDevOsX->RunLoopSrcRef, g_pRunLoopMode)) 1538 CFRunLoopAddSource(CFRunLoopGetCurrent(), pDevOsX->RunLoopSrcRef, g_pRunLoopMode);1607 usbProxyDarwinAddRunLoopRef(&pDevOsX->HeadOfRunLoopLst, pDevOsX->RunLoopSrcRef); 1539 1608 1540 1609 /*
Note:
See TracChangeset
for help on using the changeset viewer.