source: soft/giet_vm/applications/ocean/null_macros/c.m4.null.SOCLIB @ 792

Last change on this file since 792 was 581, checked in by laurent, 9 years ago

Adding ocean application, some mathematics functions and distributed locks

File size: 4.2 KB
Line 
1divert(-1)
2define(NEWPROC,) dnl
3
4define(BARRIER, `{
5        pthread_barrier_wait(&($1));
6}')
7
8define(BARDEC, `
9   pthread_barrier_t    ($1);
10')
11
12define(BARINIT, `{
13        pthread_barrier_init(&($1), NULL, $2);
14}')
15
16define(BAREXCLUDE, `{;}')
17
18define(BARINCLUDE, `{;}')
19
20define(GSDEC, `long int ($1);')
21define(GSINIT, `{ ($1) = 0; }')
22define(GETSUB, `{
23  if (($1)<=($3))
24    ($2) = ($1)++;
25  else {
26    ($2) = -1;
27    ($1) = 0;
28  }
29}')
30
31define(NU_GSDEC, `long int ($1);')
32define(NU_GSINIT, `{ ($1) = 0; }')
33define(NU_GETSUB, `GETSUB($1,$2,$3,$4)')
34
35define(ADEC, `long int ($1);')
36define(AINIT, `{;}')
37define(PROBEND, `{;}')
38
39define(LOCKDEC, `pthread_mutex_t ($1);')
40define(LOCKINIT, `{pthread_mutex_init(&($1), NULL);}')
41define(LOCK, `{pthread_mutex_lock(&($1));}')
42define(UNLOCK, `{pthread_mutex_unlock(&($1));}')
43
44define(NLOCKDEC, `long int ($1);')
45define(NLOCKINIT, `{;}')
46define(NLOCK, `{;}')
47define(NUNLOCK, `{;}')
48
49define(ALOCKDEC, `pthread_mutex_t $1[$2];')
50define(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}')
61define(ALOCK, `{pthread_mutex_lock(&$1[$2]);}')
62define(AULOCK, `{pthread_mutex_unlock(&$1[$2]);}')
63
64
65define(PAUSEDEC, `
66struct {
67   pthread_mutex_t   mutex;
68   pthread_cond_t    cond_var;
69   unsigned long int Flag;
70} $1;
71')
72
73define(PAUSEINIT, `{
74   pthread_mutex_init(&$1.mutex, NULL);
75   pthread_cond_init(&$1.cond_var, NULL);
76   $1.Flag = 0;
77}
78')
79
80define(CLEARPAUSE, `{
81   $1.Flag = 0;
82   pthread_mutex_unlock(&$1.mutex);}
83')
84define(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
91define(EVENT, `{;}')
92define(WAITPAUSE, `{
93   pthread_mutex_lock(&$1.mutex);
94   if ($1.Flag == 0) {
95      pthread_cond_wait(&$1.cond_var, &$1.mutex);
96   }
97}')
98define(PAUSE, `{;}')
99
100define(AUG_ON, ` ')
101define(AUG_OFF, ` ')
102define(TRACE_ON, ` ')
103define(TRACE_OFF, ` ')
104define(REF_TRACE_ON, ` ')
105define(REF_TRACE_OFF, ` ')
106define(DYN_TRACE_ON, `;')
107define(DYN_TRACE_OFF, `;')
108define(DYN_REF_TRACE_ON, `;')
109define(DYN_REF_TRACE_OFF, `;')
110define(DYN_SIM_ON, `;')
111define(DYN_SIM_OFF, `;')
112define(DYN_SCHED_ON, `;')
113define(DYN_SCHED_OFF, `;')
114define(AUG_SET_LOLIMIT, `;')
115define(AUG_SET_HILIMIT, `;')
116
117define(MENTER, `{;}')
118define(DELAY, `{;}')
119define(CONTINUE, `{;}')
120define(MEXIT, `{;}')
121define(MONINIT, `{;}')
122
123define(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
134define(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
158define(MAIN_INITENV, `{;}')
159define(MAIN_END, `{
160   *(unsigned int *) 0x0 = 0xDEADDEAD;
161   return 0;
162}')
163
164define(MAIN_ENV,`
165#include <pthread.h>
166//#include <sys/time.h>
167#include <unistd.h>
168#include <stdlib.h>
169#define MAX_THREADS 512
170pthread_t PThreadTable[MAX_THREADS];
171')
172
173define(ENV, ` ')
174define(EXTERN_ENV, `
175#include <pthread.h>
176//#include <sys/time.h>
177#include <unistd.h>
178#include <stdlib.h>
179extern pthread_t PThreadTable[];
180')
181
182define(G_MALLOC, `malloc($1);')
183define(G_FREE, `free($1);')
184define(G_MALLOC_F, `malloc($1)')
185define(NU_MALLOC, `malloc($1);')
186define(NU_FREE, `free($1);')
187define(NU_MALLOC_F, `malloc($1)')
188
189define(GET_HOME, `{($1) = 0;}')
190define(GET_PID, `{($1) = 0;}')
191define(AUG_DELAY, `{sleep ($1);}')
192define(ST_LOG, `{;}')
193define(SET_HOME, `{;}')
194define(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}')
200divert(0)
Note: See TracBrowser for help on using the repository browser.