/*
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