From 641f09a5f4bcc885f63b4b920b3ba033d3115d9c Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 13 Apr 2011 01:51:41 +0000 Subject: [PATCH] make work on mac --- Robust/src/Runtime/garbage.c | 14 ++++++++++++++ Robust/src/Runtime/runtime.c | 3 ++- Robust/src/Runtime/thread.c | 34 +++++++++++++++++++++++++++++----- Robust/src/Runtime/thread.h | 6 ++++++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 3a121cc3..ad9ea2c2 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -321,9 +321,11 @@ void enqueuetag(struct ___TagDescriptor___ *ptr) { #endif #if defined(STM)||defined(THREADS)||defined(MLP) +#ifndef MAC __thread char * memorybase=NULL; __thread char * memorytop=NULL; #endif +#endif void collect(struct garbagelist * stackptr) { @@ -378,7 +380,11 @@ void collect(struct garbagelist * stackptr) { } #endif #if defined(STM)||defined(THREADS)||defined(MLP) +#ifdef MAC + *((char **)pthread_getspecific(memorybasekey))=NULL; +#else memorybase=NULL; +#endif #endif /* Check current stack */ @@ -865,8 +871,12 @@ void stopforgc(struct garbagelist * ptr) { #ifndef MAC litem.stackptr=ptr; #if defined(STM)||defined(THREADS)||defined(MLP) +#ifdef MAC + litem.base=pthread_getspecific(memorybasekey); +#else litem.base=&memorybase; #endif +#endif #ifdef STM litem.tc_size=c_size; litem.tc_table=&c_table; @@ -913,6 +923,10 @@ void * helper(struct garbagelist *, int); void * mygcmalloc(struct garbagelist * stackptr, int size) { if ((size&7)!=0) size=(size&~7)+8; +#ifdef MAC + char * memorybase=*(char **)pthread_getspecific(memorybasekey); + char * memorytop=*(char **)pthread_getspecific(memorytopkey); +#endif if (memorybase==NULL||size>(memorytop-memorybase)) { int toallocate=(size>MEMORYBLOCK)?size:MEMORYBLOCK; memorybase=helper(stackptr, toallocate); diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 403fa797..f2c81b0f 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -1,4 +1,3 @@ - #include "runtime.h" #include "structdefs.h" #include @@ -55,10 +54,12 @@ __thread int objcount=0; #endif #if defined(THREADS)||defined(STM) +#ifndef MAC /* Global barrier for STM */ pthread_barrier_t barrier; pthread_barrierattr_t attr; #endif +#endif #include diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index f475c17e..ba0d9b53 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -55,6 +55,8 @@ pthread_key_t oidval; #ifndef MAC extern __thread struct listitem litem; #else +pthread_key_t memorybasekey; +pthread_key_t memorytopkey; pthread_key_t litemkey; #endif extern struct listitem * list; @@ -131,6 +133,15 @@ transstart: pthread_exit(NULL); } +#ifdef MAC +void threadhandler(int sig) { + printf("We just took sig=%d\n",sig); + printf("signal\n"); + printf("To get stack trace, set breakpoint in threadhandler in gdb\n"); + + threadexit(); +} +#else void threadhandler(int sig, struct sigcontext ctx) { void *buffer[100]; char **strings; @@ -157,6 +168,7 @@ void threadhandler(int sig, struct sigcontext ctx) { threadexit(); } +#endif #define downpage(x) ((void *)(((INTPTR)x)&~((INTPTR)4095))) @@ -176,7 +188,8 @@ void initializethreads() { #ifdef MAC pthread_key_create(&macthreadid, NULL); pthread_key_create(&threadlocks, NULL); - pthread_key_create(&litem, NULL); + pthread_key_create(&memorybasekey, NULL); + pthread_key_create(&memorytopkey, NULL); #endif processOptions(); initializeexithandler(); @@ -249,11 +262,18 @@ void initializethreads() { #ifdef MAC struct listitem *litem=malloc(sizeof(struct listitem)); struct lockvector *lvector=malloc(sizeof(struct lockvector)); - litem->lockvector=lvector; + litem->lvector=lvector; lvector->index=0; pthread_setspecific(threadlocks, lvector); - pthread_setspecific(macthreadid, 0); + pthread_setspecific(macthreadid, (void *)0); pthread_setspecific(litemkey, litem); + char ** memorybase=malloc(sizeof(char *)); + *memorybase=NULL; + pthread_setspecific(memorybasekey, memorybase); + char ** memorytop=malloc(sizeof(char *)); + *memorytop=NULL; + pthread_setspecific(memorytopkey, memorytop); + litem->prev=NULL; litem->next=list; if(list!=NULL) @@ -302,8 +322,12 @@ void initthread(struct ___Thread___ * ___this___) { //Add our litem to list of threads #ifdef MAC struct listitem litem; - pthread_setspecific(litemkey, &litem); struct lockvector lvector; + char * memorybase=NULL; + char * memorytop=NULL; + pthread_setspecific(litemkey, &litem); + pthread_setspecific(memorybasekey, &memorybase); + pthread_setspecific(memorytopkey, &memorytop); pthread_setspecific(threadlocks, &lvector); #endif litem.lvector=&lvector; @@ -311,7 +335,7 @@ void initthread(struct ___Thread___ * ___this___) { litem.prev=NULL; pthread_mutex_lock(&gclistlock); #ifdef MAC - pthread_setspecific(macthreadid, ++threadcounter); + pthread_setspecific(macthreadid, (void *)((long)(++threadcounter))); #else mythreadid=++threadcounter; #endif diff --git a/Robust/src/Runtime/thread.h b/Robust/src/Runtime/thread.h index 45e8a9d6..b07ff45b 100644 --- a/Robust/src/Runtime/thread.h +++ b/Robust/src/Runtime/thread.h @@ -11,6 +11,12 @@ extern pthread_mutex_t objlock; extern pthread_cond_t objcond; extern pthread_key_t threadlocks; extern pthread_mutex_t atomiclock; +#ifdef MAC +extern pthread_key_t litemkey; +extern pthread_key_t macthreadid; +extern pthread_key_t memorybasekey; +extern pthread_key_t memorytopkey; +#endif #ifdef PRECISE_GC #define ATOMICLOCK if (pthread_mutex_trylock(&atomiclock)!=0) { \ -- 2.34.1