Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

VMDThreads.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2008 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: VMDThreads.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.18 $       $Date: 2008/03/27 19:36:49 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *  code for spawning threads on various platforms.
00019  ***************************************************************************/
00020 
00021 #ifndef VMD_THREADS_INC
00022 #define VMD_THREADS_INC 1
00023 
00024 /* define which thread calls to use */
00025 #if defined(USEPOSIXTHREADS) && defined(USEUITHREADS)
00026 #error You may only define USEPOSIXTHREADS or USEUITHREADS, but not both
00027 #endif
00028 
00029 /* POSIX Threads */
00030 #if defined(HPUX) || defined(Irix) || defined(Linux) || defined(_CRAY) || defined(__osf__) || defined(AIX) || defined(_AIX) || defined(__APPLE__)
00031 #if !defined(USEUITHREADS) && !defined(USEPOSIXTHREADS)
00032 #define USEPOSIXTHREADS
00033 #endif
00034 #endif
00035 
00036 /* Unix International Threads */
00037 #if defined(__sun)
00038 #if !defined(USEPOSIXTHREADS)
00039 #define USEUITHREADS
00040 #endif
00041 #endif
00042 
00043 
00044 
00045 #ifdef VMDTHREADS
00046 #ifdef USEPOSIXTHREADS
00047 #include <pthread.h>
00048 
00049 typedef pthread_t        vmd_thread_t;
00050 typedef pthread_mutex_t   vmd_mutex_t;
00051 
00052 typedef struct vmd_barrier_struct {
00053   int padding1[8]; /* Padding bytes to avoid false sharing and cache aliasing */
00054   pthread_mutex_t lock;   /* Mutex lock for the structure */
00055   int n_clients;          /* Number of threads to wait for at barrier */
00056   int n_waiting;          /* Number of currently waiting threads */
00057   int phase;              /* Flag to separate waiters from fast workers */
00058   int sum;                /* Sum of arguments passed to barrier_wait */
00059   int result;             /* Answer to be returned by barrier_wait */
00060   pthread_cond_t wait_cv; /* Clients wait on condition variable to proceed */
00061   int padding2[8]; /* Padding bytes to avoid false sharing and cache aliasing */
00062 } vmd_barrier_t;
00063 
00064 #endif
00065 
00066 #ifdef USEUITHREADS
00067 #include <thread.h>
00068 
00069 typedef thread_t  vmd_thread_t;
00070 typedef mutex_t    vmd_mutex_t;
00071 
00072 typedef struct vmd_barrier_struct {
00073   int padding1[8]; /* Padding bytes to avoid false sharing and cache aliasing */
00074   mutex_t lock;           /* Mutex lock for the structure */
00075   int n_clients;          /* Number of threads to wait for at barrier */
00076   int n_waiting;          /* Number of currently waiting threads */
00077   int phase;              /* Flag to separate waiters from fast workers */
00078   int sum;                /* Sum of arguments passed to barrier_wait */
00079   int result;             /* Answer to be returned by barrier_wait */
00080   cond_t wait_cv;         /* Clients wait on condition variable to proceed */
00081   int padding2[8]; /* Padding bytes to avoid false sharing and cache aliasing */
00082 } vmd_barrier_t;
00083 
00084 #endif
00085 
00086 
00087 
00088 #ifdef _MSC_VER
00089 #include <windows.h>
00090 typedef HANDLE vmd_thread_t;
00091 typedef HANDLE vmd_mutex_t;
00092 typedef HANDLE vmd_barrier_t;
00093 #endif
00094 #endif
00095 
00096 
00097 #ifndef VMDTHREADS
00098 typedef int vmd_thread_t;
00099 typedef int vmd_mutex_t;
00100 typedef int vmd_barrier_t;
00101 #endif
00102 
00103 
00105 int vmd_thread_numphysprocessors(void);
00106 
00108 int vmd_thread_numprocessors(void);
00109 
00111 int * vmd_cpu_affinitylist(int *cpuaffinitycount);
00112 
00114 int vmd_thread_set_self_cpuaffinity(int cpu);
00115 
00117 int vmd_thread_setconcurrency(int);
00118 
00120 int vmd_thread_create(vmd_thread_t *, void * routine(void *), void *);
00121 
00123 int vmd_thread_join(vmd_thread_t, void **);
00124 
00126 int vmd_mutex_init(vmd_mutex_t *);
00127 
00129 int vmd_mutex_lock(vmd_mutex_t *);
00130 
00132 int vmd_mutex_unlock(vmd_mutex_t *);
00133 
00135 int vmd_mutex_destroy(vmd_mutex_t *);
00136 
00138 int vmd_thread_barrier_init(vmd_barrier_t *, int n_clients);
00139 
00141 void vmd_thread_barrier_destroy(vmd_barrier_t *barrier);
00142 
00144 int vmd_thread_barrier(vmd_barrier_t *barrier, int increment);
00145 
00146 #endif

Generated on Fri Sep 5 01:25:20 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002