int needtocollect=0;
struct listitem * list=NULL;
int listcount=0;
+#ifndef MAC
+__thread struct listitem litem;
+#endif
#endif
//Need to check if pointers are transaction pointers
#if defined(THREADS)||defined(DSTM)||defined(STM)
void checkcollect(void * ptr) {
- struct listitem * tmp=stopforgc((struct garbagelist *)ptr);
+ stopforgc((struct garbagelist *)ptr);
pthread_mutex_lock(&gclock); // Wait for GC
- restartaftergc(tmp);
+ restartaftergc();
pthread_mutex_unlock(&gclock);
}
#ifdef DSTM
void checkcollect2(void * ptr) {
int ptrarray[]={1, (int)ptr, (int) revertlist};
- struct listitem * tmp=stopforgc((struct garbagelist *)ptrarray);
+ stopforgc((struct garbagelist *)ptrarray);
pthread_mutex_lock(&gclock); // Wait for GC
- restartaftergc(tmp);
+ restartaftergc();
pthread_mutex_unlock(&gclock);
revertlist=(struct ___Object___*)ptrarray[2];
}
#endif
-struct listitem * stopforgc(struct garbagelist * ptr) {
- struct listitem * litem=malloc(sizeof(struct listitem));
- litem->stackptr=ptr;
+void stopforgc(struct garbagelist * ptr) {
+#ifndef MAC
+ litem.stackptr=ptr;
#ifdef THREADS
- litem->locklist=pthread_getspecific(threadlocks);
+ litem.locklist=pthread_getspecific(threadlocks);
#endif
#ifdef STM
- litem->tc_size=c_size;
- litem->tc_table=&c_table;
- litem->tc_list=&c_list;
- litem->tc_structs=&c_structs;
- litem->objlist=newobjs;
+ litem.tc_size=c_size;
+ litem.tc_table=&c_table;
+ litem.tc_list=&c_list;
+ litem.tc_structs=&c_structs;
+ litem.objlist=newobjs;
#ifdef STMSTATS
- litem->lockedlist=lockedobjs;
+ litem.lockedlist=lockedobjs;
+#endif
+ litem.base=&memorybase;
+#endif
+#else
+ //handle MAC
+ struct listitem *litem=pthread_getspecific(litemkey);
+ litem->stackptr=ptr;
+#ifdef THREADS
+ litem->locklist=pthread_getspecific(threadlocks);
#endif
- litem->base=&memorybase;
#endif
- litem->prev=NULL;
pthread_mutex_lock(&gclistlock);
- litem->next=list;
- if(list!=NULL)
- list->prev=litem;
- list=litem;
listcount++;
pthread_cond_signal(&gccond);
pthread_mutex_unlock(&gclistlock);
- return litem;
}
-void restartaftergc(struct listitem * litem) {
+void restartaftergc() {
pthread_mutex_lock(&gclistlock);
-#ifdef THREADS
- pthread_setspecific(threadlocks, litem->locklist);
-#endif
- if (litem->prev==NULL) {
- list=litem->next;
- } else {
- litem->prev->next=litem->next;
- }
- if (litem->next!=NULL) {
- litem->next->prev=litem->prev;
- }
listcount--;
pthread_mutex_unlock(&gclistlock);
- free(litem);
}
#endif
void *ptr;
#if defined(THREADS)||defined(DSTM)||defined(STM)
if (pthread_mutex_trylock(&gclock)!=0) {
- struct listitem *tmp=stopforgc(stackptr);
+ stopforgc(stackptr);
pthread_mutex_lock(&gclock);
- restartaftergc(tmp);
+ restartaftergc();
}
#endif
ptr=curr_heapptr;
#if defined(THREADS)||defined(DSTM)||defined(STM)
extern int needtocollect;
void checkcollect(void * ptr);
-struct listitem * stopforgc(struct garbagelist * ptr);
-void restartaftergc(struct listitem * litem);
+void stopforgc(struct garbagelist * ptr);
+void restartaftergc();
#endif
void * tomalloc(int size);
void collect(struct garbagelist *stackptr);
VAR(___this___)->lockcount++;
} else {
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
pthread_mutex_lock(&objlock);
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
while(1) {
if (VAR(___this___)->tid==0) {
}
{
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
pthread_cond_wait(&objcond, &objlock);
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
}
}
// Synchronization point
int ret;
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
ret = pthread_barrier_wait(&barrier);
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
sin.sin_addr.s_addr=htonl(*(int *)(((char *)&VAR(___address___)->___length___)+sizeof(int)));
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
#endif
do {
} while (rc<0 && errno==EINTR); /* repeat if interrupted */
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
#endif
int newfd;
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
#endif
newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
setsockopt(newfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(flag));
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
#endif
if (newfd<0) {
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
#endif
int byteread=-1;
} while(byteread==-1&&errno==EINTR);
#if defined(THREADS)||defined(DSTM)||defined(STM)
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
#endif
pthread_cond_t threadnotifycond;
pthread_key_t oidval;
+#if defined(THREADS) || defined(DSTM) || defined(STM)
+#ifndef MAC
+extern __thread struct listitem litem;
+#else
+pthread_key_t litemkey;
+#endif
+#endif
+
void threadexit() {
#ifdef DSTM
objheader_t* ptr;
pthread_mutex_unlock(&objlock);
#endif
pthread_mutex_lock(&gclistlock);
+#ifdef THREADS
+ pthread_setspecific(threadlocks, litem->locklist);
+#endif
+#ifndef MAC
+ if (litem.prev==NULL) {
+ list=litem.next;
+ } else {
+ litem.prev->next=litem.next;
+ }
+ if (litem.next!=NULL) {
+ litem.next->prev=litem.prev;
+ }
+#else
+ {
+ struct listitem *litem=pthread_getspecific(litemkey);
+ if (litem->prev==NULL) {
+ list=litem->next;
+ } else {
+ litem->prev->next=litem->next;
+ }
+ if (litem->next!=NULL) {
+ litem->next->prev=litem->prev;
+ }
+ }
+#endif
threadcount--;
pthread_cond_signal(&gccond);
pthread_mutex_unlock(&gclistlock);
pthread_mutex_init(&joinlock,NULL);
pthread_cond_init(&joincond,NULL);
pthread_key_create(&threadlocks, NULL);
+#ifdef MAC
+ pthread_key_create(&litem, NULL);
+#endif
processOptions();
initializeexithandler();
void initthread(struct ___Thread___ * ___this___) {
#ifdef PRECISE_GC
INTPTR p[]={1, (INTPTR) NULL, (INTPTR) ___this___};
+ //Add our litem to list of threads
+#ifdef MAC
+ struct listitem litem;
+ pthread_setspecific(litemkey, &litem);
+#endif
+ litem.prev=NULL;
+ pthread_mutex_lock(&gclistlock);
+ litem.next=list;
+ if(list!=NULL)
+ list->prev=&litem;
+ list=&litem;
+ pthread_mutex_unlock(&gclistlock);
+
#ifdef THREADS
___Thread______staticStart____L___Thread___((struct ___Thread______staticStart____L___Thread____params *)p);
#else
pthread_mutex_unlock(&joinlock);
pthread_mutex_lock(&gclistlock);
+#ifdef THREADS
+ pthread_setspecific(threadlocks, litem->locklist);
+#endif
+ if (litem.prev==NULL) {
+ list=litem.next;
+ } else {
+ litem.prev->next=litem.next;
+ }
+ if (litem.next!=NULL) {
+ litem.next->prev=litem.prev;
+ }
threadcount--;
pthread_cond_signal(&gccond);
pthread_mutex_unlock(&gclistlock);
void CALL11(___Thread______sleep____J, long long ___millis___, long long ___millis___) {
#if defined(THREADS)||defined(STM)
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
#endif
usleep(___millis___);
#if defined(THREADS)||defined(STM)
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
#endif
}
versionarray[0] = version;
/* Request Notification */
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
reqNotify(oidarray, versionarray, 1);
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
free(oidarray);
free(versionarray);
#if defined(THREADS)||defined(STM)
void CALL01(___Thread______nativeJoin____, struct ___Thread___ * ___this___) {
#ifdef PRECISE_GC
- struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+ stopforgc((struct garbagelist *)___params___);
#endif
pthread_mutex_lock(&joinlock);
while(!VAR(___this___)->___finished___)
pthread_cond_wait(&joincond, &joinlock);
pthread_mutex_unlock(&joinlock);
#ifdef PRECISE_GC
- restartaftergc(tmp);
+ restartaftergc();
#endif
}
free(ptr);
#ifdef PRECISE_GC
int p[]={1, 0 /* NULL */, oid};
+#ifdef MAC
+ struct listitem litem;
+ pthread_setspecific(litemkey, &litem);
+#endif
+
+ //Add our litem to list of threads
+ litem.prev=NULL;
+ pthread_mutex_lock(&gclistlock);
+ litem.next=list;
+ if(list!=NULL)
+ list->prev=&litem;
+ list=&litem;
+ pthread_mutex_unlock(&gclistlock);
+
((void(*) (void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(p);
#else
((void(*) (void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(oid);
*((unsigned int *) threadData) = oid;
pthread_setspecific(oidval, threadData);
pthread_mutex_lock(&gclistlock);
+
+#ifdef THREADS
+ pthread_setspecific(threadlocks, litem->locklist);
+#endif
+ if (litem.prev==NULL) {
+ list=litem.next;
+ } else {
+ litem.prev->next=litem.next;
+ }
+ if (litem.next!=NULL) {
+ litem.next->prev=litem.prev;
+ }
threadcount--;
pthread_cond_signal(&gccond);
pthread_mutex_unlock(&gclistlock);