Check that Redirect is not passed to exchange()
[junction.git] / junction / ConcurrentMap_Grampa.h
index 5f03c8b3d83c4010ead8c4802a8d98cf83c51b11..27e18ff3a5b4f1297f4f6b53835f8d3ce72a00cd 100644 (file)
@@ -23,7 +23,7 @@ namespace junction {
 
 TURF_TRACE_DECLARE(ConcurrentMap_Grampa, 27)
 
-template <typename K, typename V, class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
+template <typename K, typename V, class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V> >
 class ConcurrentMap_Grampa {
 public:
     typedef K Key;
@@ -41,7 +41,7 @@ private:
         if (root & 1) {
             typename Details::FlatTree* flatTree = (typename Details::FlatTree*) (root & ~ureg(1));
             for (;;) {
-                ureg leafIdx = (hash >> flatTree->safeShift);
+                ureg leafIdx = ureg(hash >> flatTree->safeShift);
                 table = flatTree->getTables()[leafIdx].load(turf::Relaxed);
                 if (ureg(table) != Details::RedirectFlatTree) {
                     sizeMask = (Details::LeafSize - 1);
@@ -189,7 +189,7 @@ public:
                         // Retry the loop.
                     } else {
                         ureg repeat = ureg(1) << (migration->m_safeShift - flatTree->safeShift);
-                        ureg dstStartIndex = migration->m_baseHash >> flatTree->safeShift;
+                        ureg dstStartIndex = ureg(migration->m_baseHash >> flatTree->safeShift);
                         // The subtree we're about to publish fits inside the flattree.
                         TURF_ASSERT(dstStartIndex + migration->m_numDestinations * repeat - 1 <= Hash(-1) >> flatTree->safeShift);
                         // If a previous attempt to publish got redirected, resume publishing into the new flattree,
@@ -335,6 +335,7 @@ 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_Grampa, 14, "[Mutator::exchangeValue] called", uptr(m_table), uptr(m_value));
             for (;;) {