[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 ($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 ($1);') |
---|
| 32 | define(NU_GSINIT, `{ ($1) = 0; }') |
---|
| 33 | define(NU_GETSUB, `GETSUB($1,$2,$3,$4)') |
---|
| 34 | |
---|
| 35 | define(ADEC, `long ($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 ($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 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 | define(PAUSEDEC, ` |
---|
| 65 | struct { |
---|
| 66 | pthread_mutex_t Mutex; |
---|
| 67 | pthread_cond_t CondVar; |
---|
| 68 | unsigned long Flag; |
---|
| 69 | } $1; |
---|
| 70 | ') |
---|
| 71 | define(PAUSEINIT, `{ |
---|
| 72 | pthread_mutex_init(&$1.Mutex, NULL); |
---|
| 73 | pthread_cond_init(&$1.CondVar, NULL); |
---|
| 74 | $1.Flag = 0; |
---|
| 75 | } |
---|
| 76 | ') |
---|
| 77 | define(CLEARPAUSE, `{ |
---|
| 78 | $1.Flag = 0; |
---|
| 79 | pthread_mutex_unlock(&$1.Mutex);} |
---|
| 80 | ') |
---|
| 81 | define(SETPAUSE, `{ |
---|
| 82 | pthread_mutex_lock(&$1.Mutex); |
---|
| 83 | $1.Flag = 1; |
---|
| 84 | pthread_cond_broadcast(&$1.CondVar); |
---|
| 85 | pthread_mutex_unlock(&$1.Mutex);} |
---|
| 86 | ') |
---|
| 87 | define(EVENT, `{;}') |
---|
| 88 | define(WAITPAUSE, `{ |
---|
| 89 | pthread_mutex_lock(&$1.Mutex); |
---|
| 90 | if ($1.Flag == 0) { |
---|
| 91 | pthread_cond_wait(&$1.CondVar, &$1.Mutex); |
---|
| 92 | } |
---|
| 93 | }') |
---|
| 94 | define(PAUSE, `{;}') |
---|
| 95 | |
---|
| 96 | define(AUG_ON, ` ') |
---|
| 97 | define(AUG_OFF, ` ') |
---|
| 98 | define(TRACE_ON, ` ') |
---|
| 99 | define(TRACE_OFF, ` ') |
---|
| 100 | define(REF_TRACE_ON, ` ') |
---|
| 101 | define(REF_TRACE_OFF, ` ') |
---|
| 102 | define(DYN_TRACE_ON, `;') |
---|
| 103 | define(DYN_TRACE_OFF, `;') |
---|
| 104 | define(DYN_REF_TRACE_ON, `;') |
---|
| 105 | define(DYN_REF_TRACE_OFF, `;') |
---|
| 106 | define(DYN_SIM_ON, `;') |
---|
| 107 | define(DYN_SIM_OFF, `;') |
---|
| 108 | define(DYN_SCHED_ON, `;') |
---|
| 109 | define(DYN_SCHED_OFF, `;') |
---|
| 110 | define(AUG_SET_LOLIMIT, `;') |
---|
| 111 | define(AUG_SET_HILIMIT, `;') |
---|
| 112 | |
---|
| 113 | define(MENTER, `{;}') |
---|
| 114 | define(DELAY, `{;}') |
---|
| 115 | define(CONTINUE, `{;}') |
---|
| 116 | define(MEXIT, `{;}') |
---|
| 117 | define(MONINIT, `{;}') |
---|
| 118 | |
---|
| 119 | define(WAIT_FOR_END, `{ |
---|
| 120 | long i, Error; |
---|
| 121 | for (i = 0; i < ($1) - 1; i++) { |
---|
| 122 | Error = pthread_join(PThreadTable[i], NULL); |
---|
| 123 | if (Error != 0) { |
---|
| 124 | printf("Error in pthread_join().\n"); |
---|
| 125 | exit(-1); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | }') |
---|
| 129 | |
---|
| 130 | define(CREATE, `{ |
---|
| 131 | long i, Error; |
---|
| 132 | |
---|
| 133 | for (i = 0; i < ($2) - 1; i++) { |
---|
| 134 | Error = pthread_create(&PThreadTable[i], NULL, (void * (*)(void *))($1), NULL); |
---|
| 135 | if (Error != 0) { |
---|
| 136 | printf("Error in pthread_create().\n"); |
---|
| 137 | exit(-1); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | $1(); |
---|
| 142 | }') |
---|
| 143 | |
---|
| 144 | define(MAIN_INITENV, `{;}') |
---|
| 145 | define(MAIN_END, `{exit(0);}') |
---|
| 146 | |
---|
| 147 | define(MAIN_ENV,` |
---|
| 148 | #include <pthread.h> |
---|
| 149 | #include <sys/time.h> |
---|
| 150 | #include <unistd.h> |
---|
| 151 | #include <stdlib.h> |
---|
| 152 | #include <malloc.h> |
---|
| 153 | #define MAX_THREADS 32 |
---|
| 154 | pthread_t PThreadTable[MAX_THREADS]; |
---|
| 155 | ') |
---|
| 156 | |
---|
| 157 | define(ENV, ` ') |
---|
| 158 | define(EXTERN_ENV, ` |
---|
| 159 | #include <pthread.h> |
---|
| 160 | #include <sys/time.h> |
---|
| 161 | #include <unistd.h> |
---|
| 162 | #include <stdlib.h> |
---|
| 163 | #include <malloc.h> |
---|
| 164 | extern pthread_t PThreadTable[]; |
---|
| 165 | ') |
---|
| 166 | |
---|
| 167 | define(G_MALLOC, `valloc($1);') |
---|
| 168 | define(G_FREE, `;') |
---|
| 169 | define(G_MALLOC_F, `valloc($1)') |
---|
| 170 | define(NU_MALLOC, `valloc($1);') |
---|
| 171 | define(NU_FREE, `;') |
---|
| 172 | define(NU_MALLOC_F, `valloc($1)') |
---|
| 173 | |
---|
| 174 | define(GET_HOME, `{($1) = 0;}') |
---|
| 175 | define(GET_PID, `{($1) = 0;}') |
---|
| 176 | define(AUG_DELAY, `{sleep ($1);}') |
---|
| 177 | define(ST_LOG, `{;}') |
---|
| 178 | define(SET_HOME, `{;}') |
---|
| 179 | define(CLOCK, `{ |
---|
| 180 | struct timeval FullTime; |
---|
| 181 | |
---|
| 182 | gettimeofday(&FullTime, NULL); |
---|
| 183 | ($1) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000); |
---|
| 184 | }') |
---|
| 185 | divert(0) |
---|