bug fixes in altmlookup
authoradash <adash>
Wed, 2 Dec 2009 17:48:25 +0000 (17:48 +0000)
committeradash <adash>
Wed, 2 Dec 2009 17:48:25 +0000 (17:48 +0000)
Robust/src/Runtime/DSTM/interface/altmlookup.c
Robust/src/Runtime/DSTM/interface/altmlookup.h

index e321e7006de037fcd8f350bea531680317da9b60..88768dde0ed6fac8ce5ebd6a7509ffdef014d94c 100644 (file)
@@ -1,4 +1,4 @@
-#include "mlookup.h"
+#include "altmlookup.h"
 #include "dsmlock.h"
 #include <sched.h>
 
@@ -21,7 +21,7 @@ unsigned int mhashCreate(unsigned int size, double loadfactor) {
   mlookup.loadfactor = loadfactor;
   int i;
   for(i=0;i<NUMLOCKS;i++)
-    mlookup.lockarray[i]=RW_LOCK_BIAS;
+    mlookup.larray[i].lock=RW_LOCK_BIAS;
   //Initialize the pthread_mutex variable
   return 0;
 }
@@ -42,7 +42,7 @@ void mhashInsert(unsigned int key, void *val) {
   }
 
   unsigned int keyindex=(key&mlookup.mask)>>1;
-  volatile unsigned int * lockptr=&mlookup.lockarray[keyindex&LOCKMASK].lock;
+  volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
   while(!write_trylock(lockptr)) {
     sched_yield();
   }
@@ -68,7 +68,7 @@ void *mhashSearch(unsigned int key) {
   int index;
 
   unsigned int keyindex=(key&mlookup.mask)>>1;
-  volatile unsigned int * lockptr=&mlookup.lockarray[keyindex&LOCKMASK].lock;
+  volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
 
   while(!write_trylock(lockptr)) {
     sched_yield();
@@ -95,7 +95,7 @@ unsigned int mhashRemove(unsigned int key) {
   mhashlistnode_t *ptr, *node;
 
   unsigned int keyindex=(key&mlookup.mask)>>1;
-  volatile unsigned int * lockptr=&mlookup.lockarray[keyindex&LOCKMASK].lock;
+  volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
 
   while(!write_trylock(lockptr)) {
     sched_yield();
@@ -105,7 +105,7 @@ unsigned int mhashRemove(unsigned int key) {
 
   for (; curr != NULL; curr = curr->next) {
     if (curr->key == key) {
-      atomic_dec(&mlookup.numelements);
+      atomic_dec(&(mlookup.numelements));
       if ((curr == &ptr[index]) && (curr->next == NULL)) {
        curr->key = 0;
        curr->val = NULL;
@@ -129,14 +129,14 @@ unsigned int mhashRemove(unsigned int key) {
 }
 
 // Resize table
-void int mhashResize(unsigned int newsize) {
+void mhashResize(unsigned int newsize) {
   mhashlistnode_t *node, *curr;
   int isfirst;
   unsigned int i,index;
   unsigned int mask;
 
   for(i=0;i<NUMLOCKS;i++) {
-    volatile unsigned int * lockptr=&mlookup.lockarray[i].lock;
+    volatile unsigned int * lockptr=&mlookup.larray[i].lock;
     
     while(!write_trylock(lockptr)) {
       sched_yield();
@@ -146,7 +146,7 @@ void int mhashResize(unsigned int newsize) {
   if (mlookup.numelements < mlookup.threshold) {
     //release lock and return
     for(i=0;i<NUMLOCKS;i++) {
-      volatile unsigned int * lockptr=&mlookup.lockarray[i].lock;
+      volatile unsigned int * lockptr=&mlookup.larray[i].lock;
       write_unlock(lockptr);
     }
     return;
@@ -206,7 +206,7 @@ else if (isfirst) {
 
   free(ptr);
   for(i=0;i<NUMLOCKS;i++) {
-    volatile unsigned int * lockptr=&mlookup.lockarray[i].lock;
+    volatile unsigned int * lockptr=&mlookup.larray[i].lock;
     write_unlock(lockptr);
   }
   return;
index 49a31da92330062f3c55afdc01d7ceadb58d5f85..ca5ff1ec67088437aad1cc1aec04ff8b574e70bf 100644 (file)
@@ -17,7 +17,7 @@ typedef struct mhashlistnode {
 struct lockarray {
   volatile unsigned int lock;
   int buf[15];
-}
+};
 
 #define NUMLOCKS 16
 #define LOCKMASK (NUMLOCKS-1)
@@ -29,7 +29,7 @@ typedef struct mhashtable {
   unsigned int numelements;
   unsigned int threshold;
   double loadfactor;
-  struct lockarray[NUMLOCKS];
+  struct lockarray larray[NUMLOCKS];
 } mhashtable_t;
 
 unsigned int mhashCreate(unsigned int size, double loadfactor);
@@ -37,7 +37,7 @@ unsigned int mhashFunction(unsigned int key);
 void mhashInsert(unsigned int key, void *val);
 void *mhashSearch(unsigned int key); //returns val, NULL if not found
 unsigned int mhashRemove(unsigned int key); //returns -1 if not found
-unsigned int mhashResize(unsigned int newsize);
+void mhashResize(unsigned int newsize);
 //unsigned int *mhashGetKeys(unsigned int *numKeys);
 void mhashPrint();