Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
Smab2382 committed Dec 26, 2017
1 parent 92fbc8f commit 329840d
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions cds/container/wf_hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WfHashtable
protected:
typedef enum { DEL, VALUE, OLDV } eType;

template <typename KEY, typename T>
template <typename KEY, typename T>
struct EValue {

private:
Expand Down Expand Up @@ -73,17 +73,17 @@ class WfHashtable
return oldp() && val() == NULL;
}
};

template <typename KEY, typename T>
struct Hashtable {
int size; // size of the hashtable
int occ; // number of occupied positions in the table
int dels; // number of deleted positions
int bound; // the maximal number of places that can be occupied before refreshing the table
EValue* table;
EValue<KEY,T>* table;

Hashtable(int size, int bound){
this->size = size;
this->table = new EValue<KEY,T>[size];
this->table = new EValue<KEY,T>[size];
this->bound = bound;
this->occ = 0;
this->dels = 0;
Expand All @@ -94,15 +94,15 @@ class WfHashtable
};

int P;
std::atomic<Hashtable*>* H; // 1..2P
std::atomic<Hashtable<KEY,T>*>* H; // 1..2P
int currInd; // 1..2P = index of the currently valid hashtable
int* busy; // 1..2P = number of processes that are using a hashtable
Hashtable* next; // 1..2P = next hashtable to which the contents of hashtable H[i] is being copied
Hashtable<KEY,T>* next; // 1..2P = next hashtable to which the contents of hashtable H[i] is being copied
int* prot; // 1..2P = is used to guard the variables busy[i], next[i] and H[i]
// against being reused for a new table, before all processes have discarded these

public:
template <typename KEY, typename T>
template <typename KEY, typename T>
class WfHashtableProcess {
protected:
WfHashtable* wh;
Expand All @@ -124,7 +124,7 @@ class WfHashtable
T* find(int a) {
EValue<KEY,T> r;
int n, l, k;
Hashtable* h;
Hashtable<KEY,T>* h;

h = wh->H[index];
n = 0;
Expand All @@ -151,7 +151,7 @@ class WfHashtable
{
EValue<KEY,T> r;
int k, l, n;
Hashtable* h;
Hashtable<KEY,T> * h;
bool suc;

h = wh->H[index];
Expand Down Expand Up @@ -185,10 +185,10 @@ class WfHashtable
return suc;
}

bool insert(int a, T* v) {
EValue<KEY,T> r;
bool insert(int a, EValue<KEY,T> v) {
EValue<KEY,T> r;
int k,l,n;
Hashtable* h;
Hashtable<KEY,T> * h;
bool suc;
h = wh->H[index];
if (h->occ > h->bound) {
Expand All @@ -198,15 +198,15 @@ class WfHashtable
n=0; l=h->size; suc=false;
do{
k=key(a,l,n);
std::atomic_store_explicit(&r, h->table[k]);//atomic
std::atomic_store_explicit(&r, h->table[k]);//atomic
if (r.oldp()){
refresh();
h = wh->H[index];
n = 0; l = h->size;
}else {
if(r.val() == NULL){
Hashtable* null_ptr = NULL;
if(std::atomic_compare_exchange_strong(&h->table[k] , null_ptr, v))//atmic
Hashtable<KEY,T>* null_ptr = NULL;
if(std::atomic_compare_exchange_strong(h->table[k] , null_ptr, v))//atmic
{
suc=true;
}
Expand All @@ -225,7 +225,7 @@ class WfHashtable
void assign(int a, T* v) {
EValue<KEY,T> r;
int k,l,n;
Hashtable* h;
Hashtable<KEY,T>* h;
bool suc;

h = wh->H[index];
Expand Down Expand Up @@ -282,11 +282,11 @@ class WfHashtable
}

void releaseAccess(int i) {
Hashtable* h;
Hashtable<KEY,T>* h;
h = wh->H[i];
wh->busy[i]--;
if (h != NULL && wh->busy[i] == 0) {
Hashtable* null_ptr = NULL;
Hashtable<KEY,T>* null_ptr = NULL;
if (std::atomic_compare_exchange_strong(&wh->H[i], &h, null_ptr)) {
deAlloc(i);
}
Expand All @@ -302,15 +302,16 @@ class WfHashtable
// ----------- HEAP methods -----------

void allocate(int i, int s, int b) {
Hashtable* tmp = new Hashtable(s, b)
Hashtable<KEY,T>* tmp = new Hashtable<KEY,T>(s, b);
std::atomic_exchange(&wh->H[i], tmp);
if (wh->H[i] != tmp) delete tmp;
}

void deAlloc(int h) {
Hashtable* tmp = wh->H[h];
Hashtable<KEY,T>* tmp = wh->H[h];
if (tmp != NULL) {
atomic_exchange(&wh->H[h], NULL);
Hashtable<KEY,T>* null_ptr = NULL;
std::atomic_exchange(&wh->H[h], null_ptr);
if (tmp != NULL) {
delete tmp;
}
Expand All @@ -320,10 +321,11 @@ class WfHashtable
void newTable() {
int i; // 1..2P
bool b, bb;int temp =0;
while(next[index] == 0){
Hashtable<KEY,T> *t_next=next[index];
while(t_next == 0){
i = rand() % (2*wh->P) + 1;

if(atomic_compare_exchange_strong(&prot[i] , &temp, 0)){// ATOMIC
if(std::atomic_compare_exchange_strong(&prot[i] , &temp, 0)){// ATOMIC
busy[i] = 1;
int bound = wh->H[index].bound - wh->H[index].dels + 2*P + 1;
int size = bound + 2*P + 1;
Expand All @@ -338,7 +340,7 @@ class WfHashtable

void migrate() {
int i; // 0..2P
Hashtable* h;
Hashtable<KEY,T>* h;
bool b;
i = next[index];
prot[i]++;
Expand Down Expand Up @@ -369,7 +371,7 @@ class WfHashtable
}
}

void moveContents(Hashtable* from, Hashtable* to) {
void moveContents(Hashtable<KEY,T>* from, Hashtable<KEY,T>* to) {
int i;
bool b;
EValue<KEY,T> v;
Expand All @@ -396,7 +398,7 @@ class WfHashtable
}
}

void moveElement(T* v, Hashtable* to)
void moveElement(T* v, Hashtable<KEY,T>* to)
{
int a;
int k, m, n;
Expand Down Expand Up @@ -429,7 +431,7 @@ class WfHashtable

WfHashtable(int P) {
this->P = P;
this->H = new std::atomic<Hashtable*>[2 * P];
this->H = new std::atomic<Hashtable<KEY,T>*>[2 * P];
this->busy = new int[2 * P];
this->prot = new int[2 * P];
};
Expand Down

0 comments on commit 329840d

Please sign in to comment.