@@ -434,11 +434,10 @@ uint64_t Descriptor::CondCAS(uint32_t word_index, uint64_t dirty_flag) {
434
434
return ret;
435
435
}
436
436
437
- #ifdef RTM
438
437
bool Descriptor::RTMInstallDescriptors (uint64_t dirty_flag) {
439
438
uint64_t mwcas_descptr = SetFlags (this , kMwCASFlag | dirty_flag);
440
439
uint64_t tries = 0 ;
441
- static const uint64_t kMaxTries = 10000 ;
440
+ static const uint64_t kMaxTries = 10 ;
442
441
443
442
retry:
444
443
if (_XBEGIN_STARTED == _xbegin ()) {
@@ -457,7 +456,6 @@ bool Descriptor::RTMInstallDescriptors(uint64_t dirty_flag) {
457
456
}
458
457
return false ;
459
458
}
460
- #endif
461
459
462
460
#ifndef PMEM
463
461
bool Descriptor::VolatileMwCAS (uint32_t calldepth) {
@@ -644,56 +642,57 @@ bool Descriptor::PersistentMwCAS(uint32_t calldepth) {
644
642
uint64_t descptr = SetFlags (this , kMwCASFlag | kDirtyFlag );
645
643
uint32_t my_status = kStatusSucceeded ;
646
644
647
- #ifdef RTM
648
645
// Go to phase 2 directly if helping along.
649
- if (calldepth > 0 && ! RTMInstallDescriptors ( kDirtyFlag ) ) {
646
+ if (calldepth > 0 ) {
650
647
my_status = kStatusFailed ;
651
648
}
652
- #else
653
649
654
- for (uint32_t i = 0 ; i < count_ && my_status == kStatusSucceeded ; ++i) {
655
- WordDescriptor* wd = &words_[i];
656
- // Skip entries added purely for allocating memory
657
- if ((uint64_t )wd->address_ == Descriptor::kAllocNullAddress ){
658
- continue ;
659
- }
660
- retry_entry:
661
- auto rval = CondCAS (i, kDirtyFlag );
662
-
663
- // Ok if a) we succeeded to swap in a pointer to this descriptor or b) some
664
- // other thread has already done so. Need to persist all fields (which point
665
- // to descriptors) before switching to final status, so that recovery will
666
- // know reliably whether to roll forward or back for this descriptor.
667
- if (rval == wd->old_value_ || CleanPtr (rval) == (uint64_t )this ) {
668
- continue ;
669
- }
670
-
671
- if (rval & kDirtyFlag ){
672
- goto retry_entry;
673
- }
650
+ // Try RTM install first, if failed go to fallback solution.
651
+ if (!RTMInstallDescriptors (kDirtyFlag )) {
652
+ for (uint32_t i = 0 ; i < count_ && my_status == kStatusSucceeded ; ++i) {
653
+ WordDescriptor* wd = &words_[i];
654
+ // Skip entries added purely for allocating memory
655
+ if ((uint64_t )wd->address_ == Descriptor::kAllocNullAddress ) {
656
+ continue ;
657
+ }
658
+ retry_entry:
659
+ auto rval = CondCAS (i, kDirtyFlag );
660
+
661
+ // Ok if a) we succeeded to swap in a pointer to this descriptor or b)
662
+ // some other thread has already done so. Need to persist all fields
663
+ // (which point to descriptors) before switching to final status, so that
664
+ // recovery will know reliably whether to roll forward or back for this
665
+ // descriptor.
666
+ if (rval == wd->old_value_ || CleanPtr (rval) == (uint64_t )this ) {
667
+ continue ;
668
+ }
674
669
675
- // Do we need to help another MWCAS operation?
676
- if (IsMwCASDescriptorPtr (rval)) {
677
- #if PMWCAS_THREAD_HELP == 1
678
670
if (rval & kDirtyFlag ) {
679
- wd->PersistAddress ();
680
- CompareExchange64 (wd->address_ , rval & ~kDirtyFlag , rval);
671
+ goto retry_entry;
681
672
}
682
673
683
- // Clashed with another MWCAS; help complete the other MWCAS if it is
684
- // still in flight.
685
- Descriptor *otherMWCAS = (Descriptor *)CleanPtr (rval);
686
- otherMWCAS->PersistentMwCAS (calldepth + 1 );
687
- MwCASMetrics::AddHelpAttempt ();
674
+ // Do we need to help another MWCAS operation?
675
+ if (IsMwCASDescriptorPtr (rval)) {
676
+ #if PMWCAS_THREAD_HELP == 1
677
+ if (rval & kDirtyFlag ) {
678
+ wd->PersistAddress ();
679
+ CompareExchange64 (wd->address_ , rval & ~kDirtyFlag , rval);
680
+ }
681
+
682
+ // Clashed with another MWCAS; help complete the other MWCAS if it is
683
+ // still in flight.
684
+ Descriptor* otherMWCAS = (Descriptor*)CleanPtr (rval);
685
+ otherMWCAS->PersistentMwCAS (calldepth + 1 );
686
+ MwCASMetrics::AddHelpAttempt ();
688
687
#endif
689
- goto retry_entry;
690
- } else {
691
- // rval must be another value, we failed
692
- my_status = kStatusFailed ;
688
+ goto retry_entry;
689
+ } else {
690
+ // rval must be another value, we failed
691
+ my_status = kStatusFailed ;
692
+ }
693
693
}
694
- }
695
- #endif
696
694
695
+ }
697
696
// Switch to the final state, the MwCAS concludes after this point
698
697
CompareExchange32 (&status_, my_status | kStatusDirtyFlag , kStatusUndecided );
699
698
0 commit comments