From 4b52a83ccea834b38ca57f84d87af72f04469c59 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 13 Oct 2009 23:39:11 +0000 Subject: [PATCH] more changes --- Robust/src/Runtime/STM/array.h | 15 +++++++++++++++ Robust/src/Runtime/STM/stm.c | 8 +++++++- Robust/src/Runtime/STM/tm.h | 4 ++++ Robust/src/Runtime/runtime.c | 10 ++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Robust/src/Runtime/STM/array.h diff --git a/Robust/src/Runtime/STM/array.h b/Robust/src/Runtime/STM/array.h new file mode 100644 index 00000000..90407248 --- /dev/null +++ b/Robust/src/Runtime/STM/array.h @@ -0,0 +1,15 @@ +#ifndef ARRAY_H +#define ARRAY_H + +/* Array layout */ +#define INDEXSHIFT 4 //must be at least 3 for doubles +#define DBLINDEXSHIFT INDEXSHIFT-1 //must be at least 3 for doubles + +#define GETLOCKPTR(lock, array, byteindex) { \ + lock=(int *)((char *)array-sizeof(objheader_t)-sizeof(int)*(byteindex>>DBLINDEXSHIFT)); \ + } + +#define GETVERSIONPTR(version, array, byteindex) { \ + version=(int *)((char *)array-sizeof(objheader_t)-sizeof(int)*(byteindex>>DBLINDEXSHIFT)-sizeof(int)); \ + } +#endif diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index 4699540f..0ced99c4 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -89,9 +89,15 @@ void transStart() { * This function creates objects in the transaction record * ======================================================= */ +#ifdef STMARRAY +objheader_t *transCreateObj(void * ptr, unsigned int size, int bytelength) { + int *tmpint = mygcmalloc(ptr, (sizeof(objheader_t) + size)); + objheader_t *tmp = (objheader_t *) (tmpint+(bytelength>>DBLINDEXSHIFT)); +#else objheader_t *transCreateObj(void * ptr, unsigned int size) { objheader_t *tmp = mygcmalloc(ptr, (sizeof(objheader_t) + size)); - objheader_t *retval=&tmp[1]; +#endif + objheader_t *retval=tmp+1; tmp->lock=RW_LOCK_BIAS; tmp->version = 1; //initialize obj lock to the header diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 89a7b442..2384b30c 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -260,4 +260,8 @@ struct fixedlist { void * array[200]; }; +#ifdef STMARRAY +#include "array.h" +#endif + #endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index c4502f55..b8240d22 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -469,7 +469,11 @@ __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) { /* Array allocation function */ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) { +#ifdef STMARRAY + struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(int)*(((length*classsize[type])>>DBLINDEXSHIFT)), (length*classsize[type])>>DBLINDEXSHIFT); +#else struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]); +#endif if (length<0) { printf("ERROR: negative array\n"); return NULL; @@ -479,6 +483,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, v->___length___=length; return v; } + __attribute__((malloc)) void * allocate_new(void * ptr, int type) { objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t)); struct ___Object___ * v=(struct ___Object___ *) &tmp[1]; @@ -492,7 +497,12 @@ __attribute__((malloc)) void * allocate_new(void * ptr, int type) { /* Array allocation function */ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { +#ifdef STMARRAY + int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t)+sizeof(int)*(((length*classsize[type])>>DBLINDEXSHIFT))); + objheader_t *tmp=(objheader_t *)(tmpint+((length*classsize[type])>>DBLINDEXSHIFT)); +#else objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t)); +#endif struct ArrayObject * v=(struct ArrayObject *) &tmp[1]; initdsmlocks(&tmp->lock); tmp->version=1; -- 2.34.1