]> pd.if.org Git - nbds/blobdiff - map/list.c
work in progress
[nbds] / map / list.c
index bc191cd7ef79290f9b7c230e7320101e7b335236..04bfd2d02f23c3fae4808665b4d4cd377e22d777 100644 (file)
@@ -118,7 +118,7 @@ static int find_pred (node_t **pred_ptr, node_t **item_ptr, list_t *ll, map_key_
             // Unlink logically removed items.
             TRACE("l3", "find_pred: unlinking marked item %p next is %p", item, next);
 
-            markable_t other = SYNC_CAS(&pred->next, item, STRIP_MARK(next));
+            markable_t other = SYNC_CAS(&pred->next, (markable_t)item, (markable_t)STRIP_MARK(next));
             if (other == (markable_t)item) {
                 TRACE("l2", "find_pred: unlinked item %p from pred %p", item, pred);
                 item = STRIP_MARK(next);
@@ -230,7 +230,7 @@ map_val_t ll_cas (list_t *ll, map_key_t key, map_val_t expectation, map_val_t ne
             map_key_t new_key = ll->key_type == NULL ? key : (map_key_t)ll->key_type->clone((void *)key);
             node_t *new_item = node_alloc(new_key, new_val);
             markable_t next = new_item->next = (markable_t)old_item;
-            markable_t other = SYNC_CAS(&pred->next, next, new_item);
+            markable_t other = SYNC_CAS(&pred->next, (markable_t)next, (markable_t)new_item);
             if (other == next) {
                 TRACE("l1", "ll_cas: successfully inserted new item %p", new_item, 0);
                 return DOES_NOT_EXIST; // success
@@ -298,7 +298,7 @@ map_val_t ll_remove (list_t *ll, map_key_t key) {
         }
     } while (next != old_next);
     TRACE("l2", "ll_remove: logically removed item %p", item, 0);
-    ASSERT(HAS_MARK(((volatile node_t *)item)->next));
+    ASSERT(HAS_MARK(VOLATILE_DEREF(item).next));
 
     // Atomically swap out the item's value in case another thread is updating the item while we are 
     // removing it. This establishes which operation occurs first logically, the update or the remove. 
@@ -310,7 +310,7 @@ map_val_t ll_remove (list_t *ll, map_key_t key) {
     // item earlier, we logically removed it. 
     TRACE("l2", "ll_remove: unlink the item by linking its pred %p to its successor %p", pred, next);
     markable_t other;
-    if ((other = SYNC_CAS(&pred->next, item, next)) != (markable_t)item) {
+    if ((other = SYNC_CAS(&pred->next, (markable_t)item, next)) != (markable_t)item) {
         TRACE("l1", "ll_remove: unlink failed; pred's link changed from %p to %p", item, other);
         return val;
     } 
@@ -329,22 +329,25 @@ map_val_t ll_remove (list_t *ll, map_key_t key) {
     return val;
 }
 
-void ll_print (list_t *ll) {
-    markable_t next = ll->head->next;
-    int i = 0;
-    while (next != DOES_NOT_EXIST) {
-        node_t *item = STRIP_MARK(next);
-        if (item == NULL)
-            break;
-        printf("%s%p:0x%llx ", HAS_MARK(item->next) ? "*" : "", item, (uint64_t)item->key);
-        fflush(stdout);
-        if (i++ > 30) {
-            printf("...");
-            break;
+void ll_print (list_t *ll, int verbose) {
+    if (verbose) {
+        markable_t next = ll->head->next;
+        int i = 0;
+        while (next != DOES_NOT_EXIST) {
+            node_t *item = STRIP_MARK(next);
+            if (item == NULL)
+                break;
+            printf("%s%p:0x%llx ", HAS_MARK(item->next) ? "*" : "", item, (uint64_t)item->key);
+            fflush(stdout);
+            if (i++ > 30) {
+                printf("...");
+                break;
+            }
+            next = item->next;
         }
-        next = item->next;
+        printf("\n");
     }
-    printf("\n");
+    printf("count:%llu\n", (uint64_t)ll_count(ll));
 }
 
 ll_iter_t *ll_iter_begin (list_t *ll, map_key_t key) {
@@ -377,7 +380,7 @@ map_val_t ll_iter_next (ll_iter_t *iter, map_key_t *key_ptr) {
         do {
             item = iter->pred->next;
             haz_set(hp0, STRIP_MARK(item));
-        } while (item != ((volatile node_t *)iter->pred)->next);
+        } while (item != VOLATILE_DEREF(iter->pred).next);
 #endif//LIST_USE_HAZARD_POINTER
         iter->pred = STRIP_MARK(item);
         if (iter->pred == NULL)