1 #ifndef _ARMCI_LOCKS_H_
2 #define _ARMCI_LOCKS_H_
3 
4 #if HAVE_SYS_TYPES_H
5 #   include <sys/types.h>
6 #endif
7 
8 #define MAX_LOCKS 1024
9 #define NUM_LOCKS MAX_LOCKS
10 
11 #if !(defined(PMUTEX) || defined(PSPIN) || defined(CYGNUS) || defined(CRAY_XT))
12 #   include "spinlock.h"
13 #endif
14 
15 #if !(defined(PMUTEX) || defined(PSPIN) || defined(SPINLOCK))
16 #   error cannot run
17 #endif
18 
19 #if (defined(SPINLOCK) || defined(PMUTEX) || defined(PSPIN) || defined(HITACHI)) && !(defined(BGML) || defined(DCMF))
20 #   include "armci_shmem.h"
21 typedef struct {
22     long off;
23     long idlist[SHMIDLEN];
24 } lockset_t;
25 extern lockset_t lockid;
26 #elif defined(BGML) || defined(DCMF)
27 typedef int lockset_t;
28 #endif
29 
30 #if defined(PMUTEX)
31 #   warning SPINLOCK: pthread_mutex_lock
32 #   include <pthread.h>
33 #   include <unistd.h>
34 #   define NAT_LOCK(x,p) pthread_mutex_lock(_armci_int_mutexes +x)
35 #   define NAT_UNLOCK(x,p) pthread_mutex_unlock(_armci_int_mutexes +x)
36 #   define LOCK_T pthread_mutex_t
37 #   define PAD_LOCK_T LOCK_T
38 extern PAD_LOCK_T *_armci_int_mutexes;
39 
40 #elif defined(PSPIN)
41 #   warning SPINLOCK: pthread_spin_lock
42 #   include <pthread.h>
43 #   include <unistd.h>
44 #   define NAT_LOCK(x,p) pthread_spin_lock(_armci_int_mutexes +x)
45 #   define NAT_UNLOCK(x,p) pthread_spin_unlock(_armci_int_mutexes +x)
46 #   define LOCK_T pthread_spinlock_t
47 #   define PAD_LOCK_T LOCK_T
48 extern PAD_LOCK_T *_armci_int_mutexes;
49 
50 #elif defined(SPINLOCK) && defined(SGIALTIX)
51 #   define NAT_LOCK(x,p) armci_acquire_spinlock((LOCK_T*)( ((PAD_LOCK_T*)(((void**)_armci_int_mutexes)[p]))+x ))
52 #   define NAT_UNLOCK(x,p) armci_release_spinlock((LOCK_T*)( ((PAD_LOCK_T*)(((void**)_armci_int_mutexes)[p]))+x ))
53 extern PAD_LOCK_T *_armci_int_mutexes;
54 
55 #elif defined(SPINLOCK)
56 #   define NAT_LOCK(x,p) armci_acquire_spinlock((LOCK_T*)(_armci_int_mutexes+(x)))
57 #   define NAT_UNLOCK(x,p) armci_release_spinlock((LOCK_T*)(_armci_int_mutexes+(x)))
58 extern PAD_LOCK_T *_armci_int_mutexes;
59 
60 #elif defined(HITACHI)
61 extern void armcill_lock(int mutex, int proc);
62 extern void armcill_unlock(int mutex, int proc);
63 #   define LOCK_T int
64 #   define PAD_LOCK_T LOCK_T
65 #   define NAT_LOCK(x,p) armcill_lock((x),(p))
66 #   define NAT_UNLOCK(x,p) armcill_unlock((x),(p))
67 extern PAD_LOCK_T *_armci_int_mutexes;
68 
69 #elif defined(SGI)
70 #   define SGI_SPINS 100
71 #   include <ulocks.h>
72 typedef struct {
73     int id;
74     ulock_t * lock_array[NUM_LOCKS];
75 }lockset_t;
76 extern lockset_t lockset;
77 #   define NAT_LOCK(x,p)   (void) uswsetlock(lockset.lock_array[(x)],SGI_SPINS)
78 #   define NAT_UNLOCK(x,p) (void) usunsetlock(lockset.lock_array[(x)])
79 
80 #elif defined(CONVEX)
81 #   include <sys/cnx_ail.h>
82 typedef struct{
83     unsigned state;
84     unsigned pad[15];
85 } lock_t;
86 typedef int lockset_t;
87 extern lock_t *lock_array;
88 extern void setlock(unsigned * volatile lp);
89 extern void unsetlock(unsigned  * volatile lp);
90 #   define NAT_LOCK(x,p)    (void) setlock(&lock_array[x].state)
91 #   define NAT_UNLOCK(x,p)  (void) unsetlock(&lock_array[(x)].state)
92 
93 #elif defined(WIN32)
94 typedef int lockset_t;
95 extern void setlock(int);
96 extern void unsetlock(int);
97 #   define NAT_LOCK(x,p)   setlock(x)
98 #   define NAT_UNLOCK(x,p)  unsetlock(x)
99 
100 #elif defined(CRAY_YMP) && !defined(__crayx1)
101 #   include <tfork.h>
102 typedef int lockset_t;
103 extern  lock_t cri_l[NUM_LOCKS];
104 #   pragma  _CRI common cri_l
105 #   define NAT_LOCK(x,p)   t_lock(cri_l+(x))
106 #   define NAT_UNLOCK(x,p) t_unlock(cri_l+(x))
107 
108 #elif defined(CRAY_T3E) || defined(__crayx1) || defined(CATAMOUNT) || defined(CRAY_SHMEM) || defined(PORTALS)
109 #   include <limits.h>
110 #   if defined(CRAY) || defined(CRAY_XT)
111 #       include <mpp/shmem.h>
112 #   endif
113 #   if defined(DECOSF) || defined(LINUX64) || defined(__crayx1) || defined(CATAMOUNT)
114 #       define _INT_MIN_64 (LONG_MAX-1)
115 #   endif
116 #   undef NUM_LOCKS
117 #   define NUM_LOCKS 4
118 static long armci_lock_var[4]={0,0,0,0};
119 typedef int lockset_t;
120 #   define INVALID (long)(_INT_MIN_64 +1)
121 #   define NAT_LOCK(x,p) while( shmem_swap(armci_lock_var+(x),INVALID,(p)) )
122 #   define NAT_UNLOCK(x,p) shmem_swap(armci_lock_var+(x), 0, (p))
123 
124 #elif defined(SYSV) && defined(LAPI) && defined(AIX)
125 int **_armci_int_mutexes;
126 #   define NAT_LOCK(x,p)  armci_lapi_lock(_armci_int_mutexes[armci_master]+(x))
127 #   define NAT_UNLOCK(x,p)  armci_lapi_unlock(_armci_int_mutexes[armci_master]+(x))
128 typedef int lockset_t;
129 
130 #elif defined(CYGNUS)
131 typedef int lockset_t;
132 #   define NAT_LOCK(x,p) armci_die("does not run in parallel",0)
133 #   define NAT_UNLOCK(x,p) armci_die("does not run in parallel",0)
134 
135 #elif defined(LAPI) && !defined (LINUX)
136 #   include <pthread.h>
137 typedef int lockset_t;
138 extern pthread_mutex_t _armci_mutex_thread;
139 #   define NAT_LOCK(x,p)   pthread_mutex_lock(&_armci_mutex_thread)
140 #   define NAT_UNLOCK(x,p) pthread_mutex_unlock(&_armci_mutex_thread)
141 
142 #elif defined(FUJITSU)
143 typedef int lockset_t;
144 #   include "fujitsu-vpp.h"
145 
146 #elif defined(SYSV) || defined(MACX)
147 #   include "semaphores.h"
148 #   undef NUM_LOCKS
149 #   define NUM_LOCKS ((MAX_LOCKS< SEMMSL) ? MAX_LOCKS:SEMMSL)
150 #   define NAT_LOCK(x,p)   P_semaphore(x)
151 #   define NAT_UNLOCK(x,p)  V_semaphore(x)
152 #   ifndef _LOCKS_C_
153 #       define CreateInitLocks Sem_CreateInitLocks
154 #       define InitLocks Sem_InitLocks
155 #       define DeleteLocks Sem_DeleteLocks
156 #   endif
157 
158 #else
159 #   error
160 #endif
161 
162 extern void CreateInitLocks(int num, lockset_t *id);
163 extern void InitLocks(int num , lockset_t id);
164 extern void DeleteLocks(lockset_t id);
165 
166 #ifdef FUJITSU
167 #   define NATIVE_LOCK(x,p) if(armci_nproc>1) { NAT_LOCK(p); }
168 #   define NATIVE_UNLOCK(x,p) if(armci_nproc>1) { NAT_UNLOCK(p); }
169 #else
170 #   define NATIVE_LOCK(x,p) if(armci_nproc>1) { NAT_LOCK(x,p); }
171 #   define NATIVE_UNLOCK(x,p) if(armci_nproc>1) { NAT_UNLOCK(x,p); }
172 #endif
173 
174 #endif /* _ARMCI_LOCKS_H_ */
175