int main(int argc, char *argv[]) { if (argc < 3 || argc > 4) { printf("usage: %s hashmap_tx|hashmap_atomic|ctree|btree|rbtree" " file-name [<seed>]\n", argv[0]); return 1; } const struct map_ops *ops = NULL; const char *path = argv[2]; const char *type = argv[1]; if (strcmp(type, "hashmap_tx") == 0) { ops = MAP_HASHMAP_TX; } else if (strcmp(type, "hashmap_atomic") == 0) { ops = MAP_HASHMAP_ATOMIC; } else if (strcmp(type, "ctree") == 0) { ops = MAP_CTREE; } else if (strcmp(type, "btree") == 0) { ops = MAP_BTREE; } else if (strcmp(type, "rbtree") == 0) { ops = MAP_RBTREE; } else { fprintf(stderr, "invalid hasmap type -- '%s'\n", type); return 1; } if (access(path, F_OK) != 0) { pop = pmemobj_create(path, POBJ_LAYOUT_NAME(map), PM_HASHSET_POOL_SIZE, S_IRUSR | S_IWUSR); if (pop == NULL) { fprintf(stderr, "failed to create pool: %s\n", pmemobj_errormsg()); return 1; } struct hashmap_args args; if (argc > 3) args.seed = atoi(argv[3]); else args.seed = time(NULL); srand(args.seed); mapc = map_ctx_init(ops, pop); if (!mapc) { pmemobj_close(pop); perror("map_ctx_init"); return 1; } root = POBJ_ROOT(pop, struct root); printf("seed: %u\n", args.seed); map_new(mapc, &D_RW(root)->map, &args); map = D_RO(root)->map; } else {
static void restore_set_cache_range(PMEMoid cache) { struct tx_range_cache *c = D_RW(cache); struct tx_range *range = NULL; for (int i = 0; i < MAX_CACHED_RANGES; ++i) { range = (struct tx_range *)&c->range[i]; if (range->offset == 0 || range->size == 0) break; restore_range(range); } }
static void restore_set_range(PMEMoid set) { restore_range(D_RW(set)); }
TOID(struct obj) head; }; struct obj { int data; PMEMmutex lock; TOID(struct obj) next; }; /* * do_nested_tx-- (internal) nested transaction */ static void do_nested_tx(PMEMobjpool *pop, TOID(struct obj) o, int value) { TX_BEGIN_LOCK(pop, TX_LOCK_MUTEX, &D_RW(o)->lock, TX_LOCK_NONE) { TX_ADD(o); D_RW(o)->data = value; if (!TOID_IS_NULL(D_RO(o)->next)) { /* * Add the object to undo log, while the mutex * it contains is not locked. */ TX_ADD(D_RO(o)->next); do_nested_tx(pop, D_RO(o)->next, value); } } TX_END; } /* * do_aborted_nested_tx -- (internal) aborted nested transaction