9 #include <DSTM/interface/dstm.h>
13 pthread_mutex_t gclock;
14 pthread_mutex_t gclistlock;
15 pthread_cond_t gccond;
16 pthread_mutex_t objlock;
17 pthread_cond_t objcond;
18 pthread_key_t threadlocks;
19 pthread_mutex_t threadnotifylock;
20 pthread_cond_t threadnotifycond;
21 transrecord_t * trans;
26 struct ___Object___ *ll=pthread_getspecific(threadlocks);
28 struct ___Object___ *llnext=ll->___nextlockobject___;
29 ll->___nextlockobject___=NULL;
30 ll->___prevlockobject___=NULL;
32 ll->tid=0; //unlock it
35 pthread_mutex_lock(&objlock);//wake everyone up
36 pthread_cond_broadcast(&objcond);
37 pthread_mutex_unlock(&objlock);
39 pthread_mutex_lock(&gclistlock);
41 pthread_cond_signal(&gccond);
42 pthread_mutex_unlock(&gclistlock);
43 /* Add transaction to check if thread finished for join operation */
49 ptr = (void *)transRead(trans, (unsigned int) a);
50 struct ___Thread___ *tmp = ((char *) ptr + sizeof(objheader_t));
51 tmp->___threadDone___ = 1;
52 if(transCommit(trans)) {
60 void threadhandler(int sig, siginfo_t *info, void *uap) {
62 printf("sig=%d\n",sig);
68 void initializethreads() {
71 pthread_mutex_init(&gclock, NULL);
72 pthread_mutex_init(&gclistlock, NULL);
73 pthread_cond_init(&gccond, NULL);
74 pthread_mutex_init(&objlock,NULL);
75 pthread_cond_init(&objcond,NULL);
76 pthread_key_create(&threadlocks, NULL);
78 initializeexithandler();
80 sig.sa_sigaction=&threadhandler;
81 sig.sa_flags=SA_SIGINFO;
82 sigemptyset(&sig.sa_mask);
84 /* Catch bus errors, segmentation faults, and floating point exceptions*/
85 sigaction(SIGBUS,&sig,0);
86 sigaction(SIGSEGV,&sig,0);
87 sigaction(SIGFPE,&sig,0);
88 signal(SIGPIPE, SIG_IGN);
92 void initthread(struct ___Thread___ * ___this___) {
94 struct ___Thread______staticStart____L___Thread____params p={1, NULL, ___this___};
95 ___Thread______staticStart____L___Thread___(&p);
97 ___Thread______staticStart____L___Thread___(___this___);
99 pthread_mutex_lock(&gclistlock);
101 pthread_cond_signal(&gccond);
102 pthread_mutex_unlock(&gclistlock);
106 void CALL11(___Thread______sleep____J, long long ___millis___, long long ___millis___) {
109 struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
112 usleep(___millis___);
120 /* Add thread join capability */
122 void CALL01(___Thread______join____, struct ___Thread___ * ___this___) {
124 printf("DEBUG -> Inside thread join\n");
126 if(VAR(___this___)->___threadDone___) {
129 /* Request Notification */
130 pthread_cond_broadcast(&objcond);
131 pthread_mutex_unlock(&objlock);
132 pthread_mutex_lock(&threadnotifylock);//wake everyone up
133 status = reqNotify((unsigned int)VAR(___this___));
135 if((status = reqNotify((unsigned int)VAR(___this___))) != 0) {
136 printf("No notification is sent %s, %d\n", __FILE__, __LINE__);
145 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
148 pthread_attr_t nattr;
150 pthread_mutex_lock(&gclistlock);
152 pthread_mutex_unlock(&gclistlock);
153 pthread_attr_init(&nattr);
154 pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED);
157 retval=pthread_create(&thread, &nattr, (void * (*)(void *)) &initthread, VAR(___this___));
162 pthread_attr_destroy(&nattr);
167 void CALL12(___Thread______start____I, int ___mid___, struct ___Thread___ * ___this___, int ___mid___) {
168 startRemoteThread((unsigned int)VAR(___this___), ___mid___);
173 void initDSMthread(int *ptr) {
178 int p[]={1, 0 /* NULL */, oid};
179 ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(p);
181 ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(oid);
183 pthread_mutex_lock(&gclistlock);
185 pthread_cond_signal(&gccond);
186 pthread_mutex_unlock(&gclistlock);
187 /* Add transaction to check if thread finished for join operation */
193 trans = transStart();
194 ptr = (void *)transRead(trans, (unsigned int) oid);
195 struct ___Thread___ *tmp = ((char *) ptr + sizeof(objheader_t));
196 tmp->___threadDone___ = 1;
197 if(transCommit(trans)) {
204 void startDSMthread(int oid, int objType) {
207 pthread_attr_t nattr;
209 pthread_mutex_lock(&gclistlock);
211 pthread_mutex_unlock(&gclistlock);
212 pthread_attr_init(&nattr);
213 pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED);
214 int * ptr=malloc(sizeof(int)*2);
218 retval=pthread_create(&thread, &nattr, (void * (*)(void *)) &initDSMthread, ptr);
223 pthread_attr_destroy(&nattr);