8 #define TRANS_SOFT_ABORT 12
10 #define TRANS_COMMIT 14
11 #define TRANS_ABORT_RETRY 15
13 /* ========================
14 * Library header files
15 * ========================
23 #include "stmlookup.h"
26 /* ==================================
27 * Bit designation for status field
29 * ==================================
36 #include "structdefs.h"
38 typedef struct threadrec {
42 typedef struct objheader {
44 unsigned int lock; /* reader and writer lock for object header */
46 int abortCount; /* track how many times does this object cause abort */
47 int accessCount; /* track how many times is this object accessed */
48 threadrec_t *trec; /* some thread that locked this object */
49 int riskyflag; /* track how risky is the object */
50 pthread_mutex_t *objlock; /* lock this object */
56 (*((void **)&((struct ___Object___ *)(((char *) x) + sizeof(objheader_t)))->___objlocation___))
59 ((((void *) x )!=NULL) ? (*((void **)&((struct ___Object___ *) x)->___objlocation___)) : NULL)
62 *((unsigned int *) &(((struct ___Object___ *)(((char *) x) + sizeof(objheader_t)))->___objstatus___))
64 #define STATUSPTR(x) \
65 ((unsigned int *) &(((struct ___Object___ *)(((char *) x) + sizeof(objheader_t)))->___objstatus___))
68 ((struct ___Object___ *)((char *) x + sizeof(objheader_t)))->type
70 #define GETSIZE(size, x) { \
72 if (type<NUMCLASSES) { \
73 size=classsize[type]; \
75 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject); \
81 #define TYPE(x) x->type
82 #define STATUS(x) x->status
83 #define STATUSPTR(x) &x->status
84 #define GETSIZE(size, x) size=classsize[TYPE(x)]
88 /* ================================
90 * ================================
92 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
94 #define NEED_LOCK_THRESHOLD 0.020000
95 #define OSUSED(x) (((unsigned INTPTR)(x)->top)-((unsigned INTPTR) (x+1)))
96 #define OSFREE(x) ((x)->size-OSUSED(x))
98 #define TRANSREAD(x,y,z) { \
100 if ((inputvalue=y)==NULL) x=NULL;\
102 chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; \
104 if (cnodetmp->key==inputvalue) {x=cnodetmp->val; break;} \
105 cnodetmp=cnodetmp->next; \
106 if (cnodetmp==NULL) {if (((struct ___Object___*)inputvalue)->___objstatus___&NEW) {x=inputvalue; break;} else \
107 {x=transRead(inputvalue,z); asm volatile ("" : "=m" (c_table),"=m" (c_mask)); break;}} \
111 #define TRANSREADRD(x,y) { \
113 if ((inputvalue=y)==NULL) x=NULL;\
115 chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; \
117 if (cnodetmp->key==inputvalue) {x=cnodetmp->val; break;} \
118 cnodetmp=cnodetmp->next; \
119 if (cnodetmp==NULL) {if (((struct ___Object___*)inputvalue)->___objstatus___&NEW) {x=inputvalue; break;} else \
120 {x=inputvalue;rd_t_chashInsertOnce(inputvalue, ((objheader_t *)inputvalue)[-1].version); break;}} \
124 /* =================================
126 * =================================
128 typedef struct objstr {
129 unsigned int size; //this many bytes are allocated after this header
134 #define MAXOBJLIST 512
137 void * objs[MAXOBJLIST];
138 struct objlist * next;
141 extern __thread struct objlist * newobjs;
142 extern __thread objstr_t *t_cache;
143 extern __thread objstr_t *t_reserve;
145 typedef struct objlockstate {
147 pthread_mutex_t lock[MAXOBJLIST];
148 struct objlockstate *next;
150 extern __thread threadrec_t *trec;
151 extern __thread struct objlist * lockedobjs;
152 extern objlockstate_t *objlockscope;
153 extern __thread int t_objnumcount;
154 pthread_mutex_t lockedobjstore;
156 typedef struct objtypestat {
159 int numtrans; //num of transactions that accessed this object type and aborted
162 /* Variables for probability model */
167 /***********************************
168 * Global Variables for statistics
169 **********************************/
171 extern int numTransCommit;
172 extern int numTransAbort;
173 extern int nSoftAbort;
174 extern int nSoftAbortAbort;
175 extern int nSoftAbortCommit;
179 extern objtypestat_t typesCausingAbort[];
183 /* ================================
185 * ================================
189 void objstrDelete(objstr_t *store);
190 objstr_t *objstrCreate(unsigned int size);
193 objheader_t *transCreateObj(void * ptr, unsigned int size, int bytelength);
195 objheader_t *transCreateObj(void * ptr, unsigned int size);
197 unsigned int getNewOID(void);
198 void *objstrAlloc(unsigned int size);
199 __attribute__((pure)) void *transRead(void *, void *);
201 __attribute__((pure)) void *transReadOnly(void *);
204 int transCommit(void (*commitmethod)(void *, void *, void *), void * primitives, void * locals, void * params);
205 int traverseCache(void (*commitmethod)(void *, void *, void *), void * primitives, void * locals, void * params);
206 int alttraverseCache(void (*commitmethod)(void *, void *, void *), void * primitives, void * locals, void * params);
207 void transCommitProcess(struct garbagelist *, int, int, void (*commitmethod)(void *, void *, void *), void * primitives, void * locals, void * params);
211 int alttraverseCache();
212 void transCommitProcess(struct garbagelist *, int);
214 int altalttraverseCache();
215 void transAbortProcess(struct garbagelist *, int);
216 void randomdelay(int);
217 #if defined(STMSTATS)||defined(SOFTABORT)
218 int getTotalAbortCount(int, int, void *, int, void*, int*, int*, int, objheader_t*, int*);
219 int getTotalAbortCount2(void *, int, void *, int *, int*, int, objheader_t*, int*);
220 int getReadAbortCount(int, int, void*, int*, int*, int, objheader_t*, int*);
223 objheader_t * needLock(objheader_t *, void *);
231 #define DEBUGSTMSTAT(args...)
233 #define DEBUGSTMSTAT(args...)
237 #define DEBUGSTM(x...) printf(x);
239 #define DEBUGSTM(x...);
243 #define DEBUGSTATS(x...) printf(x);
245 #define DEBUGSTATS(x...);
249 /* Thread variable for locking/unlocking */
250 extern __thread threadrec_t *trec;
251 extern __thread struct objlist * lockedobjs;
252 extern __thread int t_objnumcount;
256 #define unlikely(x) x
258 extern void * curr_heapbase;
259 extern void * curr_heapptr;
260 extern void * curr_heaptop;