X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=map%2Flist.c;h=ac6b6a570feebffd751b5795e588b3903269747b;hp=f7a9cd43cbaa2da9049be46bc791d11f81e92cda;hb=9d72edf41ce3a2ddbbe2d44afc23ef5ec53339c3;hpb=11572afcaf218cfcbb8e9747f22739f75252c4f4 diff --git a/map/list.c b/map/list.c index f7a9cd4..ac6b6a5 100644 --- a/map/list.c +++ b/map/list.c @@ -10,7 +10,7 @@ #include #include "common.h" -#include "mlocal.h" +#include "list.h" #include "mem.h" typedef struct node { @@ -24,13 +24,6 @@ struct ll { const datatype_t *key_type; }; -static const map_impl_t ll_map_impl = { - (map_alloc_t)ll_alloc, (map_cas_t)ll_cas, (map_get_t)ll_lookup, (map_remove_t)ll_remove, - (map_count_t)ll_count, (map_print_t)ll_print, (map_free_t)ll_free -}; - -const map_impl_t *MAP_TYPE_LIST = &ll_map_impl; - static node_t *node_alloc (void *key, uint64_t val) { node_t *item = (node_t *)nbd_malloc(sizeof(node_t)); item->key = key; @@ -252,8 +245,7 @@ uint64_t ll_remove (list_t *ll, void *key) { return DOES_NOT_EXIST; } - // Mark removed. This must be atomic. If multiple threads try to remove the same item - // only one of them should succeed. + // Mark removed. If multiple threads try to remove the same item only one of them should succeed. node_t *next; node_t *old_next = item->next; do { @@ -267,7 +259,8 @@ uint64_t ll_remove (list_t *ll, void *key) { TRACE("l2", "ll_remove: logically removed item %p", item, 0); ASSERT(IS_TAGGED(item->next)); - // This has to be an atomic swap in case another thread is updating the item while we are removing it. + // 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. uint64_t val = SYNC_SWAP(&item->val, DOES_NOT_EXIST); TRACE("l2", "ll_remove: replaced item's val %p with DOES_NOT_EXIT", val, 0);