[581] | 1 | divert(-1) |
---|
| 2 | define(NEWPROC,) dnl |
---|
| 3 | |
---|
| 4 | define(BARRIER, `{ |
---|
| 5 | pthread_barrier_wait(&($1)); |
---|
| 6 | }') |
---|
| 7 | |
---|
| 8 | define(BARDEC, ` |
---|
| 9 | pthread_barrier_t ($1); |
---|
| 10 | ') |
---|
| 11 | |
---|
| 12 | define(BARINIT, `{ |
---|
| 13 | pthread_barrier_init(&($1), NULL, $2); |
---|
| 14 | }') |
---|
| 15 | |
---|
| 16 | define(BAREXCLUDE, `{;}') |
---|
| 17 | |
---|
| 18 | define(BARINCLUDE, `{;}') |
---|
| 19 | |
---|
| 20 | define(GSDEC, `long int ($1);') |
---|
| 21 | define(GSINIT, `{ ($1) = 0; }') |
---|
| 22 | define(GETSUB, `{ |
---|
| 23 | if (($1)<=($3)) |
---|
| 24 | ($2) = ($1)++; |
---|
| 25 | else { |
---|
| 26 | ($2) = -1; |
---|
| 27 | ($1) = 0; |
---|
| 28 | } |
---|
| 29 | }') |
---|
| 30 | |
---|
| 31 | define(NU_GSDEC, `long int ($1);') |
---|
| 32 | define(NU_GSINIT, `{ ($1) = 0; }') |
---|
| 33 | define(NU_GETSUB, `GETSUB($1,$2,$3,$4)') |
---|
| 34 | |
---|
| 35 | define(ADEC, `long int ($1);') |
---|
| 36 | define(AINIT, `{;}') |
---|
| 37 | define(PROBEND, `{;}') |
---|
| 38 | |
---|
| 39 | define(LOCKDEC, `pthread_mutex_t ($1);') |
---|
| 40 | define(LOCKINIT, `{pthread_mutex_init(&($1), NULL);}') |
---|
| 41 | define(LOCK, `{pthread_mutex_lock(&($1));}') |
---|
| 42 | define(UNLOCK, `{pthread_mutex_unlock(&($1));}') |
---|
| 43 | |
---|
| 44 | define(NLOCKDEC, `long int ($1);') |
---|
| 45 | define(NLOCKINIT, `{;}') |
---|
| 46 | define(NLOCK, `{;}') |
---|
| 47 | define(NUNLOCK, `{;}') |
---|
| 48 | |
---|
| 49 | define(ALOCKDEC, `pthread_mutex_t $1[$2];') |
---|
| 50 | define(ALOCKINIT, `{ |
---|
| 51 | unsigned long int i, error; |
---|
| 52 | |
---|
| 53 | for (i = 0; i < $2; i++) { |
---|
| 54 | error = pthread_mutex_init(&$1[i], NULL); |
---|
| 55 | if (error != 0) { |
---|
| 56 | printf("Error while initializing array of locks.\n"); |
---|
| 57 | exit(-1); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | }') |
---|
| 61 | define(ALOCK, `{pthread_mutex_lock(&$1[$2]);}') |
---|
| 62 | define(AULOCK, `{pthread_mutex_unlock(&$1[$2]);}') |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | define(PAUSEDEC, ` |
---|
| 66 | struct { |
---|
| 67 | pthread_mutex_t mutex; |
---|
| 68 | pthread_cond_t cond_var; |
---|
| 69 | unsigned long int Flag; |
---|
| 70 | } $1; |
---|
| 71 | ') |
---|
| 72 | |
---|
| 73 | define(PAUSEINIT, `{ |
---|
| 74 | pthread_mutex_init(&$1.mutex, NULL); |
---|
| 75 | pthread_cond_init(&$1.cond_var, NULL); |
---|
| 76 | $1.Flag = 0; |
---|
| 77 | } |
---|
| 78 | ') |
---|
| 79 | |
---|
| 80 | define(CLEARPAUSE, `{ |
---|
| 81 | $1.Flag = 0; |
---|
| 82 | pthread_mutex_unlock(&$1.mutex);} |
---|
| 83 | ') |
---|
| 84 | define(SETPAUSE, `{ |
---|
| 85 | pthread_mutex_lock(&$1.mutex); |
---|
| 86 | $1.Flag = 1; |
---|
| 87 | pthread_cond_broadcast(&$1.cond_var); |
---|
| 88 | pthread_mutex_unlock(&$1.mutex);} |
---|
| 89 | ') |
---|
| 90 | |
---|
| 91 | define(EVENT, `{;}') |
---|
| 92 | define(WAITPAUSE, `{ |
---|
| 93 | pthread_mutex_lock(&$1.mutex); |
---|
| 94 | if ($1.Flag == 0) { |
---|
| 95 | pthread_cond_wait(&$1.cond_var, &$1.mutex); |
---|
| 96 | } |
---|
| 97 | }') |
---|
| 98 | define(PAUSE, `{;}') |
---|
| 99 | |
---|
| 100 | define(AUG_ON, ` ') |
---|
| 101 | define(AUG_OFF, ` ') |
---|
| 102 | define(TRACE_ON, ` ') |
---|
| 103 | define(TRACE_OFF, ` ') |
---|
| 104 | define(REF_TRACE_ON, ` ') |
---|
| 105 | define(REF_TRACE_OFF, ` ') |
---|
| 106 | define(DYN_TRACE_ON, `;') |
---|
| 107 | define(DYN_TRACE_OFF, `;') |
---|
| 108 | define(DYN_REF_TRACE_ON, `;') |
---|
| 109 | define(DYN_REF_TRACE_OFF, `;') |
---|
| 110 | define(DYN_SIM_ON, `;') |
---|
| 111 | define(DYN_SIM_OFF, `;') |
---|
| 112 | define(DYN_SCHED_ON, `;') |
---|
| 113 | define(DYN_SCHED_OFF, `;') |
---|
| 114 | define(AUG_SET_LOLIMIT, `;') |
---|
| 115 | define(AUG_SET_HILIMIT, `;') |
---|
| 116 | |
---|
| 117 | define(MENTER, `{;}') |
---|
| 118 | define(DELAY, `{;}') |
---|
| 119 | define(CONTINUE, `{;}') |
---|
| 120 | define(MEXIT, `{;}') |
---|
| 121 | define(MONINIT, `{;}') |
---|
| 122 | |
---|
| 123 | define(WAIT_FOR_END, `{ |
---|
| 124 | long int i, error; |
---|
| 125 | for (i = 1; i < ($1); i++) { |
---|
| 126 | error = pthread_join(PThreadTable[i], NULL); |
---|
| 127 | if (error != 0) { |
---|
| 128 | printf("Error in pthread_join().\n"); |
---|
| 129 | exit(-1); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | }') |
---|
| 133 | |
---|
| 134 | define(CREATE, `{ |
---|
| 135 | long int i, error; |
---|
| 136 | pthread_attr_t attr; |
---|
| 137 | |
---|
| 138 | error = pthread_attr_init(&attr); |
---|
| 139 | if (error != 0) { |
---|
| 140 | fprintf(stderr, "*** Error in pthread_attr_init\n"); |
---|
| 141 | exit(1); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // HypothÚse : le thread "main" s exécute sur le proc 0 ; pour almos utiliser l option -p x de exec dans le shrc |
---|
| 145 | for (i = 1; i < ($2); i++) { |
---|
| 146 | pthread_attr_setcpuid_np(&attr, i, NULL); |
---|
| 147 | |
---|
| 148 | error = pthread_create(&PThreadTable[i], &attr, (void * (*)(void *))($1), NULL); |
---|
| 149 | if (error != 0) { |
---|
| 150 | printf("Error in pthread_create().\n"); |
---|
| 151 | exit(-1); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | $1(); |
---|
| 156 | }') |
---|
| 157 | |
---|
| 158 | define(MAIN_INITENV, `{;}') |
---|
| 159 | define(MAIN_END, `{ |
---|
| 160 | *(unsigned int *) 0x0 = 0xDEADDEAD; |
---|
| 161 | return 0; |
---|
| 162 | }') |
---|
| 163 | |
---|
| 164 | define(MAIN_ENV,` |
---|
| 165 | #include <pthread.h> |
---|
| 166 | //#include <sys/time.h> |
---|
| 167 | #include <unistd.h> |
---|
| 168 | #include <stdlib.h> |
---|
| 169 | #define MAX_THREADS 512 |
---|
| 170 | pthread_t PThreadTable[MAX_THREADS]; |
---|
| 171 | ') |
---|
| 172 | |
---|
| 173 | define(ENV, ` ') |
---|
| 174 | define(EXTERN_ENV, ` |
---|
| 175 | #include <pthread.h> |
---|
| 176 | //#include <sys/time.h> |
---|
| 177 | #include <unistd.h> |
---|
| 178 | #include <stdlib.h> |
---|
| 179 | extern pthread_t PThreadTable[]; |
---|
| 180 | ') |
---|
| 181 | |
---|
| 182 | define(G_MALLOC, `malloc($1);') |
---|
| 183 | define(G_FREE, `free($1);') |
---|
| 184 | define(G_MALLOC_F, `malloc($1)') |
---|
| 185 | define(NU_MALLOC, `malloc($1);') |
---|
| 186 | define(NU_FREE, `free($1);') |
---|
| 187 | define(NU_MALLOC_F, `malloc($1)') |
---|
| 188 | |
---|
| 189 | define(GET_HOME, `{($1) = 0;}') |
---|
| 190 | define(GET_PID, `{($1) = 0;}') |
---|
| 191 | define(AUG_DELAY, `{sleep ($1);}') |
---|
| 192 | define(ST_LOG, `{;}') |
---|
| 193 | define(SET_HOME, `{;}') |
---|
| 194 | define(CLOCK, `{ |
---|
| 195 | struct timeval timer; |
---|
| 196 | |
---|
| 197 | gettimeofday(&timer, NULL); |
---|
| 198 | ($1) = (unsigned long long int) (timer.tv_sec); // Number of cycles of simulation |
---|
| 199 | }') |
---|
| 200 | divert(0) |
---|