Check that Redirect is not passed to exchange()
[junction.git] / junction / ConcurrentMap_LeapFrog.h
index 8b6c0f3e9fb0f608184417b4e6864aa187458340..f6b1e6c0c24fd5f7d5d6a53542f10f899c2d9411 100644 (file)
@@ -96,7 +96,6 @@ public:
             : m_map(map), m_table(map.m_root.load(turf::Consume)), m_value(Value(ValueTraits::NullValue)) {
             TURF_TRACE(ConcurrentMap_LeapFrog, 2, "[Mutator] insert constructor called", uptr(m_table), uptr(key));
             Hash hash = KeyTraits::hash(key);
-            bool mustDouble = false;
             for (;;) {
                 m_table = m_map.m_root.load(turf::Consume);
                 ureg overflowIdx;
@@ -116,14 +115,12 @@ public:
                     return; // Found an existing value
                 }
                 case Details::InsertResult_Overflow: {
-                    Details::beginTableMigration(m_map, m_table, overflowIdx, mustDouble);
+                    Details::beginTableMigration(m_map, m_table, overflowIdx);
                     break;
                 }
                 }
                 // A migration has been started (either by us, or another thread). Participate until it's complete.
                 m_table->jobCoordinator.participate();
-                // If we still overflow after this, avoid an infinite loop by forcing the next table to double.
-                mustDouble = true;
                 // Try again using the latest root.
             }
         }
@@ -136,9 +133,9 @@ public:
 
         Value exchangeValue(Value desired) {
             TURF_ASSERT(desired != Value(ValueTraits::NullValue));
+            TURF_ASSERT(desired != Value(ValueTraits::Redirect));
             TURF_ASSERT(m_cell); // Cell must have been found or inserted
             TURF_TRACE(ConcurrentMap_LeapFrog, 4, "[Mutator::exchangeValue] called", uptr(m_table), uptr(m_value));
-            bool mustDouble = false;
             for (;;) {
                 Value oldValue = m_value;
                 if (m_cell->value.compareExchangeStrong(m_value, desired, turf::ConsumeRelease)) {
@@ -185,14 +182,12 @@ public:
                     case Details::InsertResult_Overflow:
                         TURF_TRACE(ConcurrentMap_LeapFrog, 10, "[Mutator::exchangeValue] overflow after redirect", uptr(m_table),
                                    overflowIdx);
-                        Details::beginTableMigration(m_map, m_table, overflowIdx, mustDouble);
+                        Details::beginTableMigration(m_map, m_table, overflowIdx);
                         break;
                     }
                     // We were redirected... again
                 }
             breakOuter:;
-                // If we still overflow after this, avoid an infinite loop by forcing the next table to double.
-                mustDouble = true;
                 // Try again in the new table.
             }
         }