From 329840da8d88c5de99c5678714c34461afbb8799 Mon Sep 17 00:00:00 2001 From: Smab2382 Date: Tue, 26 Dec 2017 23:35:11 +0300 Subject: [PATCH] fix error --- cds/container/wf_hashtable.h | 56 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/cds/container/wf_hashtable.h b/cds/container/wf_hashtable.h index 461f8af60..37f9bb696 100644 --- a/cds/container/wf_hashtable.h +++ b/cds/container/wf_hashtable.h @@ -19,7 +19,7 @@ class WfHashtable protected: typedef enum { DEL, VALUE, OLDV } eType; - template + template struct EValue { private: @@ -73,17 +73,17 @@ class WfHashtable return oldp() && val() == NULL; } }; - +template 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* table; Hashtable(int size, int bound){ this->size = size; - this->table = new EValue[size]; + this->table = new EValue[size]; this->bound = bound; this->occ = 0; this->dels = 0; @@ -94,15 +94,15 @@ class WfHashtable }; int P; - std::atomic* H; // 1..2P + std::atomic*>* 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* 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 + template class WfHashtableProcess { protected: WfHashtable* wh; @@ -124,7 +124,7 @@ class WfHashtable T* find(int a) { EValue r; int n, l, k; - Hashtable* h; + Hashtable* h; h = wh->H[index]; n = 0; @@ -151,7 +151,7 @@ class WfHashtable { EValue r; int k, l, n; - Hashtable* h; + Hashtable * h; bool suc; h = wh->H[index]; @@ -185,10 +185,10 @@ class WfHashtable return suc; } - bool insert(int a, T* v) { - EValue r; + bool insert(int a, EValue v) { + EValue r; int k,l,n; - Hashtable* h; + Hashtable * h; bool suc; h = wh->H[index]; if (h->occ > h->bound) { @@ -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* null_ptr = NULL; + if(std::atomic_compare_exchange_strong(h->table[k] , null_ptr, v))//atmic { suc=true; } @@ -225,7 +225,7 @@ class WfHashtable void assign(int a, T* v) { EValue r; int k,l,n; - Hashtable* h; + Hashtable* h; bool suc; h = wh->H[index]; @@ -282,11 +282,11 @@ class WfHashtable } void releaseAccess(int i) { - Hashtable* h; + Hashtable* h; h = wh->H[i]; wh->busy[i]--; if (h != NULL && wh->busy[i] == 0) { - Hashtable* null_ptr = NULL; + Hashtable* null_ptr = NULL; if (std::atomic_compare_exchange_strong(&wh->H[i], &h, null_ptr)) { deAlloc(i); } @@ -302,15 +302,16 @@ class WfHashtable // ----------- HEAP methods ----------- void allocate(int i, int s, int b) { - Hashtable* tmp = new Hashtable(s, b) + Hashtable* tmp = new Hashtable(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* tmp = wh->H[h]; if (tmp != NULL) { - atomic_exchange(&wh->H[h], NULL); + Hashtable* null_ptr = NULL; + std::atomic_exchange(&wh->H[h], null_ptr); if (tmp != NULL) { delete tmp; } @@ -320,10 +321,11 @@ class WfHashtable void newTable() { int i; // 1..2P bool b, bb;int temp =0; - while(next[index] == 0){ + Hashtable *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; @@ -338,7 +340,7 @@ class WfHashtable void migrate() { int i; // 0..2P - Hashtable* h; + Hashtable* h; bool b; i = next[index]; prot[i]++; @@ -369,7 +371,7 @@ class WfHashtable } } - void moveContents(Hashtable* from, Hashtable* to) { + void moveContents(Hashtable* from, Hashtable* to) { int i; bool b; EValue v; @@ -396,7 +398,7 @@ class WfHashtable } } - void moveElement(T* v, Hashtable* to) + void moveElement(T* v, Hashtable* to) { int a; int k, m, n; @@ -429,7 +431,7 @@ class WfHashtable WfHashtable(int P) { this->P = P; - this->H = new std::atomic[2 * P]; + this->H = new std::atomic*>[2 * P]; this->busy = new int[2 * P]; this->prot = new int[2 * P]; };