#include "garbage.h"
/* Thread transaction variables */
__thread objstr_t *t_cache;
+__thread objstr_t *t_reserve;
__thread struct objlist * newobjs;
#ifdef TRANSSTATS
return tmp;
}
+void objstrReset() {
+ while(t_cache->next!=NULL) {
+ objstr_t *next=t_cache->next;
+ t_cache->next=t_reserve;
+ t_reserve=t_cache;
+ t_cache=next;
+ }
+ t_cache->top=t_cache+1;
+}
+
//free entire list, starting at store
void objstrDelete(objstr_t *store) {
objstr_t *tmp;
* =================================================
*/
void transStart() {
- t_cache = objstrCreate(1048576);
- t_chashCreate(CHASH_SIZE, CLOADFACTOR);
+ //Transaction start is currently free...commit and aborting is not
}
/* =======================================================
* - allocate space in an object store
* ==============================================
*/
-void *objstrAlloc(objstr_t **osptr, unsigned int size) {
+void *objstrAlloc(unsigned int size) {
void *tmp;
int i=0;
- objstr_t *store=*osptr;
+ objstr_t *store=t_cache;
if ((size&7)!=0) {
size+=(8-(size&7));
}
- for(;i<3;i++) {
+ for(;i<2;i++) {
if (OSFREE(store)>=size) {
tmp=store->top;
store->top +=size;
{
unsigned int newsize=size>DEFAULT_OBJ_STORE_SIZE?size:DEFAULT_OBJ_STORE_SIZE;
+ objstr_t **otmp=&t_reserve;
+ objstr_t *ptr;
+ while((ptr=*otmp)!=NULL) {
+ if (ptr->size>=newsize) {
+ //remove from list
+ *otmp=ptr->next;
+ ptr->next=t_cache;
+ t_cache=ptr;
+ ptr->top=((char *)(&ptr[1]))+size;
+ return &ptr[1];
+ }
+ }
+
objstr_t *os=(objstr_t *)calloc(1,(sizeof(objstr_t) + newsize));
- void *ptr=&os[1];
- os->next=*osptr;
- (*osptr)=os;
+ void *nptr=&os[1];
+ os->next=t_cache;
+ t_cache=os;
os->size=newsize;
- os->top=((char *)ptr)+size;
- return ptr;
+ os->top=((char *)nptr)+size;
+ return nptr;
}
}
objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t));
GETSIZE(size, header);
size += sizeof(objheader_t);
- objcopy = (objheader_t *) objstrAlloc(&t_cache, size);
+ objcopy = (objheader_t *) objstrAlloc(size);
memcpy(objcopy, header, size);
/* Insert into cache's lookup table */
STATUS(objcopy)=0;
}
#endif
freenewobjs();
- objstrDelete(t_cache);
- t_cache=NULL;
- t_chashDelete();
+ objstrReset();
+ t_chashreset();
return TRANS_ABORT;
}
if(finalResponse == TRANS_COMMIT) {
}
#endif
freenewobjs();
- objstrDelete(t_cache);
- t_cache=NULL;
- t_chashDelete();
+ objstrReset();
+ t_chashreset();
return 0;
}
/* wait a random amount of time before retrying to commit transaction*/
#include "stmlookup.h"
+#include "strings.h"
__thread chashlistnode_t *c_table;
__thread unsigned int c_size;
c_numelements = 0; // Initial number of elements in the hash
}
+void t_chashreset() {
+ chashlistnode_t *ptr = c_table;
+ int i;
+ for(i=0 ; i<c_size ; i++) {
+ chashlistnode_t * curr = ptr[i].next;
+ while(curr!=NULL) {
+ chashlistnode_t * next = curr->next;
+ free(curr);
+ curr=next;
+ }
+ }
+ c_numelements = 0;
+ bzero(c_table, sizeof(chashlistnode_t)*c_size);
+}
+
chashtable_t *chashCreate(unsigned int size, double loadfactor) {
chashtable_t *ctable;
chashlistnode_t *nodes;
unsigned int size; //this many bytes are allocated after this header
void *top;
struct objstr *next;
- struct objstr *prev;
} objstr_t;
#define MAXOBJLIST 512
};
extern __thread struct objlist * newobjs;
+extern __thread objstr_t *t_cache;
+extern __thread objstr_t *t_reserve;
+
#ifdef TRANSSTATS
/***********************************
* ================================
*/
int stmStartup();
+void objstrReset();
void objstrDelete(objstr_t *store);
objstr_t *objstrCreate(unsigned int size);
void transStart();
objheader_t *transCreateObj(void * ptr, unsigned int size);
unsigned int getNewOID(void);
-void *objstrAlloc(objstr_t **osptr, unsigned int size);
+void *objstrAlloc(unsigned int size);
__attribute__((pure)) void *transRead(void * oid);
int transCommit();
int traverseCache();
#ifndef RAW
#include <stdio.h>
#endif
+#ifdef STM
+#include "tm.h"
+#endif
+
int threadcount;
pthread_mutex_t gclock;
pthread_mutex_t gclistlock;
___Thread______staticStart____L___Thread___((struct ___Thread______staticStart____L___Thread____params *)p);
#else
newobjs=calloc(1, sizeof(struct objlist));
+ t_cache = objstrCreate(1048576);
+ t_reserve=NULL;
+ t_chashCreate(CHASH_SIZE, CLOADFACTOR);
___Thread____NN____staticStart____L___Thread___((struct ___Thread____NN____staticStart____L___Thread____params *)p);
- free(newobjs);
+ objstrDelete(t_cache);
+ objstrDelete(t_reserve);
+ t_chashDelete();
+ free(newobjs);
#endif
___this___=(struct ___Thread___ *) p[2];
#else