Changeset 27509 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Mar 18, 2010 11:47:16 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 59012
- Location:
- trunk/src/VBox/Runtime/r3/win
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/pipe-win.cpp
r27431 r27509 1018 1018 1019 1019 /** 1020 * Internal RTPollSetAdd helper that returns one or two handles that should be1021 * added tothe pollset.1020 * Internal RTPollSetAdd helper that returns the handle that should be added to 1021 * the pollset. 1022 1022 * 1023 1023 * @returns Valid handle on success, INVALID_HANDLE_VALUE on failure. 1024 1024 * @param hPipe The pipe handle. 1025 1025 * @param fEvents The events we're polling for. 1026 * @param ph1 wher to put the primary handle. 1027 * @param ph2 Where to optionally return a 2nd handle. 1026 * @param ph wher to put the primary handle. 1028 1027 */ 1029 int rtPipePollGetHandle s(RTPIPE hPipe, uint32_t fEvents, PHANDLE ph1, PHANDLE ph2)1028 int rtPipePollGetHandle(RTPIPE hPipe, uint32_t fEvents, PHANDLE ph) 1030 1029 { 1031 1030 RTPIPEINTERNAL *pThis = hPipe; … … 1036 1035 AssertReturn(!(fEvents & RTPOLL_EVT_WRITE) || !pThis->fRead, VERR_INVALID_PARAMETER); 1037 1036 1038 *ph1 = pThis->Overlapped.hEvent;1039 1037 /* Later: Try register an event handle with the pipe like on OS/2, there is 1040 1038 a file control for doing this obviously intended for the OS/2 subsys. 1041 1039 The question is whether this still exists on Vista and W7. */ 1042 *ph 2 = INVALID_HANDLE_VALUE;1040 *ph = pThis->Overlapped.hEvent; 1043 1041 return VINF_SUCCESS; 1044 1042 } … … 1127 1125 * @param hPollSet The poll set handle (for access checks). 1128 1126 * @param fEvents The events we're polling for. 1127 * @param fFinalEntry Set if this is the final entry for this handle 1128 * in this poll set. This can be used for dealing 1129 * with duplicate entries. 1129 1130 * @param fNoWait Set if it's a zero-wait poll call. Clear if 1130 1131 * we'll wait for an event to occur. 1131 1132 */ 1132 uint32_t rtPipePollStart(RTPIPE hPipe, RTPOLLSET hPollSet, uint32_t fEvents, bool f NoWait)1133 uint32_t rtPipePollStart(RTPIPE hPipe, RTPOLLSET hPollSet, uint32_t fEvents, bool fFinalEntry, bool fNoWait) 1133 1134 { 1134 1135 /** @todo All this polling code could be optimized to make fewer system … … 1207 1208 * @param hPipe The pipe handle. 1208 1209 * @param fEvents The events we're polling for. 1210 * @param fFinalEntry Set if this is the final entry for this handle 1211 * in this poll set. This can be used for dealing 1212 * with duplicate entries. Only keep in mind that 1213 * this method is called in reverse order, so the 1214 * first call will have this set (when the entire 1215 * set was processed). 1209 1216 */ 1210 uint32_t rtPipePollDone(RTPIPE hPipe, uint32_t fEvents )1217 uint32_t rtPipePollDone(RTPIPE hPipe, uint32_t fEvents, bool fFinalEntry) 1211 1218 { 1212 1219 RTPIPEINTERNAL *pThis = hPipe; -
trunk/src/VBox/Runtime/r3/win/poll-win.cpp
r27431 r27509 2 2 /** @file 3 3 * IPRT - Polling I/O Handles, Windows Implementation. 4 * 5 * @todo merge poll-win.cpp and poll-posix.cpp, there is lots of common code. 4 6 */ 5 7 … … 46 48 #include <iprt/thread.h> 47 49 #include <iprt/time.h> 50 48 51 #include "internal/pipe.h" 52 #define IPRT_INTERNAL_SOCKET_POLLING_ONLY 53 #include "internal/socket.h" 49 54 #include "internal/magics.h" 50 55 … … 64 69 /** The events we're waiting for here. */ 65 70 uint32_t fEvents; 71 /** Set if this is the final entry for this handle. 72 * If the handle is entered more than once, this will be clear for all but 73 * the last entry. */ 74 bool fFinalEntry; 66 75 /** The handle union. */ 67 76 RTHANDLEUNION u; … … 123 132 { 124 133 case RTHANDLETYPE_PIPE: 125 fEvents = rtPipePollStart(pThis->aHandles[i].u.hPipe, pThis, pThis->aHandles[i].fEvents, fNoWait); 134 fEvents = rtPipePollStart(pThis->aHandles[i].u.hPipe, pThis, pThis->aHandles[i].fEvents, 135 pThis->aHandles[i].fFinalEntry, fNoWait); 136 break; 137 138 case RTHANDLETYPE_SOCKET: 139 fEvents = rtSocketPollStart(pThis->aHandles[i].u.hSocket, pThis, pThis->aHandles[i].fEvents, 140 pThis->aHandles[i].fFinalEntry, fNoWait); 126 141 break; 127 142 … … 155 170 { 156 171 case RTHANDLETYPE_PIPE: 157 rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents); 172 rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents, 173 pThis->aHandles[i].fFinalEntry); 158 174 break; 175 176 case RTHANDLETYPE_SOCKET: 177 rtSocketPollDone(pThis->aHandles[i].u.hSocket, pThis->aHandles[i].fEvents, 178 pThis->aHandles[i].fFinalEntry); 179 break; 180 159 181 default: 160 182 AssertFailed(); … … 198 220 { 199 221 case RTHANDLETYPE_PIPE: 200 fEvents = rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents); 201 break; 222 rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents, 223 pThis->aHandles[i].fFinalEntry); 224 break; 225 226 case RTHANDLETYPE_SOCKET: 227 rtSocketPollDone(pThis->aHandles[i].u.hSocket, pThis->aHandles[i].fEvents, 228 pThis->aHandles[i].fFinalEntry); 229 break; 230 202 231 default: 203 232 AssertFailed(); … … 230 259 * Set the busy flag and do the job. 231 260 */ 232 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_ WRONG_ORDER);261 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 233 262 234 263 int rc; … … 270 299 * Set the busy flag and do the job. 271 300 */ 272 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_ WRONG_ORDER);301 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 273 302 274 303 int rc = rtPollNoResumeWorker(pThis, cMillies, pfEvents, pid); … … 305 334 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 306 335 AssertReturn(pThis->u32Magic == RTPOLLSET_MAGIC, VERR_INVALID_HANDLE); 307 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_ WRONG_ORDER);336 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 308 337 309 338 ASMAtomicWriteU32(&pThis->u32Magic, ~RTPOLLSET_MAGIC); … … 334 363 * Set the busy flag and do the job. 335 364 */ 336 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_WRONG_ORDER); 337 338 int rc = VINF_SUCCESS; 339 HANDLE hNative = INVALID_HANDLE_VALUE; 340 HANDLE hNative2 = INVALID_HANDLE_VALUE; 365 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 366 367 int rc = VINF_SUCCESS; 368 HANDLE hNative = INVALID_HANDLE_VALUE; 369 RTHANDLEUNION uh; 370 uh.uInt = 0; 341 371 switch (pHandle->enmType) 342 372 { 343 373 case RTHANDLETYPE_PIPE: 344 if (pHandle->u.hPipe != NIL_RTPIPE) 345 rc = rtPipePollGetHandles(pHandle->u.hPipe, fEvents, &hNative, &hNative2); 374 uh.hPipe = pHandle->u.hPipe; 375 if (uh.hPipe != NIL_RTPIPE) 376 rc = rtPipePollGetHandle(uh.hPipe, fEvents, &hNative); 346 377 break; 347 378 348 379 case RTHANDLETYPE_SOCKET: 349 if (pHandle->u.hSocket != NIL_RTSOCKET) 350 rc = VERR_NOT_IMPLEMENTED; 380 uh.hSocket = pHandle->u.hSocket; 381 if (uh.hSocket != NIL_RTSOCKET) 382 rc = rtSocketPollGetHandle(uh.hSocket, fEvents, &hNative); 351 383 break; 352 384 … … 372 404 373 405 /* Check that the handle ID doesn't exist already. */ 374 uint32_t j = i; 406 uint32_t iPrev = UINT32_MAX; 407 uint32_t j = i; 375 408 while (j-- > 0) 409 { 376 410 if (pThis->aHandles[j].id == id) 377 411 { … … 379 413 break; 380 414 } 415 if ( pThis->aHandles[j].enmType == pHandle->enmType 416 && pThis->aHandles[j].u.uInt == uh.uInt) 417 iPrev = j; 418 } 381 419 382 420 /* Check that we won't overflow the poll set now. */ 383 421 if ( RT_SUCCESS(rc) 384 && i + 1 + (hNative2 != INVALID_HANDLE_VALUE)> RT_ELEMENTS(pThis->ahNative))422 && i + 1 > RT_ELEMENTS(pThis->ahNative)) 385 423 rc = VERR_POLL_SET_IS_FULL; 386 424 if (RT_SUCCESS(rc)) 387 425 { 388 426 /* Add the handles to the two parallel arrays. */ 389 pThis->ahNative[i] = hNative; 390 pThis->aHandles[i].enmType = pHandle->enmType; 391 pThis->aHandles[i].u = pHandle->u; 392 pThis->aHandles[i].id = id; 393 pThis->aHandles[i].fEvents = fEvents; 394 if (hNative2 == INVALID_HANDLE_VALUE) 395 pThis->cHandles = i + 1; 396 else 427 pThis->ahNative[i] = hNative; 428 pThis->aHandles[i].enmType = pHandle->enmType; 429 pThis->aHandles[i].u = uh; 430 pThis->aHandles[i].id = id; 431 pThis->aHandles[i].fEvents = fEvents; 432 pThis->aHandles[i].fFinalEntry = true; 433 pThis->cHandles = i + 1; 434 435 if (iPrev != UINT32_MAX) 397 436 { 398 pThis->ahNative[i + 1] = hNative2; 399 pThis->aHandles[i + 1] = pThis->aHandles[i]; 400 pThis->cHandles = i + 2; 437 Assert(pThis->aHandles[i].fFinalEntry); 438 pThis->aHandles[i].fFinalEntry = false; 401 439 } 402 440 … … 423 461 * Set the busy flag and do the job. 424 462 */ 425 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_ WRONG_ORDER);463 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 426 464 427 465 int rc = VERR_POLL_HANDLE_ID_NOT_FOUND; … … 430 468 if (pThis->aHandles[i].id == id) 431 469 { 470 /* Save some details for the duplicate searching. */ 471 bool fFinalEntry = pThis->aHandles[i].fFinalEntry; 472 RTHANDLETYPE enmType = pThis->aHandles[i].enmType; 473 RTHANDLEUNION uh = pThis->aHandles[i].u; 474 475 /* Remove the entry. */ 432 476 pThis->cHandles--; 433 477 size_t const cToMove = pThis->cHandles - i; … … 437 481 memmove(&pThis->ahNative[i], &pThis->ahNative[i + 1], cToMove * sizeof(pThis->ahNative[i])); 438 482 } 483 484 /* Check for duplicate and set the fFinalEntry flag. */ 485 if (fFinalEntry) 486 while (i-- > 0) 487 if ( pThis->aHandles[i].u.uInt == uh.uInt 488 && pThis->aHandles[i].enmType == enmType) 489 { 490 Assert(!pThis->aHandles[i].fFinalEntry); 491 pThis->aHandles[i].fFinalEntry = true; 492 break; 493 } 494 439 495 rc = VINF_SUCCESS; 496 break; 440 497 } 441 498 … … 459 516 * Set the busy flag and do the job. 460 517 */ 461 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_ WRONG_ORDER);518 AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), VERR_CONCURRENT_ACCESS); 462 519 463 520 int rc = VERR_POLL_HANDLE_ID_NOT_FOUND; … … 480 537 481 538 482 RTDECL(uint32_t) RTPollSet Count(RTPOLLSET hPollSet)539 RTDECL(uint32_t) RTPollSetGetCount(RTPOLLSET hPollSet) 483 540 { 484 541 /* … … 499 556 } 500 557 501
Note:
See TracChangeset
for help on using the changeset viewer.