NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
types.c
Go to the documentation of this file.
1 #include "types.h"
2 #include "hashmap_tx.h"
3 #include <libpmemobj.h>
4 #include <errno.h>
5 
6 // The pool that would contain this HashTable
7 PMEMobjpool *pop;
8 
9 
10 // The stored HashTable
11 TOID(struct hashmap_tx) hashmap;
12 
13 void init_types_table() {
14  char filename[50];
15  strcpy(filename, program_invocation_short_name);
16  strcat(filename, "_types_table");
17  pop = pmemobj_open(filename, POBJ_LAYOUT_NAME(types_tab));
18 
19  if(pop == NULL) {
20  pop = pmemobj_create(filename, POBJ_LAYOUT_NAME(types_tab), 5*PMEMOBJ_MIN_POOL, 0666);
21  //printf("%d %s %p\n", errno, filename, pop);
22  hashmap = POBJ_ROOT(pop, struct hashmap_tx);
23 
24  struct hashmap_args *args = (struct hashmap_args *) malloc(sizeof(struct hashmap_args));
25  args->seed = 8274; // Just a random number
26  #ifdef DEBUG
27  printf("hmap create result = %d\n",hm_tx_create(pop, &hashmap, (void *)args));
28  #else
29  hm_tx_create(pop, &hashmap, (void *)args);
30  #endif
31  } else {
32  //printf("%second d %s %p\n", errno, filename, pop);
33  hashmap = POBJ_ROOT(pop, struct hashmap_tx);
34  #ifdef DEBUG
35  printf("map address %p\n", (hashmap).oid.off);
36  #endif
37  hm_tx_init(pop, hashmap);
38  }
39 }
40 
41 // void* _key_get_first(MEMoidKey key) {
42 // MEMoid m = get_MEMoid(key);
43 // if (m != MEMOID_NULL) {
44 // return MEMOID_FIRST(m);
45 // }
46 // return NULL;
47 // }
48 
49 // void* _key_get_last(MEMoidKey key) {
50 // MEMoid m = get_MEMoid(key);
51 // if (m != MEMOID_NULL) {
52 // return MEMOID_FIRST(m) + m.size;
53 // }
54 // return NULL;
55 // }
56 
65  MEMoid m = hm_tx_get(pop, hashmap, (uint64_t) key);
66  //printf("memoid poolid = %d, offset = %ld, size = %ld\n", m.pool_id, m.offset, m.size);
67  return m;
68 }
69 
71  hm_tx_insert(pop, hashmap, (uint64_t)key, oid);
72 }
73 
75  hm_tx_remove(pop, hashmap, (uint64_t)key);
76 }
77 
78 TOID(struct hashmap_tx)* get_types_map(){
79  return &hashmap;
80 }
81 
83  hm_tx_debug(pop, hashmap, stderr);
84 }
debug_hashmap
void debug_hashmap(MEMoidKey key)
Definition: types.c:82
hashmap_tx
Definition: hashmap_tx.h:48
types.h
insert_object_to_hashmap
void insert_object_to_hashmap(MEMoidKey key, MEMoid oid)
Definition: types.c:70
hashmap_args
Definition: hashmap_tx.h:9
pop
PMEMobjpool * pop
Definition: types.c:7
MEMoid_st
The struct that stores the memptr for the object.
Definition: malloc.h:29
MEMoidKey
uint64_t MEMoidKey
The key of the HashTable that contains <MEMoidKey, MEMoid>.
Definition: malloc.h:49
init_types_table
void init_types_table()
hm_tx_remove
MEMoid hm_tx_remove(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key)
Removes specified value from the hashmap.
Definition: hashmap_tx.c:224
remove_object_from_hashmap
void remove_object_from_hashmap(MEMoidKey key)
Definition: types.c:74
hm_tx_create
int hm_tx_create(PMEMobjpool *pop, TOID(struct hashmap_tx) *map, void *arg)
Allocates a new hashmap.
Definition: hashmap_tx.c:433
uint64_t
__uint64_t uint64_t
Definition: globals.h:51
TOID
TOID(struct hashmap_tx)
Definition: types.c:11
hm_tx_init
int hm_tx_init(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
Recovers hashmap state.
Definition: hashmap_tx.c:415
NULL
#define NULL
Definition: list.h:13
hm_tx_insert
int hm_tx_insert(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key, MEMoid value)
Inserts the specified value into the hashmap.
Definition: hashmap_tx.c:164
hashmap_args::seed
uint32_t seed
Definition: hashmap_tx.h:10
hm_tx_debug
void hm_tx_debug(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, FILE *out)
Prints complete hashmap state.
Definition: hashmap_tx.c:314
get_MEMoid
MEMoid get_MEMoid(MEMoidKey key)
The function to obtain the MEMoid object given the MEMoidKey
Definition: types.c:64
hm_tx_get
MEMoid hm_tx_get(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key)
Checks whether specified key is in the hashmap and retries the value associated with it.
Definition: hashmap_tx.c:349
program_invocation_short_name
char * program_invocation_short_name
The predefined pools.
hashmap_tx.h