00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef VMD_THREADS_INC
00023 #define VMD_THREADS_INC 1
00024
00025
00026 #if defined(__hpux) || defined(__irix) || defined(__linux) || defined(_CRAY) || defined(__osf__) || defined(_AIX) || defined(__APPLE__) || defined(__sun)
00027 #if !defined(USEPOSIXTHREADS)
00028 #define USEPOSIXTHREADS
00029 #endif
00030 #endif
00031
00032 #ifdef VMDTHREADS
00033 #ifdef USEPOSIXTHREADS
00034 #include <pthread.h>
00035
00036 typedef pthread_t vmd_thread_t;
00037 typedef pthread_mutex_t vmd_mutex_t;
00038 typedef pthread_cond_t vmd_cond_t;
00039
00040 typedef struct vmd_barrier_struct {
00041 int padding1[8];
00042 pthread_mutex_t lock;
00043 int n_clients;
00044 int n_waiting;
00045 int phase;
00046 int sum;
00047 int result;
00048 pthread_cond_t wait_cv;
00049 int padding2[8];
00050 } vmd_barrier_t;
00051
00052 #endif
00053
00054
00055
00056 #ifdef _MSC_VER
00057 #include <windows.h>
00058 typedef HANDLE vmd_thread_t;
00059 typedef CRITICAL_SECTION vmd_mutex_t;
00060
00061 #if 0 && (NTDDI_VERSION >= NTDDI_WS08 || _WIN32_WINNT > 0x0600)
00062
00063 #define VMDUSEWIN2008CONDVARS 1
00064 typedef CONDITION_VARIABLE vmd_cond_t;
00065 #else
00066
00067
00068
00069
00070
00071
00072 #if 1
00073 #define VMDUSEINTERLOCKEDATOMICOPS 1
00074 #endif
00075 #define VMD_COND_SIGNAL 0
00076 #define VMD_COND_BROADCAST 1
00077 typedef struct {
00078 LONG waiters;
00080 CRITICAL_SECTION waiters_lock;
00081 HANDLE events[2];
00082 } vmd_cond_t;
00083 #endif
00084
00085 typedef HANDLE vmd_barrier_t;
00086 #endif
00087 #endif
00088
00089
00090 #ifndef VMDTHREADS
00091 typedef int vmd_thread_t;
00092 typedef int vmd_mutex_t;
00093 typedef int vmd_cond_t;
00094 typedef int vmd_barrier_t;
00095 #endif
00096
00097 #ifdef __cplusplus
00098 extern "C" {
00099 #endif
00100
00101
00102
00103
00104
00105
00106 int vmd_mutex_init(vmd_mutex_t *);
00107
00108
00109 int vmd_mutex_lock(vmd_mutex_t *);
00110
00111
00112 int vmd_mutex_unlock(vmd_mutex_t *);
00113
00114
00115 int vmd_mutex_destroy(vmd_mutex_t *);
00116
00117
00118
00119
00120
00121
00122 int vmd_cond_init(vmd_cond_t *);
00123
00124
00125 int vmd_cond_destroy(vmd_cond_t *);
00126
00127
00128 int vmd_cond_wait(vmd_cond_t *, vmd_mutex_t *);
00129
00130
00131 int vmd_cond_signal(vmd_cond_t *);
00132
00133
00134 int vmd_cond_broadcast(vmd_cond_t *);
00135
00136 #endif
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 int vmd_thread_barrier_init_proc_shared(vmd_barrier_t *, int n_clients);
00147
00148
00149 void vmd_thread_barrier_destroy(vmd_barrier_t *barrier);
00150
00151
00152
00153
00154
00155 int vmd_thread_barrier(vmd_barrier_t *barrier, int increment);
00156
00157 #ifdef __cplusplus
00158 }
00159 #endif