Skip to content

Commit

Permalink
bug fix and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarp authored and jschmieg committed Feb 9, 2018
1 parent 424c24e commit 4e622e7
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void pmemKVpairSet(void *key, void *val)

kv_PM_oid = sdsPMEMoidBackReference((sds)key);
kv_PM_p = (struct key_val_pair_PM *)pmemobj_direct(*kv_PM_oid);
TX_ADD_DIRECT(kv_PM_p);

val_oid.pool_uuid_lo = server.pool_uuid_lo;
val_oid.off = (uint64_t)val - (uint64_t)server.pm_pool->addr;

TX_ADD_FIELD_DIRECT(kv_PM_p, val_oid);
kv_PM_p->val_oid = val_oid;
return;
}
Expand All @@ -97,16 +97,17 @@ pmemAddToPmemList(void *key, void *val)
kv_PM_p->val_oid = val_oid;
typed_kv_PM.oid = kv_PM;

pmemobj_tx_add_range(server.pm_rootoid.oid, 0, sizeof(struct redis_pmem_root));
root = pmemobj_direct(server.pm_rootoid.oid);

kv_PM_p->pmem_list_next = root->pe_first;
if(!TOID_IS_NULL(root->pe_first)) {
TX_ADD(D_RW(root->pe_first)->pmem_list_prev);
D_RW(root->pe_first)->pmem_list_prev = typed_kv_PM;
struct key_val_pair_PM *head = D_RW(root->pe_first);
TX_ADD_FIELD_DIRECT(head,pmem_list_prev);
head->pmem_list_prev = typed_kv_PM;
}
root->pe_first = typed_kv_PM;

TX_ADD_DIRECT(root);
root->pe_first = typed_kv_PM;
root->num_dict_entries++;

return kv_PM;
Expand All @@ -118,35 +119,40 @@ pmemRemoveFromPmemList(PMEMoid kv_PM_oid)
TOID(struct key_val_pair_PM) typed_kv_PM;
struct redis_pmem_root *root;

pmemobj_tx_add_range(server.pm_rootoid.oid, 0, sizeof(struct redis_pmem_root));
root = pmemobj_direct(server.pm_rootoid.oid);

typed_kv_PM.oid = kv_PM_oid;

if(TOID_EQUALS(root->pe_first, typed_kv_PM)) {
TOID(struct key_val_pair_PM) typed_kv_PM_next = D_RO(typed_kv_PM)->pmem_list_next;
if(!TOID_IS_NULL(typed_kv_PM_next)){
TX_ADD(typed_kv_PM_next);
D_RW(typed_kv_PM_next)->pmem_list_prev.oid = OID_NULL;
struct key_val_pair_PM *next = D_RW(typed_kv_PM_next);
TX_ADD_FIELD_DIRECT(next,pmem_list_prev);
next->pmem_list_prev.oid = OID_NULL;
}
TX_FREE(root->pe_first);
TX_ADD_DIRECT(root);
root->pe_first = typed_kv_PM_next;
root->num_dict_entries--;
return;
}
else {
TOID(struct key_val_pair_PM) typed_kv_PM_prev = D_RO(typed_kv_PM)->pmem_list_prev;
TOID(struct key_val_pair_PM) typed_kv_PM_next = D_RO(typed_kv_PM)->pmem_list_next;
if(!TOID_IS_NULL(typed_kv_PM_prev)){
TX_ADD(typed_kv_PM_prev);
D_RW(typed_kv_PM_prev)->pmem_list_next = typed_kv_PM_next;
struct key_val_pair_PM *prev = D_RW(typed_kv_PM_prev);
TX_ADD_FIELD_DIRECT(prev,pmem_list_next);
prev->pmem_list_next = typed_kv_PM_next;
}
if(!TOID_IS_NULL(typed_kv_PM_next)){
TX_ADD(typed_kv_PM_next);
D_RW(typed_kv_PM_next)->pmem_list_prev = typed_kv_PM_prev;
struct key_val_pair_PM *next = D_RW(typed_kv_PM_next);
TX_ADD_FIELD_DIRECT(next,pmem_list_prev);
next->pmem_list_prev = typed_kv_PM_prev;
}
TX_FREE(typed_kv_PM);
TX_ADD_FIELD_DIRECT(root,num_dict_entries);
root->num_dict_entries--;
return;
}

root->num_dict_entries--;
return;
}
#endif

0 comments on commit 4e622e7

Please sign in to comment.