1 2# Copyright (C) Igor Sysoev 3# Copyright (C) NGINX, Inc. 4 5 6case "$NXT_SYSTEM" in 7 8 Linux) 9 NXT_PTHREAD="-lpthread" 10 ;; 11 12 FreeBSD) 13 # FreeBSD libc supports only pthread stubs. 14 NXT_PTHREAD="-lpthread" 15 ;; 16 17 SunOS) 18 case "$NXT_SYSTEM_VERSION" in 19 5.8 | 5.9) 20 NXT_PTHREAD="-lpthread" 21 ;; 22 *) 23 # Solaris 10 libpthread.so.1 is a filter to libc.so.1. 24 NXT_PTHREAD= 25 ;; 26 esac 27 ;; 28 29 Darwin) 30 # MacOSX libpthread.dylib is a symlink to libSystem.dylib. 31 NXT_PTHREAD= 32 ;; 33 34 *) 35 NXT_PTHREAD="-lpthread" 36 ;; 37esac 38 39 40# Linux, FreeBSD. 41 42nxt_feature="pthread_yield()" 43nxt_feature_name=NXT_HAVE_PTHREAD_YIELD 44nxt_feature_run= 45nxt_feature_incs= 46nxt_feature_libs=$NXT_PTHREAD 47nxt_feature_test="#define _GNU_SOURCE 48 #include <pthread.h> 49 50 int main() { 51 pthread_yield(); 52 return 0; 53 }" 54. auto/feature 55 56 57if [ $nxt_found = no ]; then 58 59 # MacOSX. 60 61 nxt_feature="pthread_yield_np()" 62 nxt_feature_name=NXT_HAVE_PTHREAD_YIELD_NP 63 nxt_feature_run= 64 nxt_feature_incs= 65 nxt_feature_libs=$NXT_PTHREAD 66 nxt_feature_test="#include <pthread.h> 67 68 int main() { 69 pthread_yield_np(); 70 return 0; 71 }" 72 . auto/feature 73fi 74 75 76# FreeBSD, Solaris, AIX. 77 78nxt_feature="pthread spinlock" 79nxt_feature_name=NXT_HAVE_PTHREAD_SPINLOCK 80nxt_feature_run=yes 81nxt_feature_incs= 82nxt_feature_libs=$NXT_PTHREAD 83nxt_feature_test="#include <pthread.h> 84 85 int main() { 86 pthread_spinlock_t lock; 87 88 if (pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE) != 0) 89 return 1; 90 if (pthread_spin_lock(&lock) != 0) 91 return 1; 92 if (pthread_spin_unlock(&lock) != 0) 93 return 1; 94 if (pthread_spin_destroy(&lock) != 0) 95 return 1; 96 return 0; 97 }" 98. auto/feature 99 100 101if [ $nxt_found = yes ]; then 102 103 # Linux glibc uses 0 as pthread_spinlock_t initial value on the most 104 # platforms. However, on i386 and x86_64 the initial value is 1. 105 106 nxt_feature="pthread spinlock zero initial value" 107 nxt_feature_name=NXT_HAVE_PTHREAD_SPINLOCK_ZERO 108 nxt_feature_run=yes 109 nxt_feature_incs= 110 nxt_feature_libs=$NXT_PTHREAD 111 nxt_feature_test="#include <pthread.h> 112 113 pthread_spinlock_t lock = 0; 114 115 int main() { 116 if (pthread_spin_trylock(&lock) != 0) 117 return 1; 118 if (pthread_spin_unlock(&lock) != 0) 119 return 1; 120 return 0; 121 }" 122 . auto/feature 123fi 124 125 126if [ $nxt_found = no ]; then 127 128 # MacOSX spinlock(3). 129 130 nxt_feature="MacOSX spinlock" 131 nxt_feature_name=NXT_HAVE_MACOSX_SPINLOCK 132 nxt_feature_run=yes 133 nxt_feature_incs= 134 nxt_feature_libs=$NXT_PTHREAD 135 nxt_feature_test="#include <libkern/OSAtomic.h> 136 137 int main() { 138 OSSpinLock lock = 0; 139 140 if (OSSpinLockTry(&lock) == 0) 141 return 1; 142 OSSpinLockUnlock(&lock); 143 return 0; 144 }" 145 . auto/feature 146fi 147 148 149nxt_feature="sem_timedwait()" 150nxt_feature_name=NXT_HAVE_SEM_TIMEDWAIT 151nxt_feature_run=yes 152nxt_feature_incs= 153nxt_feature_libs= 154nxt_feature_test="#include <semaphore.h> 155 156 int main() { 157 sem_t sem; 158 struct timespec ts; 159 160 if (sem_init(&sem, 0, 0) != 0) 161 return 1; 162 if (sem_post(&sem) != 0) 163 return 1; 164 165 ts.tv_sec = 0; 166 ts.tv_nsec = 0; 167 if (sem_timedwait(&sem, &ts) != 0) 168 return 1; 169 170 if (sem_destroy(&sem) != 0) 171 return 1; 172 return 0; 173 }" 174. auto/feature 175 176 177if [ $nxt_found = no ]; then 178 179 if [ -n "$NXT_PTHREAD" ]; then 180 181 # Linux requires libpthread. 182 183 nxt_feature="sem_timedwait() in libpthread" 184 nxt_feature_libs=$NXT_PTHREAD 185 . auto/feature 186 fi 187 188 if [ $nxt_found = no ]; then 189 190 # Solaris 10 requires librt. 191 192 nxt_feature="sem_timedwait() in librt" 193 nxt_feature_libs="-lrt" 194 . auto/feature 195 196 if [ $nxt_found = yes ]; then 197 NXT_LIBRT="-lrt" 198 fi 199 fi 200fi 201 202 203# Thread Local Storage / Thread Specific Data. 204# 205# Linux, FreeBSD 5.3, Solaris. 206# MacOSX 10.7 (Lion) Clang. 207 208nxt_feature="__thread" 209nxt_feature_name=NXT_HAVE_THREAD_STORAGE_CLASS 210nxt_feature_run=yes 211nxt_feature_incs= 212nxt_feature_libs=$NXT_PTHREAD 213nxt_feature_test="#include <pthread.h> 214 #include <stdlib.h> 215 216 __thread int key; 217 218 void *func(void *p); 219 220 void *func(void *p) { 221 key = 0x9abcdef0; 222 return NULL; 223 } 224 225 int main() { 226 void *n; 227 pthread_t pt; 228 229 key = 0x12345678; 230 if (pthread_create(&pt, NULL, func, NULL)) 231 return 1; 232 if (pthread_join(pt, &n)) 233 return 1; 234 if (key != 0x12345678) 235 return 1; 236 return 0; 237 }" 238. auto/feature 239 240 241if [ $nxt_found = no ]; then 242 243 # MacOSX GCC lacks __thread support. 244 # On NetBSD __thread causes segmentation fault. 245 246 nxt_feature="phtread_key_t" 247 nxt_feature_name=NXT_HAVE_PTHREAD_SPECIFIC_DATA 248 nxt_feature_run=yes 249 nxt_feature_incs= 250 nxt_feature_libs=$NXT_PTHREAD 251 nxt_feature_test="#include <pthread.h> 252 253 int main() { 254 pthread_key_t key = -1; 255 256 if (pthread_key_create(&key, NULL)) 257 return 1; 258 if (pthread_setspecific(key, (void *) 0x12345678)) 259 return 1; 260 if (pthread_getspecific(key) != (void *) 0x12345678) 261 return 1; 262 return 0; 263 }" 264 . auto/feature 265 266 267 nxt_feature="PTHREAD_KEYS_MAX" 268 nxt_feature_name= 269 nxt_feature_run=value 270 nxt_feature_incs= 271 nxt_feature_libs= 272 nxt_feature_test="#include <limits.h> 273 #include <pthread.h> 274 #include <stdio.h> 275 276 int main() { 277 printf(\"%d\", PTHREAD_KEYS_MAX); 278 return 0; 279 }" 280 . auto/feature 281fi 282