Changeset 90637 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 11, 2021 9:15:42 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/generic/critsectrw-generic.cpp
r82968 r90637 107 107 pThis->fFlags = (uint16_t)(fFlags & ~RTCRITSECT_FLAGS_RING0); 108 108 #endif 109 pThis->u64State = 0; 110 pThis->hNativeWriter = NIL_RTNATIVETHREAD; 109 pThis->u.u128.s.Hi = 0; 110 pThis->u.u128.s.Lo = 0; 111 pThis->u.s.hNativeWriter= NIL_RTNATIVETHREAD; 112 AssertCompile(sizeof(pThis->u.u128) >= sizeof(pThis->u.s)); 111 113 pThis->cWriterReads = 0; 112 114 pThis->cWriteRecursions = 0; … … 115 117 pThis->pValidatorWrite = NULL; 116 118 pThis->pValidatorRead = NULL; 117 #if HC_ARCH_BITS == 32118 pThis->HCPtrPadding = NIL_RTHCPTR;119 #endif120 119 121 120 #ifdef RTCRITSECTRW_STRICT … … 216 215 int rc9; 217 216 RTNATIVETHREAD hNativeWriter; 218 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);217 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 219 218 if (hNativeWriter != NIL_RTTHREAD && hNativeWriter == RTThreadNativeSelf()) 220 219 rc9 = RTLockValidatorRecExclCheckOrder(pThis->pValidatorWrite, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT); … … 229 228 * Get cracking... 230 229 */ 231 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);230 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 232 231 uint64_t u64OldState = u64State; 233 232 … … 242 241 u64State &= ~RTCSRW_CNT_RD_MASK; 243 242 u64State |= c << RTCSRW_CNT_RD_SHIFT; 244 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))243 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 245 244 { 246 245 #ifdef RTCRITSECTRW_STRICT … … 255 254 u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); 256 255 u64State |= (UINT64_C(1) << RTCSRW_CNT_RD_SHIFT) | (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT); 257 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))256 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 258 257 { 259 258 Assert(!pThis->fNeedReset); … … 269 268 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 270 269 RTNATIVETHREAD hNativeWriter; 271 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);270 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 272 271 if (hNativeSelf == hNativeWriter) 273 272 { … … 291 290 { 292 291 IPRT_CRITSECTRW_SHARED_BUSY(pThis, NULL, 293 (void *)pThis-> hNativeWriter,292 (void *)pThis->u.s.hNativeWriter, 294 293 (uint32_t)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT), 295 294 (uint32_t)((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT)); … … 310 309 u64State |= (c << RTCSRW_CNT_RD_SHIFT) | (cWait << RTCSRW_WAIT_CNT_RD_SHIFT); 311 310 312 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))311 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 313 312 { 314 313 IPRT_CRITSECTRW_SHARED_WAITING(pThis, NULL, 315 (void *)pThis-> hNativeWriter,314 (void *)pThis->u.s.hNativeWriter, 316 315 (uint32_t)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT), 317 316 (uint32_t)((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT)); … … 340 339 for (;;) 341 340 { 342 u64OldState = u64State = ASMAtomicReadU64(&pThis->u 64State);341 u64OldState = u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 343 342 c = (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; Assert(c > 0); 344 343 c--; … … 347 346 u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_WAIT_CNT_RD_MASK); 348 347 u64State |= (c << RTCSRW_CNT_RD_SHIFT) | (cWait << RTCSRW_WAIT_CNT_RD_SHIFT); 349 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))348 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 350 349 break; 351 350 } … … 354 353 355 354 Assert(pThis->fNeedReset); 356 u64State = ASMAtomicReadU64(&pThis->u 64State);355 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 357 356 if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) 358 357 break; … … 371 370 u64State |= cWait << RTCSRW_WAIT_CNT_RD_SHIFT; 372 371 373 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))372 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 374 373 { 375 374 if (cWait == 0) … … 383 382 break; 384 383 } 385 u64State = ASMAtomicReadU64(&pThis->u 64State);384 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 386 385 } 387 386 … … 397 396 398 397 ASMNopPause(); 399 u64State = ASMAtomicReadU64(&pThis->u 64State);398 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 400 399 u64OldState = u64State; 401 400 } 402 401 403 402 /* got it! */ 404 Assert((ASMAtomicReadU64(&pThis->u 64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT));403 Assert((ASMAtomicReadU64(&pThis->u.s.u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)); 405 404 IPRT_CRITSECTRW_SHARED_ENTERED(pThis, NULL, 406 405 (uint32_t)((u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT), … … 467 466 * Check the direction and take action accordingly. 468 467 */ 469 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);468 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 470 469 uint64_t u64OldState = u64State; 471 470 if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) … … 492 491 u64State &= ~RTCSRW_CNT_RD_MASK; 493 492 u64State |= c << RTCSRW_CNT_RD_SHIFT; 494 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))493 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 495 494 break; 496 495 } … … 500 499 u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_DIR_MASK); 501 500 u64State |= RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT; 502 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))501 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 503 502 { 504 503 int rc = RTSemEventSignal(pThis->hEvtWrite); … … 509 508 510 509 ASMNopPause(); 511 u64State = ASMAtomicReadU64(&pThis->u 64State);510 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 512 511 u64OldState = u64State; 513 512 } … … 517 516 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 518 517 RTNATIVETHREAD hNativeWriter; 519 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);518 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 520 519 AssertReturn(hNativeSelf == hNativeWriter, VERR_NOT_OWNER); 521 520 AssertReturn(pThis->cWriterReads > 0, VERR_NOT_OWNER); … … 567 566 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 568 567 RTNATIVETHREAD hNativeWriter; 569 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);568 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 570 569 if (hNativeSelf == hNativeWriter) 571 570 { 572 Assert((ASMAtomicReadU64(&pThis->u 64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT));571 Assert((ASMAtomicReadU64(&pThis->u.s.u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)); 573 572 #ifdef RTCRITSECTRW_STRICT 574 573 int rc9 = RTLockValidatorRecExclRecursion(pThis->pValidatorWrite, pSrcPos); … … 582 581 if (IPRT_CRITSECTRW_EXCL_ENTERED_ENABLED()) 583 582 { 584 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);583 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 585 584 IPRT_CRITSECTRW_EXCL_ENTERED(pThis, NULL, cNestings + pThis->cWriterReads, 586 585 (uint32_t)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT), … … 594 593 * Get cracking. 595 594 */ 596 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);595 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 597 596 uint64_t u64OldState = u64State; 598 597 … … 608 607 u64State &= ~RTCSRW_CNT_WR_MASK; 609 608 u64State |= c << RTCSRW_CNT_WR_SHIFT; 610 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))609 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 611 610 break; 612 611 } … … 616 615 u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); 617 616 u64State |= (UINT64_C(1) << RTCSRW_CNT_WR_SHIFT) | (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT); 618 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))617 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 619 618 break; 620 619 } … … 630 629 u64State &= ~RTCSRW_CNT_WR_MASK; 631 630 u64State |= c << RTCSRW_CNT_WR_SHIFT; 632 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))631 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 633 632 break; 634 633 } … … 638 637 639 638 ASMNopPause(); 640 u64State = ASMAtomicReadU64(&pThis->u 64State);639 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 641 640 u64OldState = u64State; 642 641 } … … 650 649 || fTryOnly); 651 650 if (fDone) 652 ASMAtomicCmpXchgHandle(&pThis-> hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone);651 ASMAtomicCmpXchgHandle(&pThis->u.s.hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone); 653 652 if (!fDone) 654 653 { … … 660 659 for (;;) 661 660 { 662 u64OldState = u64State = ASMAtomicReadU64(&pThis->u 64State);661 u64OldState = u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 663 662 uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; Assert(c > 0); 664 663 c--; 665 664 u64State &= ~RTCSRW_CNT_WR_MASK; 666 665 u64State |= c << RTCSRW_CNT_WR_SHIFT; 667 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))666 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 668 667 break; 669 668 } … … 673 672 (uint32_t)((u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT), 674 673 (uint32_t)((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT), 675 (void *)pThis-> hNativeWriter);674 (void *)pThis->u.s.hNativeWriter); 676 675 return VERR_SEM_BUSY; 677 676 } … … 685 684 (uint32_t)((u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT), 686 685 (uint32_t)((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT), 687 (void *)pThis-> hNativeWriter);686 (void *)pThis->u.s.hNativeWriter); 688 687 for (uint32_t iLoop = 0; ; iLoop++) 689 688 { … … 712 711 for (;;) 713 712 { 714 u64OldState = u64State = ASMAtomicReadU64(&pThis->u 64State);713 u64OldState = u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 715 714 uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; Assert(c > 0); 716 715 c--; 717 716 u64State &= ~RTCSRW_CNT_WR_MASK; 718 717 u64State |= c << RTCSRW_CNT_WR_SHIFT; 719 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))718 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 720 719 break; 721 720 } … … 723 722 } 724 723 725 u64State = ASMAtomicReadU64(&pThis->u 64State);724 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 726 725 if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)) 727 726 { 728 ASMAtomicCmpXchgHandle(&pThis-> hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone);727 ASMAtomicCmpXchgHandle(&pThis->u.s.hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone); 729 728 if (fDone) 730 729 break; … … 737 736 * Got it! 738 737 */ 739 Assert((ASMAtomicReadU64(&pThis->u 64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT));738 Assert((ASMAtomicReadU64(&pThis->u.s.u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)); 740 739 ASMAtomicWriteU32(&pThis->cWriteRecursions, 1); 741 740 Assert(pThis->cWriterReads == 0); … … 806 805 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 807 806 RTNATIVETHREAD hNativeWriter; 808 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);807 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 809 808 AssertReturn(hNativeSelf == hNativeWriter, VERR_NOT_OWNER); 810 809 … … 824 823 */ 825 824 ASMAtomicWriteU32(&pThis->cWriteRecursions, 0); 826 ASMAtomicWriteHandle(&pThis-> hNativeWriter, NIL_RTNATIVETHREAD);827 828 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);825 ASMAtomicWriteHandle(&pThis->u.s.hNativeWriter, NIL_RTNATIVETHREAD); 826 827 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 829 828 IPRT_CRITSECTRW_EXCL_LEAVING(pThis, NULL, 0, 830 829 (uint32_t)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT), … … 845 844 u64State &= ~RTCSRW_CNT_WR_MASK; 846 845 u64State |= c << RTCSRW_CNT_WR_SHIFT; 847 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))846 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 848 847 { 849 848 if (c > 0) … … 860 859 u64State &= ~(RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); 861 860 u64State |= RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT; 862 if (ASMAtomicCmpXchgU64(&pThis->u 64State, u64State, u64OldState))861 if (ASMAtomicCmpXchgU64(&pThis->u.s.u64State, u64State, u64OldState)) 863 862 { 864 863 Assert(!pThis->fNeedReset); … … 873 872 if (pThis->u32Magic != RTCRITSECTRW_MAGIC) 874 873 return VERR_SEM_DESTROYED; 875 u64State = ASMAtomicReadU64(&pThis->u 64State);874 u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 876 875 } 877 876 } … … 888 887 if (IPRT_CRITSECTRW_EXCL_LEAVING_ENABLED()) 889 888 { 890 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);889 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 891 890 IPRT_CRITSECTRW_EXCL_LEAVING(pThis, NULL, cNestings + pThis->cWriterReads, 892 891 (uint32_t)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT), … … 919 918 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 920 919 RTNATIVETHREAD hNativeWriter; 921 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hNativeWriter);920 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hNativeWriter); 922 921 return hNativeWriter == hNativeSelf; 923 922 } … … 943 942 * Inspect the state. 944 943 */ 945 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);944 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 946 945 if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)) 947 946 { … … 952 951 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 953 952 RTNATIVETHREAD hWriter; 954 ASMAtomicUoReadHandle(&pThis-> hNativeWriter, &hWriter);953 ASMAtomicUoReadHandle(&pThis->u.s.hNativeWriter, &hWriter); 955 954 return hWriter == hNativeSelf; 956 955 } … … 1020 1019 * Return the requested data. 1021 1020 */ 1022 uint64_t u64State = ASMAtomicReadU64(&pThis->u 64State);1021 uint64_t u64State = ASMAtomicReadU64(&pThis->u.s.u64State); 1023 1022 if ((u64State & RTCSRW_DIR_MASK) != (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) 1024 1023 return 0; … … 1037 1036 //Assert(pThis->cNestings == 0); 1038 1037 //Assert(pThis->cLockers == -1); 1039 Assert(pThis-> hNativeWriter == NIL_RTNATIVETHREAD);1038 Assert(pThis->u.s.hNativeWriter == NIL_RTNATIVETHREAD); 1040 1039 #ifdef IN_RING0 1041 1040 Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0); … … 1051 1050 1052 1051 pThis->fFlags = 0; 1053 pThis->u 64State = 0;1052 pThis->u.s.u64State = 0; 1054 1053 1055 1054 RTSEMEVENT hEvtWrite = pThis->hEvtWrite;
Note:
See TracChangeset
for help on using the changeset viewer.