Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _CRAY_MTLOCK_H
00039 #define _CRAY_MTLOCK_H
00040
00041
00042
00043
00044
00045 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00046 #include <cray/libuni.h>
00047 #endif
00048
00049 #if defined(__mips)
00050 #include <mutex.h>
00051 #elif defined(_SOLARIS)
00052 #include <synch.h>
00053 #elif defined(_LITTLE_ENDIAN) && !defined(__sv2)
00054
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #if defined(__mips) || (defined(_LITTLE_ENDIAN) && defined(__sv2))
00067 typedef unsigned long plock_t;
00068 #elif defined(_SOLARIS)
00069 typedef mutex_t plock_t;
00070 #elif defined(_LITTLE_ENDIAN) && !defined(__sv2)
00071
00072 typedef unsigned long plock_t;
00073 #else
00074 typedef volatile long plock_t;
00075 #endif
00076 typedef long mpplock_t;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #define DECL_LOCK(name) plock_t name;
00090 #define DECL_MPP_LOCK(name) mpplock_t name;
00091 #define EXTERN_LOCK(name) extern plock_t name;
00092 #define EXTERN_MPP_LOCK(name) extern mpplock_t name;
00093
00094
00095
00096
00097
00098 #if defined(_CRAY1) || defined(_LIB_UMK)
00099 #define MULTI_ON ($MULTION == 0)
00100 #elif defined(__mips)
00101 #define MULTI_ON 1
00102 #elif defined(_SOLARIS)
00103 #define MULTI_ON 1
00104 #else
00105 #define MULTI_ON 0
00106 #endif
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 #if defined(_CRAY1) || defined(_LIB_UMK)
00117 #define MEM_LOCK(lock) { if (MULTI_ON) _inline_mtlock(lock); }
00118 #define MEM_UNLOCK(lock) { if (MULTI_ON) _inline_mtunlock(lock); }
00119
00120 #elif defined(__mips) || (defined(_LITTLE_ENDIAN) && defined(__sv2))
00121 #define MEM_LOCK(lock) { while (__lock_test_and_set((lock),1L)); }
00122 #define MEM_UNLOCK(lock) { *(lock) = 0; }
00123
00124 #elif defined(_SOLARIS)
00125 #define MEM_LOCK(lock) mutex_lock(lock);
00126 #define MEM_UNLOCK(lock) mutex_unlock(lock);
00127
00128 #elif defined(_LITTLE_ENDIAN) && !defined(__sv2)
00129
00130
00131
00132 #define MEM_LOCK(lock)
00133 #define MEM_UNLOCK(lock)
00134
00135 #else
00136 #define MEM_LOCK(lock)
00137 #define MEM_UNLOCK(lock)
00138
00139 #endif
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 #if defined(_CRAY1) || defined(_LIB_UMK)
00151 #define LMEM_LOCK(lock) { _inline_mtlock(lock); }
00152 #define LMEM_UNLOCK(lock) { _inline_mtunlock(lock); }
00153
00154 #else
00155
00156 #define LMEM_LOCK(lock) MEM_LOCK(lock)
00157 #define LMEM_UNLOCK(lock) MEM_UNLOCK(lock)
00158
00159 #endif
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 #ifdef _CRAYMPP
00171 #define MPP_LOCK(lock) { if (_num_pes() > 1) _shmem_set_lock(lock); }
00172 #define MPP_UNLOCK(lock) { if (_num_pes() > 1) _shmem_clear_lock(lock); }
00173 #else
00174 #define MPP_LOCK(lock)
00175 #define MPP_UNLOCK(lock)
00176 #endif
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 #ifdef MULTIP
00188 #define LIB_LOCK(index) MEM_LOCK(&__lib_locks[index])
00189 #define LIB_UNLOCK(index) MEM_UNLOCK(&__lib_locks[index])
00190 #else
00191 #define LIB_LOCK(index)
00192 #define LIB_UNLOCK(index)
00193 #endif
00194
00195
00196
00197
00198
00199 #define ENVIRON_LOCK 0
00200 #define TRACEBACK_LOCK 1
00201 #define MESSAGE_LOCK 2
00202 #define LIB_LOCK_MAX 64
00203
00204
00205
00206
00207
00208 #ifdef MULTIP
00209 extern plock_t __lib_locks[];
00210 #pragma common __lib_locks
00211 #endif
00212
00213 #if defined(_CRAY1) || defined(_LIB_UMK)
00214
00215 #pragma _CRI soft $MULTION
00216 extern $MULTION(void);
00217
00218 #pragma _CRI soft _lockon
00219 extern int _lockon(plock_t *);
00220
00221 #pragma _CRI soft _lockoff
00222 extern int _lockoff(plock_t *);
00223
00224 #endif
00225
00226
00227
00228
00229
00230 #define SIGNBIT (1<<63)
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 #if defined(_CRAY1) || defined(_LIB_UMK)
00251
00252 extern void _semts(int);
00253 extern void _semclr(int);
00254 extern void _cmr(void);
00255
00256 #define TSKLK 2
00257
00258 #pragma _CRI inline _inline_mtlock
00259 static void
00260 _inline_mtlock(plock_t *lck)
00261 {
00262 _semts(TSKLK);
00263
00264
00265
00266
00267 if (*lck != 0) {
00268 _semclr(TSKLK);
00269 _lockon(lck);
00270 }
00271 else {
00272 *lck = SIGNBIT;
00273
00274 #if defined(_CRAY1) && defined(_ADDR64)
00275
00276
00277
00278
00279 _Pragma("_CRI suppress");
00280 #endif
00281
00282
00283
00284
00285 _cmr();
00286 _semclr(TSKLK);
00287 }
00288 }
00289
00290 #pragma _CRI inline _inline_mtunlock
00291 static void
00292 _inline_mtunlock(plock_t *lck)
00293 {
00294 _semts(TSKLK);
00295
00296
00297
00298
00299 if ((*lck & ~SIGNBIT) != 0) {
00300
00301
00302
00303
00304 _semclr(TSKLK);
00305 _lockoff(lck);
00306 }
00307 else {
00308
00309
00310
00311
00312
00313
00314
00315
00316 *lck = 0;
00317 _cmr();
00318 _semclr(TSKLK);
00319 }
00320 }
00321
00322 #endif
00323
00324 #undef SIGNBIT
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 #ifdef _CRAYT3D
00341 #define SHARED_CC_BUG_WORKAROUND(name) void name(void) {}
00342 #else
00343 #define SHARED_CC_BUG_WORKAROUND(name)
00344 #endif
00345
00346 #endif