[go: up one dir, main page]

Menu

[r6]: / trunk / src / cdthread.c  Maximize  Restore  History

Download this file

268 lines (199 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
xmd - molecular dynamics for metals and ceramics
By Jonathan Rifkin <jon.rifkin@uconn.edu>
Copyright 1995-2004 Jonathan Rifkin
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
************************************************************************
History
************************************************************************
*/
/*
23 April 1998
A dummy pthread module to replace standard pthread library. Essentially
when this module is included it converts a pthread program to a
normal sequential program.
The functions do some rudimentary parameter checking to verify
that threads are being called correctly. This will help catch bugs
before real threading is used.
*/
/*
************************************************************************
Compile Switches
************************************************************************
*/
/*
************************************************************************
Include Files
************************************************************************
*/
#include <stdio.h>
#include "cdthread.h"
/*
************************************************************************
Defines
************************************************************************
*/
#define BOOLEAN int
#define TRUE 1
#define FALSE 0
#define X 0
#define Y 1
#define Z 2
#define NDIR 3
/*
************************************************************************
Debugging Macros
************************************************************************
*/
/*
Debugging Macro: Test assertion, if failed list file and line number
*/
#define ASSERT(TEST) if (!(TEST)) \
printf ("INTERNAL ERROR: Failed assertion (%s) in file %s line %i.\n", \
#TEST, __FILE__, __LINE__);
/*
Debugging Macro: Print current file and line number
*/
#define WRITEMSG \
{ \
printf ("In file %s at line %i.\n", __FILE__, __LINE__); \
}
/*
Debugging Macro: Print out variable name and value
*/
#define WRITEVAR(VAR_NAME,VAR_TYPE) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf ("%s = ", #VAR_NAME); \
printf (#VAR_TYPE, (VAR_NAME) ); \
printf ("\n"); \
}
/*
Debugging Macro: Print out debugging note
*/
#define WRITENOT(MSG) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf (" (%s)\n", MSG); \
}
/*
************************************************************************
Macros
************************************************************************
*/
#define LOOP(INDEX,LIMIT) \
for ((INDEX)=0; (INDEX)<(LIMIT); (INDEX)++)
/*
************************************************************************
Type Definitions
************************************************************************
*/
typedef void ThreadFunction_t(void *);
/*
************************************************************************
Global Variables
************************************************************************
*/
/*
************************************************************************
Module-Wide Variables
************************************************************************
*/
static NumProc_m = 1;
/*
************************************************************************
Local Function Prototypes
************************************************************************
*/
/*
************************************************************************
Exported Functions
************************************************************************
*/
void SetNumProc (int NumProc)
{
NumProc_m = NumProc;
}
int GetNumProc (void)
{
return NumProc_m;
}
/*
************************************************************************
Exported Functions - PTHREAD LIBRARY REPLACEMENT
************************************************************************
*/
/* Compile this only if not using real threads */
#ifndef HAVE_LIBPTHREAD
int pthread_mutex_init
(
PTHREAD_MUTEX_T *Lock,
PTHREAD_MUTEXATTR_T *Dummy
)
{
ASSERT (Lock!=NULL)
*Lock = 0;
}
int pthread_create
(
PTHREAD_T *Thread,
PTHREAD_ATTR_T *Dummy,
void *(*Function)(void *),
void *FunctionParam
)
{
ThreadFunction_t *ThreadFunction;
ASSERT (Function!=NULL)
ASSERT (Thread!=NULL)
ThreadFunction = (ThreadFunction_t *) Function;
ThreadFunction (FunctionParam);
*Thread = 1;
}
int pthread_join (PTHREAD_T DummyThread, void *Dummy)
{
DummyThread--;
ASSERT (DummyThread==0)
}
int pthread_mutex_lock (PTHREAD_MUTEX_T *Lock)
{
ASSERT (Lock!=NULL)
ASSERT (*Lock==0)
(*Lock)++;
}
int pthread_mutex_unlock (PTHREAD_MUTEX_T *Lock)
{
ASSERT (Lock!=NULL)
ASSERT (*Lock==1)
(*Lock)--;
}
#endif /* #ifndef HAVE_LIBPTHREAD */
/*
************************************************************************
Test Driver
************************************************************************
*/
#ifdef TEST_DRIVER
void TestFunction (void *);
int main ()
{
PTHREAD_T Thread;
pthread_create (&Thread, NULL, (void *) &TestFunction, NULL);
return 0;
}
void TestFunction (void *Dummy)
{
printf ("Inside TestFunction\n");
}
#endif