-#include "mlookup.h"
+#include "altmlookup.h"
#include "dsmlock.h"
#include <sched.h>
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;
}
}
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();
}
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();
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();
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;
}
// 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();
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;
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;
struct lockarray {
volatile unsigned int lock;
int buf[15];
-}
+};
#define NUMLOCKS 16
#define LOCKMASK (NUMLOCKS-1)
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);
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();