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(void) { 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(void) { 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(void) { 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(void) { 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 126nxt_feature="sem_timedwait()" 127nxt_feature_name=NXT_HAVE_SEM_TIMEDWAIT 128nxt_feature_run=yes 129nxt_feature_incs= 130nxt_feature_libs= 131nxt_feature_test="#include <semaphore.h> 132 133 int main(void) { 134 sem_t sem; 135 struct timespec ts; 136 137 if (sem_init(&sem, 0, 0) != 0) 138 return 1; 139 if (sem_post(&sem) != 0) 140 return 1; 141 142 ts.tv_sec = 0; 143 ts.tv_nsec = 0; 144 if (sem_timedwait(&sem, &ts) != 0) 145 return 1; 146 147 if (sem_destroy(&sem) != 0) 148 return 1; 149 return 0; 150 }" 151. auto/feature 152 153 154if [ $nxt_found = no ]; then 155 156 if [ -n "$NXT_PTHREAD" ]; then 157 158 # Linux requires libpthread. 159 160 nxt_feature="sem_timedwait() in libpthread" 161 nxt_feature_libs=$NXT_PTHREAD 162 . auto/feature 163 fi 164 165 if [ $nxt_found = no ]; then 166 167 # Solaris 10 requires librt. 168 169 nxt_feature="sem_timedwait() in librt" 170 nxt_feature_libs="-lrt" 171 . auto/feature 172 173 if [ $nxt_found = yes ]; then 174 NXT_LIBRT="-lrt" 175 fi 176 fi 177fi 178 179 180# Thread Local Storage / Thread Specific Data. 181# 182# Linux, FreeBSD 5.3, Solaris. 183# MacOSX 10.7 (Lion) Clang. 184 185nxt_feature="__thread" 186nxt_feature_name=NXT_HAVE_THREAD_STORAGE_CLASS 187nxt_feature_run=yes 188nxt_feature_incs= 189nxt_feature_libs=$NXT_PTHREAD 190nxt_feature_test="#include <pthread.h> 191 #include <stdlib.h> 192 193 __thread int key; 194 195 void *func(void *p); 196 197 void *func(void *p) { 198 key = 0x9abcdef0; 199 return NULL; 200 } 201 202 int main(void) { 203 void *n; 204 pthread_t pt; 205 206 key = 0x12345678; 207 if (pthread_create(&pt, NULL, func, NULL)) 208 return 1; 209 if (pthread_join(pt, &n)) 210 return 1; 211 if (key != 0x12345678) 212 return 1; 213 return 0; 214 }" 215. auto/feature 216 217 218if [ $nxt_found = no ]; then 219 220 # MacOSX GCC lacks __thread support. 221 # On NetBSD __thread causes segmentation fault. 222 223 nxt_feature="phtread_key_t" 224 nxt_feature_name=NXT_HAVE_PTHREAD_SPECIFIC_DATA 225 nxt_feature_run=yes 226 nxt_feature_incs= 227 nxt_feature_libs=$NXT_PTHREAD 228 nxt_feature_test="#include <pthread.h> 229 230 int main(void) { 231 pthread_key_t key = -1; 232 233 if (pthread_key_create(&key, NULL)) 234 return 1; 235 if (pthread_setspecific(key, (void *) 0x12345678)) 236 return 1; 237 if (pthread_getspecific(key) != (void *) 0x12345678) 238 return 1; 239 return 0; 240 }" 241 . auto/feature 242 243 244 nxt_feature="PTHREAD_KEYS_MAX" 245 nxt_feature_name= 246 nxt_feature_run=value 247 nxt_feature_incs= 248 nxt_feature_libs= 249 nxt_feature_test="#include <limits.h> 250 #include <pthread.h> 251 #include <stdio.h> 252 253 int main(void) { 254 printf(\"%d\", PTHREAD_KEYS_MAX); 255 return 0; 256 }" 257 . auto/feature 258fi 259