source: soft/giet_vm/applications/ocean/null_macros/c.m4.null.POSIX_BARRIER @ 605

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

Adding ocean application, some mathematics functions and distributed locks

File size: 3.7 KB
Line 
1divert(-1)
2define(NEWPROC,) dnl
3
4define(BARRIER, `{
5        pthread_barrier_wait(&($1));
6}')
7
8define(BARDEC, `
9pthread_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 ($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 ($1);')
32define(NU_GSINIT, `{ ($1) = 0; }')
33define(NU_GETSUB, `GETSUB($1,$2,$3,$4)')
34
35define(ADEC, `long ($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 ($1);')
45define(NLOCKINIT, `{;}')
46define(NLOCK, `{;}')
47define(NUNLOCK, `{;}')
48
49define(ALOCKDEC, `pthread_mutex_t $1[$2];')
50define(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}')
61define(ALOCK, `{pthread_mutex_lock(&$1[$2]);}')
62define(AULOCK, `{pthread_mutex_unlock(&$1[$2]);}')
63
64define(PAUSEDEC, `
65struct {
66        pthread_mutex_t Mutex;
67        pthread_cond_t  CondVar;
68        unsigned long   Flag;
69} $1;
70')
71define(PAUSEINIT, `{
72        pthread_mutex_init(&$1.Mutex, NULL);
73        pthread_cond_init(&$1.CondVar, NULL);
74        $1.Flag = 0;
75}
76')
77define(CLEARPAUSE, `{
78        $1.Flag = 0;
79        pthread_mutex_unlock(&$1.Mutex);}
80')
81define(SETPAUSE, `{
82        pthread_mutex_lock(&$1.Mutex);
83        $1.Flag = 1;
84        pthread_cond_broadcast(&$1.CondVar);
85        pthread_mutex_unlock(&$1.Mutex);}
86')
87define(EVENT, `{;}')
88define(WAITPAUSE, `{
89        pthread_mutex_lock(&$1.Mutex);
90        if ($1.Flag == 0) {
91                pthread_cond_wait(&$1.CondVar, &$1.Mutex);
92        }
93}')
94define(PAUSE, `{;}')
95
96define(AUG_ON, ` ')
97define(AUG_OFF, ` ')
98define(TRACE_ON, ` ')
99define(TRACE_OFF, ` ')
100define(REF_TRACE_ON, ` ')
101define(REF_TRACE_OFF, ` ')
102define(DYN_TRACE_ON, `;')
103define(DYN_TRACE_OFF, `;')
104define(DYN_REF_TRACE_ON, `;')
105define(DYN_REF_TRACE_OFF, `;')
106define(DYN_SIM_ON, `;')
107define(DYN_SIM_OFF, `;')
108define(DYN_SCHED_ON, `;')
109define(DYN_SCHED_OFF, `;')
110define(AUG_SET_LOLIMIT, `;')
111define(AUG_SET_HILIMIT, `;')
112
113define(MENTER, `{;}')
114define(DELAY, `{;}')
115define(CONTINUE, `{;}')
116define(MEXIT, `{;}')
117define(MONINIT, `{;}')
118
119define(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
130define(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
144define(MAIN_INITENV, `{;}')
145define(MAIN_END, `{exit(0);}')
146
147define(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
154pthread_t PThreadTable[MAX_THREADS];
155')
156
157define(ENV, ` ')
158define(EXTERN_ENV, `
159#include <pthread.h>
160#include <sys/time.h>
161#include <unistd.h>
162#include <stdlib.h>
163#include <malloc.h>
164extern pthread_t PThreadTable[];
165')
166
167define(G_MALLOC, `valloc($1);')
168define(G_FREE, `;')
169define(G_MALLOC_F, `valloc($1)')
170define(NU_MALLOC, `valloc($1);')
171define(NU_FREE, `;')
172define(NU_MALLOC_F, `valloc($1)')
173
174define(GET_HOME, `{($1) = 0;}')
175define(GET_PID, `{($1) = 0;}')
176define(AUG_DELAY, `{sleep ($1);}')
177define(ST_LOG, `{;}')
178define(SET_HOME, `{;}')
179define(CLOCK, `{
180        struct timeval  FullTime;
181
182        gettimeofday(&FullTime, NULL);
183        ($1) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
184}')
185divert(0)
Note: See TracBrowser for help on using the repository browser.